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

chore: Select component refactoring - SelectAsyncControl - Iteration 5 #16609

Merged
merged 20 commits into from
Oct 7, 2021
Merged

chore: Select component refactoring - SelectAsyncControl - Iteration 5 #16609

merged 20 commits into from
Oct 7, 2021

Conversation

geido
Copy link
Member

@geido geido commented Sep 6, 2021

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

  1. Visit Explore
  2. Click on "Edit dataset"
  3. Click on "Settings"
  4. Change owners and observe the behavior of the Select

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

@geido geido added hold:testing! On hold for testing risk:refactor High risk as it involves large refactoring work labels Sep 6, 2021
@geido geido added this to In progress in AntD Transition (SIP-48) via automation Sep 6, 2021
@geido geido moved this from In progress to In review in AntD Transition (SIP-48) Sep 6, 2021
@codecov
Copy link

codecov bot commented Sep 6, 2021

Codecov Report

Merging #16609 (1c7ca57) into master (3f0756f) will decrease coverage by 0.00%.
The diff coverage is 79.48%.

Impacted file tree graph

@@            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     
Flag Coverage Δ
javascript 70.91% <79.48%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
superset-frontend/src/components/Select/Select.tsx 92.25% <50.00%> (-0.30%) ⬇️
...e/components/controls/SelectAsyncControl/index.tsx 81.08% <81.08%> (ø)
...ontend/src/dashboard/components/menu/HoverMenu.tsx 90.00% <0.00%> (-10.00%) ⬇️
...uperset-frontend/src/components/Menu/MenuRight.tsx 91.22% <0.00%> (-1.08%) ⬇️
...eFilters/FiltersConfigModal/FiltersConfigModal.tsx 88.46% <0.00%> (-0.97%) ⬇️
superset-frontend/src/chart/chartAction.js 50.47% <0.00%> (-0.49%) ⬇️
superset-frontend/src/views/menu.tsx 0.00% <0.00%> (ø)
...src/dashboard/components/gridComponents/Header.jsx 100.00% <0.00%> (ø)
...c/dashboard/components/gridComponents/Markdown.jsx 83.16% <0.00%> (ø)
...d/components/DashboardBuilder/DashboardBuilder.tsx 90.17% <0.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3f0756f...1c7ca57. Read the comment docs.

…e/select-component-refactoring-selectasynccontrol-iteration-5

interface SelectAsyncControlProps extends SelectAsyncProps {
addDangerToast: (error: string) => void;
ariaLabel?: string;
Copy link
Member

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! 😄

Copy link
Member Author

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.

@geido geido requested review from michael-s-molina, etr2460 and ktmud and removed request for michael-s-molina September 16, 2021 13:51
@geido geido removed the hold:testing! On hold for testing label Sep 16, 2021
@michael-s-molina
Copy link
Member

/testenv up

@github-actions
Copy link
Contributor

@michael-s-molina Ephemeral environment spinning up at http://54.245.47.145:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

value,
...props
}: SelectAsyncControlProps) => {
const [options, setOptions] = useState<OptionsType>([]);
Copy link
Member

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?

Copy link
Member Author

@geido geido Sep 17, 2021

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">
Copy link
Member

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?

geido and others added 2 commits September 21, 2021 13:54
…ontrol/index.tsx

Co-authored-by: David Aaron Suddjian <1858430+suddjian@users.noreply.github.com>
Copy link
Member

@villebro villebro left a 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

Comment on lines 59 to 67
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;
}
Copy link
Member

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)

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 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.

@geido geido merged commit a782a62 into apache:master Oct 7, 2021
@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2021

Ephemeral environment shutdown and build artifacts deleted.

opus-42 pushed a commit to opus-42/incubator-superset that referenced this pull request Nov 14, 2021
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>
@eschutho eschutho added the v1.4 label Nov 22, 2021
eschutho pushed a commit that referenced this pull request Nov 22, 2021
#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>
QAlexBall pushed a commit to QAlexBall/superset that referenced this pull request Dec 28, 2021
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>
@mistercrunch mistercrunch added 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 1.5.0 labels Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels hold:testing! On hold for testing risk:refactor High risk as it involves large refactoring work size/L test_priority:high v1.4 🍒 1.4.0 🍒 1.4.1 🍒 1.4.2 🚢 1.5.0
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

8 participants