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(sqllab): Sort db selector options by the API order #28749

Conversation

justinpark
Copy link
Member

@justinpark justinpark commented May 29, 2024

SUMMARY

Currently, the order of the db selector dropdown in SQL Lab is always sorted by record ID, regardless of the intended sort order.
This issue arises due to two reasons:

  1. an incorrect order_column name is being passed
  2. AsyncSelect component's default sortComparator is sorting by ID (Since label is not a string, the next ordering will be by id).

This commit fixes these issues, ensuring that the db selector is sorted by the API order as intended.

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

Added unit tests.

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

@dosubot dosubot bot added change:frontend Requires changing the frontend sqllab Namespace | Anything related to the SQL Lab labels May 29, 2024
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.

@justinpark if you look at the default DEFAULT_SORT_COMPARATOR implementation, you can see that it will sort items alphabetically if label is of type string. In this case, it's not sorting alphabetically because label is being set to a React component here instead of using customLabel for that purpose. If you set label to database_name and customLabel to the React component, you'll get the desired behavior.

@justinpark
Copy link
Member Author

justinpark if you look at the default DEFAULT_SORT_COMPARATOR implementation, you can see that it will sort items alphabetically if label is of type string. In this case, it's not sorting alphabetically because label is being set to a React component here instead of using customLabel for that purpose. If you set label to database_name and customLabel to the React component, you'll get the desired behavior.

You are right, but I think that if the API that includes the actual sorting items is implemented, we would want the results to be sorted according to the API. Also, relying on client-side sorting can lead to inconsistencies, especially when handling paginated results, so I believe it is better to follow the API's results.

Additionally, I have optimized the code to use the suggested order field.

@michael-s-molina
Copy link
Member

@justinpark Could you also update the PR description to say that the objective is to sort by the API order?

@justinpark justinpark changed the title fix(sqllab): invalid sorting order on db selector fix(sqllab): Sort db selector options by the API order May 29, 2024
@justinpark justinpark merged commit 453a645 into apache:master May 29, 2024
35 checks passed
@michael-s-molina michael-s-molina added the v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch label May 30, 2024
EnxDev pushed a commit to EnxDev/superset that referenced this pull request May 31, 2024
@mistercrunch mistercrunch added 🍒 4.0.2 🏷️ bot A label used by `supersetbot` to keep track of which PR where auto-tagged with release labels labels Jul 24, 2024
vinothkumar66 pushed a commit to vinothkumar66/superset that referenced this pull request Nov 11, 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 change:frontend Requires changing the frontend size/M sqllab Namespace | Anything related to the SQL Lab v4.0 Label added by the release manager to track PRs to be included in the 4.0 branch 🍒 4.0.2 🚢 4.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants