From 5ac52a531f1fd1468aed7ab5a87853d4c8f2cf5f Mon Sep 17 00:00:00 2001 From: Adam Armistead <37308565+adamarmistead@users.noreply.github.com> Date: Thu, 14 Nov 2024 20:04:59 -0800 Subject: [PATCH] feat: Natural sort collection names with numbers Sorts collections by name in alphabetical order Collections with numbers in the names are sorted in numerical order. Results in `['Test 10', 'Test 2', 'Test 1']` being sorted to: `['Test 1', 'Test 2', 'Test 10']` instead of: `['Test 1', 'Test 10', 'Test 2']` Accurately sorts numbers with decimals as well. --- .../src/providers/ReduxStore/slices/collections/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js index 58efc93e0..43fc1c946 100644 --- a/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js +++ b/packages/bruno-app/src/providers/ReduxStore/slices/collections/index.js @@ -90,15 +90,16 @@ export const collectionsSlice = createSlice({ }, sortCollections: (state, action) => { state.collectionSortOrder = action.payload.order; + const collator = new Intl.Collator(undefined, {numeric: true, sensitivity: 'base'}); switch (action.payload.order) { case 'default': state.collections = state.collections.sort((a, b) => a.importedAt - b.importedAt); break; case 'alphabetical': - state.collections = state.collections.sort((a, b) => a.name.localeCompare(b.name)); + state.collections = state.collections.sort((a, b) => collator.compare(a.name, b.name)); break; case 'reverseAlphabetical': - state.collections = state.collections.sort((a, b) => b.name.localeCompare(a.name)); + state.collections = state.collections.sort((a, b) => -collator.compare(a.name, b.name)); break; } },