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

Select Deprecation edits #2434

Merged
merged 3 commits into from
Jun 5, 2023
Merged

Select Deprecation edits #2434

merged 3 commits into from
Jun 5, 2023

Conversation

brandonlenz
Copy link
Contributor

Summary

Batched PR feedback/suggestions for #2415

How To Test

Unit tests, storybook

Screenshots (optional)

Dropdown still works, and displays deprecation warning:
image

Select of course also works, does not display deprecation warning:
image

- Updates TODO Comment to highlight more obviously in most IDEs
- We have a convention of preferring named exports, and that's what we export in index.tsx
const { queryByTestId } = render(
<Select id="input-type-text" name="input-type-text">
<Dropdown id="input-type-text" name="input-type-text">
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test should still be for the Dropdown component. Might've accidentally gotten updated by IDE in #2415

Comment on lines +19 to +22
expect(deprecationWarning).toHaveBeenCalledTimes(1)
expect(deprecationWarning).toHaveBeenCalledWith(
'Dropdown is deprecated and will be removed in the future. Please use the Select component instead.'
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really necessary, since deprecationWarning and withDeprecationWarning have tests, but it was peace of mind for me making sure that my suggestions actually work because this was just a theory until confirming it 😉

Copy link
Contributor

Choose a reason for hiding this comment

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

bah i tried adding this but couldn't get it to work

Comment on lines +8 to +11
export const Dropdown = withDeprecationWarning(
Select,
'Dropdown is deprecated and will be removed in the future. Please use the Select component instead.'
)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@werdnanoslen this was the main thing I wanted to suggest. withDeprecationWarning allows you to wrap any component, and it just returns a new component with the name you give it, which renders with a useEffect that calls deprecationWarning on initial render, and also renders the component you pass in.

So no need to define and pass around props, it basically inherits all of that from Select. Dropdown is now just Select with the old name, that also renders a warning.

🪄 Magic 🪄

Copy link
Contributor

Choose a reason for hiding this comment

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

ahh got it, haven't used a pattern like this (intentionally) before, but that makes sense!

@@ -48,5 +48,3 @@ export const Select = ({
</select>
)
}

export default Select
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I noticed this leading to some new(?) eslint warnings. Since the default export had no usages, and we seem to prefer the named export as a convention, this can be removed 😄

@werdnanoslen werdnanoslen merged commit 372ff97 into an-select-2308 Jun 5, 2023
@werdnanoslen werdnanoslen deleted the bl-an-select-edits branch June 5, 2023 21:53
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.

2 participants