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: Extract common select component code #21094

Merged

Conversation

cccs-RyanK
Copy link
Contributor

Recently in the ongoing effort to clean up the select component, it was split into Sync and Async components. After splitting they shared alot of common code. This PR is to move some of the shared code into a new common file that each of the components can import from in order to better reuse code.

Overall task is outlined here: #20143

SUMMARY

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • [ x ] Has associated issue: feat: Adds the "Select all" option to the Select component #20143
  • 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

@cccs-RyanK cccs-RyanK marked this pull request as ready for review August 15, 2022 18:20
@codecov
Copy link

codecov bot commented Aug 18, 2022

Codecov Report

Merging #21094 (1f9ac36) into master (99a4f05) will increase coverage by 0.10%.
The diff coverage is 86.17%.

@@            Coverage Diff             @@
##           master   #21094      +/-   ##
==========================================
+ Coverage   66.45%   66.56%   +0.10%     
==========================================
  Files        1789     1791       +2     
  Lines       68296    68411     +115     
  Branches     7275     7302      +27     
==========================================
+ Hits        45387    45535     +148     
+ Misses      21034    20995      -39     
- Partials     1875     1881       +6     
Flag Coverage Δ
javascript 52.74% <86.17%> (+0.24%) ⬆️

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

Impacted Files Coverage Δ
.../src/dashboard/components/RefreshIntervalModal.tsx 80.00% <ø> (ø)
...c/filters/components/Select/SelectFilterPlugin.tsx 62.82% <ø> (ø)
...frontend/src/views/CRUD/alert/AlertReportModal.tsx 52.08% <ø> (ø)
superset-frontend/src/components/Select/utils.tsx 81.52% <81.52%> (ø)
...set-frontend/src/components/Select/AsyncSelect.tsx 84.61% <100.00%> (+1.14%) ⬆️
superset-frontend/src/components/Select/Select.tsx 92.55% <100.00%> (+5.13%) ⬆️
...e/components/controls/SelectAsyncControl/index.tsx 54.83% <100.00%> (ø)
...s/CRUD/data/dataset/AddDataset/LeftPanel/index.tsx 46.42% <0.00%> (-53.58%) ⬇️
...cy-preset-chart-nvd3/src/TimePivot/controlPanel.ts 33.33% <0.00%> (-16.67%) ⬇️
...t-controls/src/sections/echartsTimeSeriesQuery.tsx 33.33% <0.00%> (-16.67%) ⬇️
... and 54 more

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@geido
Copy link
Member

geido commented Aug 22, 2022

Hi @cccs-RyanK. Thanks for this! Before I dive into the code I have a general comment.
I am not very fond of the idea of having constants, types and common components all within a common file. If we are opting for separation then I believe it makes sense to separate things a bit more.

I'd prefer to see a structure similar to this one:

  • types.ts: Containing all the shared types
  • utils.ts: Containing shared functions and constants
  • BaseSelect.tsx: containing the shared component
  • This is optional, but we could also have a styles.ts for the common styled components

@michael-s-molina what's your thought about this?

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

Thank you so much for PR @cccs-RyanK! I left some first-pass comments.

superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
superset-frontend/src/components/Select/common.tsx Outdated Show resolved Hide resolved
@michael-s-molina
Copy link
Member

michael-s-molina commented Aug 24, 2022

Hi @cccs-RyanK. Thanks for this! Before I dive into the code I have a general comment. I am not very fond of the idea of having constants, types and common components all within a common file. If we are opting for separation then I believe it makes sense to separate things a bit more.

I'd prefer to see a structure similar to this one:

  • types.ts: Containing all the shared types
  • utils.ts: Containing shared functions and constants
  • BaseSelect.tsx: containing the shared component
  • This is optional, but we could also have a styles.ts for the common styled components

@michael-s-molina what's your thought about this?

What I generally do is to keep things in context and depending on the size of things, break them into related submodules. One thing I don't like is mixing things that belong to different components. For example, I don't like to have a types.ts that contains all sync and async types because they are not shared. When things get bigger, and I have many types or styled-components, then I generally create your suggested structure but under each component folder like this:

AsyncSelect
  types.ts
  styles.ts
  test.ts
  index.ts
Select
  types.ts
  styles.ts
  test.ts
  index.ts
utils.ts (shared)
types.ts (shared)

If I have a few types or styled-components, I generally define them in the component.

@geido
Copy link
Member

geido commented Aug 24, 2022

AsyncSelect
  types.ts
  styles.ts
  test.ts
  index.ts
Select
  types.ts
  styles.ts
  test.ts
  index.ts
utils.ts (shared)
types.ts (shared)

If I have a few types or styled-components, I generally define them in the component.

This makes sense but I still believe we should not have all the shared parts under one utils file even though this is not very big. For instance, I don't see why styles should be under utils.

@michael-s-molina
Copy link
Member

This makes sense but I still believe we should not have all the shared parts under one utils file even though this is not very big. For instance, I don't see why styles should be under utils.

Maybe I was not clear but in my example styles would never be under utils. It would belong to the component file if we have a few of them, or to a styles submodule if we have many. So I think we're in agreement.

Copy link
Member

@michael-s-molina michael-s-molina left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for all the hard work @cccs-RyanK!

@michael-s-molina michael-s-molina merged commit 4fcc1d9 into apache:master Sep 15, 2022
@mistercrunch mistercrunch added 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels 🚢 2.1.0 and removed 🚢 2.1.3 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 size/XXL 🚢 2.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants