-
Notifications
You must be signed in to change notification settings - Fork 377
chore(FormSelect): convert examples to TypeScript #7489
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
Conversation
88eb5a5 to
8e92525
Compare
|
Preview: https://patternfly-react-pr-7489.surge.sh A11y report: https://patternfly-react-pr-7489-a11y.surge.sh |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work on this @tompsota ! The examples are looking great. Left some comments below.
In a lot of cases, TS can infer the type of your hooks itself e.g. when you set the value to a string. You don't need the extra <string> type declaration for those!
Just a few easy fixes and otherwise LGTM 👍
packages/react-core/src/components/FormSelect/examples/FormSelectBasic.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectDisabled.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectGrouped.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectIconSpriteVariant.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectIconSpriteVariant.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectIconSpriteVariant.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectInvalid.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectValidated.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectValidated.tsx
Outdated
Show resolved
Hide resolved
packages/react-core/src/components/FormSelect/examples/FormSelectValidated.tsx
Outdated
Show resolved
Hide resolved
8e92525 to
1a10452
Compare
jenny-s51
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks 👍👍!
thatblindgeye
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on the conversions! I also had a couple change requests below, let me know if you have any questions! 🙂
packages/react-core/src/components/FormSelect/examples/FormSelectDisabled.tsx
Outdated
Show resolved
Hide resolved
| const isEmpty = () => formSelectValue !== ''; | ||
| const onChange = (value: string) => { | ||
| const validated = isEmpty() && ValidatedOptions.error; | ||
| setFormSelectValue(value); | ||
| setValidated(validated); | ||
| }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't look like this part of the example is working how it may have been intended when originally added.
Rather than trying to set both the validated and value states in the onChange function, it might work better to have the onChange function only call setFormSelectValue like other examples have, and moving the setValidated and checking if formSelectValue is an empty string to a useEffect hook that only runs when the formSelectValue updates. The isEmpty function would just also have to be updated to check that formSelectValue === ''
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this works better. Thanks for pointing it out.
I also renamed const validated variable so it doesn't collide with state variable.
1a10452 to
9becd3a
Compare
| }; | ||
|
|
||
| React.useEffect(() => { | ||
| const validationState = !isEmpty() && ValidatedOptions.error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line just needs to be updated so that it sets the validated state correctly; right now it's having the opposite effect of a valid selection rendering the error icon in the example.
| const validationState = !isEmpty() && ValidatedOptions.error; | |
| const validationState = isEmpty() && ValidatedOptions.error; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so iiuc, only Select a number option should be invalid? If this is the case, won't it be better to use e.g. 3 as the only valid option and add to corresponding FormSelectOptions label that this is the only valid option? Similarly as in Validated example.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay so iiuc, only Select a number option should be invalid?
That's what it seemed like the intention originally was, at least based on the variable being named isEmpty.
If this is the case, won't it be better to use e.g. 3 as the only valid option and add to corresponding FormSelectOptions label that this is the only valid option? Similarly as in Validated example.
I think either way could work really. While both Validated and Invalid examples are very similar, the main difference just seems to be that the Validate example shows various states of validation instead of only an error like the Invalid example does. As long as that remains true, reusing the onChange from the Validate example and tweaking it to not use helper text or simulate a network call could work (this would also make the useEffect unnecessary)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, so I kept the original example, it does what we need it to do so it's probably not necessary to make it more complicated.
9becd3a to
cd90249
Compare
thatblindgeye
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thank you for working on this! 💪🏼
tlabaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mcarrano I think we can actually remove the "invalid" example. It is from before we hd the different "validated" states. I don't remember if we kept it for a reason.
Sounds good to me. |
Signed-off-by: Tomas Psota <tpsota@redhat.com>
cd90249 to
a00495f
Compare
tlabaj
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
chore(FormSelect): convert examples to TypeScript
Signed-off-by: Tomas Psota tpsota@redhat.com
What: Closes #7475