From 99389961ab2bab3f78a2a4809a2742a1bafefcfc Mon Sep 17 00:00:00 2001 From: Herbert Gainor Date: Fri, 2 Sep 2022 18:31:21 -0600 Subject: [PATCH 1/4] Sort dashboard list alphabetically when saving a chart --- .../src/explore/actions/saveModalActions.js | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/superset-frontend/src/explore/actions/saveModalActions.js b/superset-frontend/src/explore/actions/saveModalActions.js index 2ad6e55490696..c3c875f4c71d2 100644 --- a/superset-frontend/src/explore/actions/saveModalActions.js +++ b/superset-frontend/src/explore/actions/saveModalActions.js @@ -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; + }); return dispatch(fetchDashboardsSucceeded(choices)); }) From 2938bda00d0798050581025b23a391d7c084fef5 Mon Sep 17 00:00:00 2001 From: Herbert Gainor Date: Mon, 26 Sep 2022 18:54:48 -0600 Subject: [PATCH 2/4] When strings start with numbers sort by numeric order --- .../src/explore/actions/saveModalActions.js | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/explore/actions/saveModalActions.js b/superset-frontend/src/explore/actions/saveModalActions.js index b5e79657d123f..047c692be15fa 100644 --- a/superset-frontend/src/explore/actions/saveModalActions.js +++ b/superset-frontend/src/explore/actions/saveModalActions.js @@ -46,13 +46,12 @@ export function fetchDashboards(userId) { choices.sort((a, b) => { const labelA = a.label.toUpperCase(); const labelB = b.label.toUpperCase(); - if (labelA < labelB) { - return -1; + const labelAMatch = labelA.match(/^(\d+)/g); + const labelBMatch = labelB.match(/^(\d+)/g); + if (!!labelAMatch && !!labelBMatch) { + return Number(labelAMatch[0]) - Number(labelBMatch[0]); } - if (labelA > labelB) { - return 1; - } - return 0; + return labelA.localeCompare(labelB); }); return dispatch(fetchDashboardsSucceeded(choices)); From 7bd19da0818a0b6c6693bf15d39dd4dc33191366 Mon Sep 17 00:00:00 2001 From: Herbert Gainor Date: Mon, 26 Sep 2022 18:54:48 -0600 Subject: [PATCH 3/4] Use localeCompare with Natural Sorting --- .../src/explore/actions/saveModalActions.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/superset-frontend/src/explore/actions/saveModalActions.js b/superset-frontend/src/explore/actions/saveModalActions.js index b5e79657d123f..2c884231d2705 100644 --- a/superset-frontend/src/explore/actions/saveModalActions.js +++ b/superset-frontend/src/explore/actions/saveModalActions.js @@ -46,13 +46,10 @@ export function fetchDashboards(userId) { 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; + return labelA.localeCompare(labelB, { + sensitivity: 'base', + numeric: true, + }); }); return dispatch(fetchDashboardsSucceeded(choices)); From c90e2233b62b0d3d3ba226b86fd5ebc063b750e4 Mon Sep 17 00:00:00 2001 From: Herbert Gainor Date: Fri, 30 Sep 2022 10:55:36 -0600 Subject: [PATCH 4/4] Small refactor --- .../src/explore/actions/saveModalActions.js | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/superset-frontend/src/explore/actions/saveModalActions.js b/superset-frontend/src/explore/actions/saveModalActions.js index 2c884231d2705..1764a009c3cfc 100644 --- a/superset-frontend/src/explore/actions/saveModalActions.js +++ b/superset-frontend/src/explore/actions/saveModalActions.js @@ -43,14 +43,12 @@ 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(); - return labelA.localeCompare(labelB, { + choices.sort((a, b) => + a.label.localeCompare(b.label, { sensitivity: 'base', numeric: true, - }); - }); + }), + ); return dispatch(fetchDashboardsSucceeded(choices)); })