Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exchange defaultProps for default parameters in function components #1226

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

asizemore
Copy link
Member

@asizemore asizemore commented Oct 9, 2024

Partially resolves #1218

defaultProps is being deprecated for function components. This PR removes the old defaultProps from all function components.

Below is the list that Bob provided (for completeness). I either completed the update or found it was not a case that needed changing:

  • packages/libs/wdk-client/src/Views/Answer/AnswerTable.jsx Class component
  • packages/libs/wdk-client/src/Views/Records/RecordNavigation/RecordNavigationSection.jsx Class component
  • packages/libs/wdk-client/src/Views/Records/RecordActionLink.jsx
  • packages/libs/wdk-client/src/Core/Root.tsx Class component
  • packages/libs/wdk-client/src/Components/Display/TabbableContainer.tsx Class component
  • packages/libs/wdk-client/src/Components/InputControls/NativeCheckboxList.tsx Class component
  • packages/libs/wdk-client/src/Components/Overlays/Popup.tsx Class component
  • packages/libs/wdk-client/src/Components/Shared/Spinnable.tsx Class component
  • packages/libs/wdk-client/src/Components/SearchBox/RealTimeSearchBox.tsx Class component
  • packages/libs/wdk-client/src/Components/AttributeFilter/FieldFilter.jsx
  • packages/libs/wdk-client/src/Components/AttributeFilter/MembershipField.jsx Class component
  • packages/libs/wdk-client/src/Components/AttributeFilter/ServerSideAttributeFilter.jsx
  • packages/libs/wdk-client/src/Components/AttributeFilter/Histogram.jsx Class component
  • packages/libs/coreui/src/components/inputs/checkboxes/CheckboxTree/CheckboxTree.tsx
  • packages/libs/coreui/src/components/inputs/SelectTree/SelectTree.tsx
  • packages/libs/coreui/src/assets/icons/CaretDown.tsx NA
  • packages/libs/coreui/src/assets/icons/CaretUp.tsx NA
  • packages/libs/coreui/src/assets/icons/DoubleArrow.tsx NA
  • packages/libs/coreui/src/assets/icons/Cancel.tsx NA
  • packages/libs/coreui/src/assets/icons/Arrow.tsx NA
  • packages/libs/web-common/src/components/records/Sequence.tsx
  • packages/libs/web-common/src/util/customElements.jsx Class component

I also found deafultProps in Compound.jsx, Gbrowse.jsx, and OverviewThumbnail.jsx but they were all being used with class components.

Notes

  • For SelectTree, I removed the default props entirely if they both were the same as the component they were being passed to and caused no errors when removing.
  • Multiple functions in CheckboxTree.tsx relied on default values being set, so i defined them in the file and then reused these values across the different functions.
  • Could not find Sequence component on gene record pages. Where does it get loaded? Otherwise I checked all the other updated components on the genomics or mbio site.

@asizemore
Copy link
Member Author

Started looking into removing findDOMNode. It's not as straightforward as i had hoped, so i'll make a new PR for it.

@asizemore asizemore marked this pull request as ready for review October 11, 2024 21:35
@asizemore asizemore requested a review from dmfalke October 11, 2024 21:35
Copy link
Member

@dmfalke dmfalke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really good! See my comments about CheckboxTree, and let me know what you think.

shouldCloseOnSelection,
wrapPopover,
currentList,
selectedList = [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need this. Isn't selectedList an option prop for CheckboxTree?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is but we use selectedList below to auto close the popover.

setKey(selectedList.join(', '));

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(line 45 ish)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It occurred to me that you could do something like this in the component:

function CheckboxTree<T>(partialProps: Props<T>) {
  const props = { ...defaultProps, ...partialProps };

  // ...

}

If a prop is defined in partialProps, it's value will be used; otherwise, the value in defaultProps will be used.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be so much nicer. I tried this for a bit but could not shake a missing in types validation default props error. Even after ensuring props was of the correct type.
Happy to try something else if you have an idea of how to get around this!

@asizemore
Copy link
Member Author

@dmfalke I finally got around to responding to comments!
I ended up using all of the defualtCheckboxTreeProps in deconstructing props for CheckboxTree.

I also couldn't find a way around a type issue. But otherwise was mostly able to apply your suggestions!

@asizemore
Copy link
Member Author

Testing now, and will re-request a review when tests are complete

@asizemore
Copy link
Member Author

Looking good now. Ready for another look when you have a min, @dmfalke !

@asizemore asizemore requested a review from dmfalke December 5, 2024 15:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tech debt: remove deprecated defaultProps
2 participants