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(explore): Dashboard list is unsorted in save modal #21317

Merged
merged 7 commits into from
Oct 3, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions superset-frontend/src/explore/actions/saveModalActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,17 @@ export function fetchDashboards(userId) {
value: id,
label: (json.result[index] || {}).dashboard_title,
}));
choices.sort((a, b) => {
const labelA = a.label.toUpperCase();
const labelB = b.label.toUpperCase();
if (labelA < labelB) {
return -1;
}
if (labelA > labelB) {
return 1;
}
return 0;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (labelA < labelB) {
return -1;
}
if (labelA > labelB) {
return 1;
}
return 0;
return labelA.localeCompare(labelB);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@michael-s-molina @geido Made a change so that when a string begins with a number it sorts numerically instead. Does not fix all the cases but addresses several.

Copy link
Member

Choose a reason for hiding this comment

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

@agl-developer What you're trying to achieve is a concept called Natural Sorting. This is already supported natively by localeCompare using { sensitivity: 'base', numeric: true }

});

return dispatch(fetchDashboardsSucceeded(choices));
})
Expand Down