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 8 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
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?

searchTerm,
selectedList,
searchTerm = '',
selectedList = [],
Copy link
Member

Choose a reason for hiding this comment

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

This will create a new array on each render. Use defaultCheckboxTreeProps.selectedList to prevent that

Suggested change
selectedList = [],
selectedList = defaultCheckboxTreeProps.selectedList,

Comment on lines +732 to +734
onSelectionChange = () => {
//
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onSelectionChange = () => {
//
},
onSelectionChange = defaultCheckboxTreeProps.onSelectionChange,

Comment on lines +742 to +744
onSearchTermChange = () => {
//
},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
onSearchTermChange = () => {
//
},
onSearchTermChange = defaultCheckboxTreeProps.onSearchTermChange,

searchIconName,
searchIconPosition,
searchBoxHelp,
searchBoxHelp = '',
searchPredicate = () => true,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
searchPredicate = () => true,
searchPredicate = defaultCheckboxTreeProps.searchPredicate,

additionalFilters,
wrapTreeSection,
shouldExpandOnClick = true,
customCheckboxes,
customCheckboxes = {},
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
customCheckboxes = {},
customCheckboxes = defaultCheckboxTreeProps.customCheckboxes,

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.

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