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

fix: Order of Select items when unselecting #17169

Conversation

michael-s-molina
Copy link
Member

SUMMARY

The objective of this PR is to fix an issue with the order of select options when unselecting. It also changes the default sorting algorithm of the Select component to alphabetical sorting while providing an alternative to the component's users to override this behavior. Alphabetical sorting is the most common sorting algorithm used by select components in Superset but we do have cases where the order is calculated by different criteria. Another objective of the solution is to enable server-side sorting.

To fill these objectives, this PR introduced an optional property to the Select called sortCompator that accepts a comparison function and is set to alphabetical comparison by default. This function accepts any object that adheres to the select options interface which allows custom properties to be used when comparing the options. This can be used by server-side sorting, where the response can include an order field or similar to be used in a custom sort comparator.

This comparator is also important to reorder the items after an unselect action because we don't know the original order of the elements, especially with server-side sorting.

This PR also:

  • Includes test cases for the new property
  • Removes previous sorting related code to avoid duplication
  • Modifies previous sorting related code to use a custom comparator when necessary

@geido Can you include this information in the Select API docs?

@yousoph @rusackas @hughhhh @junlincc

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

Screen.Recording.2021-10-20.at.11.04.20.AM.mov
Screen.Recording.2021-10-20.at.11.06.25.AM.mov

TESTING INSTRUCTIONS

Check the videos for instructions

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

@codecov
Copy link

codecov bot commented Oct 20, 2021

Codecov Report

Merging #17169 (4af7286) into master (96f4421) will increase coverage by 0.02%.
The diff coverage is 93.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #17169      +/-   ##
==========================================
+ Coverage   76.91%   76.94%   +0.02%     
==========================================
  Files        1038     1039       +1     
  Lines       55557    55592      +35     
  Branches     7567     7584      +17     
==========================================
+ Hits        42731    42774      +43     
+ Misses      12576    12568       -8     
  Partials      250      250              
Flag Coverage Δ
javascript 70.99% <93.33%> (+0.06%) ⬆️

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

Impacted Files Coverage Δ
...perset-frontend/src/addSlice/AddSliceContainer.tsx 62.06% <0.00%> (+2.06%) ⬆️
...tersConfigModal/FiltersConfigForm/ColumnSelect.tsx 96.07% <ø> (-0.08%) ⬇️
...ersConfigModal/FiltersConfigForm/DatasetSelect.tsx 50.00% <0.00%> (+1.51%) ⬆️
...ore/components/controls/DateFilterControl/types.ts 100.00% <ø> (ø)
superset-frontend/src/components/Select/Select.tsx 92.35% <96.66%> (+0.10%) ⬆️
...frontend/src/components/DatabaseSelector/index.tsx 95.00% <100.00%> (-0.13%) ⬇️
...et-frontend/src/components/TableSelector/index.tsx 74.28% <100.00%> (-0.25%) ⬇️
...frontend/src/components/TimezoneSelector/index.tsx 97.72% <100.00%> (-0.06%) ⬇️
.../src/dashboard/components/RefreshIntervalModal.tsx 89.47% <100.00%> (ø)
...onalFormattingControl/FormattingPopoverContent.tsx 53.06% <100.00%> (ø)
... and 25 more

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 96f4421...4af7286. Read the comment docs.

@geido
Copy link
Member

geido commented Oct 20, 2021

As discussed, I think it would be great to have a central place where the sorting functions can be defined to avoid repetition in the code.

@michael-s-molina
Copy link
Member Author

michael-s-molina commented Oct 20, 2021

As discussed, I think it would be great to have a central place where the sorting functions can be defined to avoid repetition in the code.

That's a great idea! We can have functions that take into consideration a specific property, handle numeric types, etc.

@yousoph
Copy link
Member

yousoph commented Oct 22, 2021

/testenv up

@github-actions
Copy link
Contributor

@yousoph Ephemeral environment spinning up at http://54.189.67.76:8080. Credentials are admin/admin. Please allow several minutes for bootstrapping and startup.

@yousoph
Copy link
Member

yousoph commented Oct 22, 2021

Tested a bit on the ephemeral, looking good to me. Thanks @michael-s-molina !

Copy link
Member

@geido geido 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 the improvement!

@michael-s-molina michael-s-molina merged commit 55be249 into apache:master Oct 25, 2021
@github-actions
Copy link
Contributor

Ephemeral environment shutdown and build artifacts deleted.

@mistercrunch mistercrunch added 🏷️ 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 size/L 🚢 1.5.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants