From b83ea1f682cb0f21f870fd556069fd77e8093260 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 11 May 2022 09:04:33 +0100 Subject: [PATCH] Update screen sorting to sort using url param order --- packages/builder/src/builderStore/index.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 842b193a40..1dd1df0cd3 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -28,8 +28,18 @@ export const sortedScreens = derived(store, $store => { if (homeA !== homeB) { return homeA ? -1 : 1 } - // Finally sort alphabetically by route - return a.routing.route < b.routing.route ? -1 : 1 + // Then sort alphabetically by each URL param + const aParams = a.routing.route.split("/") + const bParams = b.routing.route.split("/") + let minParams = Math.min(aParams.length, bParams.length) + for (let i = 0; i < minParams; i++) { + if (aParams[i] === bParams[i]) { + continue + } + return aParams[i] < bParams[i] ? -1 : 1 + } + // Then sort by the fewest amount of URL params + return aParams.length < bParams.length ? -1 : 1 }) })