From 5316382113c36dcf6561e929b54ce94fb94e595a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 9 Apr 2022 21:19:12 -0700 Subject: [PATCH] New: Natural Sorting Manual Import Relative Paths (cherry picked from commit bdd5865876796bc203c8117418a5389afc8b5f11) --- .../src/Store/Actions/interactiveImportActions.js | 3 ++- frontend/src/Utilities/String/naturalExpansion.js | 11 +++++++++++ frontend/src/Utilities/String/titleCase.js | 4 +++- 3 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Utilities/String/naturalExpansion.js diff --git a/frontend/src/Store/Actions/interactiveImportActions.js b/frontend/src/Store/Actions/interactiveImportActions.js index 8316340b0..6cf355c27 100644 --- a/frontend/src/Store/Actions/interactiveImportActions.js +++ b/frontend/src/Store/Actions/interactiveImportActions.js @@ -4,6 +4,7 @@ import { batchActions } from 'redux-batched-actions'; import { sortDirections } from 'Helpers/Props'; import { createThunk, handleThunks } from 'Store/thunks'; import createAjaxRequest from 'Utilities/createAjaxRequest'; +import naturalExpansion from 'Utilities/String/naturalExpansion'; import { set, update, updateItem } from './baseActions'; import createHandleActions from './Creators/createHandleActions'; import createSetClientSideCollectionSortReducer from './Creators/Reducers/createSetClientSideCollectionSortReducer'; @@ -35,7 +36,7 @@ export const defaultState = { relativePath: function(item, direction) { const relativePath = item.relativePath; - return relativePath.toLowerCase(); + return naturalExpansion(relativePath.toLowerCase()); }, movie: function(item, direction) { diff --git a/frontend/src/Utilities/String/naturalExpansion.js b/frontend/src/Utilities/String/naturalExpansion.js new file mode 100644 index 000000000..2cdd69b86 --- /dev/null +++ b/frontend/src/Utilities/String/naturalExpansion.js @@ -0,0 +1,11 @@ +const regex = /\d+/g; + +function naturalExpansion(input) { + if (!input) { + return ''; + } + + return input.replace(regex, (n) => n.padStart(8, '0')); +} + +export default naturalExpansion; diff --git a/frontend/src/Utilities/String/titleCase.js b/frontend/src/Utilities/String/titleCase.js index 5b76c10dd..03573b9e3 100644 --- a/frontend/src/Utilities/String/titleCase.js +++ b/frontend/src/Utilities/String/titleCase.js @@ -1,9 +1,11 @@ +const regex = /\b\w+/g; + function titleCase(input) { if (!input) { return ''; } - return input.replace(/\b\w+/g, (match) => { + return input.replace(regex, (match) => { return match.charAt(0).toUpperCase() + match.substr(1).toLowerCase(); }); }