-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
chore: Select component refactoring - SelectAsyncControl - Iteration 5 #16609
chore: Select component refactoring - SelectAsyncControl - Iteration 5 #16609
Conversation
…e/select-component-refactoring-selectasynccontrol-iteration-5
Codecov Report
@@ Coverage Diff @@
## master #16609 +/- ##
==========================================
- Coverage 76.93% 76.92% -0.01%
==========================================
Files 1030 1030
Lines 55023 55043 +20
Branches 7463 7473 +10
==========================================
+ Hits 42332 42344 +12
- Misses 12438 12445 +7
- Partials 253 254 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
…e/select-component-refactoring-selectasynccontrol-iteration-5
|
||
interface SelectAsyncControlProps extends SelectAsyncProps { | ||
addDangerToast: (error: string) => void; | ||
ariaLabel?: string; |
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.
Maybe at some point, we should make this required! 😄
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.
True. However, we would need to act on superset-ui as well. ariaLabel
is required for the Select component itself.
…e/select-component-refactoring-selectasynccontrol-iteration-5
/testenv up |
@michael-s-molina Ephemeral environment spinning up at http://54.245.47.145:8080. Credentials are |
value, | ||
...props | ||
}: SelectAsyncControlProps) => { | ||
const [options, setOptions] = useState<OptionsType>([]); |
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.
Do we need to keep the options
state? Can't we just pass loadOptions
directly to the Select
?
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.
There is a mutator
function that is expecting to get an object with a result
property. In order to make sure the mutator
gets the right data this is the shortest path. Otherwise, we would need to wait for the options to be loaded by the Select component itself and then mutate those options, but that would require changing the mutator
functions everywhere, also in superset-ui. I didn't want to make changes to the superset-ui a dependency for this PR.
}, [dataEndpoint, mutator]); | ||
|
||
return ( | ||
<div data-test="SelectAsyncControl"> |
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.
Do we need this div
?
superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx
Outdated
Show resolved
Hide resolved
…ontrol/index.tsx Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
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 with one minor comment about the type checking code
if (Array.isArray(val)) { | ||
const values = val.map(v => | ||
typeof v === 'object' && 'value' in v ? v.value : v, | ||
); | ||
onChangeVal = values as string[] | number[]; | ||
} | ||
if (typeof val === 'object' && (val as LabeledValue)?.value) { | ||
onChangeVal = (val as LabeledValue).value; | ||
} |
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.
Could be nice to replace these type checks with type guards (I notice there's quite a few similar ones for AntdLabeledValue
in Select/Select.tsx
that could benefit from type guards, too)
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 is a great suggestion @villebro. For now, I implemented it here but I do agree we should go back to the Select component and add type guards wherever it makes sense.
Ephemeral environment shutdown and build artifacts deleted. |
apache#16609) * Refactor Select * Implement onError * Separate async request * Lint * Allow clear * Improve type * Reconcile with Select latest changes * Fix handleOnChange * Clean up * Add placeholder * Accept null values * Update superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> * Clean up * Implement type guard * Fix lint * Catch error within loadOptions Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
#16609) * Refactor Select * Implement onError * Separate async request * Lint * Allow clear * Improve type * Reconcile with Select latest changes * Fix handleOnChange * Clean up * Add placeholder * Accept null values * Update superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> * Clean up * Implement type guard * Fix lint * Catch error within loadOptions Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
apache#16609) * Refactor Select * Implement onError * Separate async request * Lint * Allow clear * Improve type * Reconcile with Select latest changes * Fix handleOnChange * Clean up * Add placeholder * Accept null values * Update superset-frontend/src/explore/components/controls/SelectAsyncControl/index.tsx Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com> * Clean up * Implement type guard * Fix lint * Catch error within loadOptions Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
SUMMARY
This PR replaces the react-select Select with the Antdesign Select in the SelectAsyncControl component.
BEFORE/AFTER
SelectAsyncControl_before.mp4
SelectAsyncControl_after.mp4
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION