From 4139e159639e169b55860cf81c24daf65a41aff9 Mon Sep 17 00:00:00 2001 From: Josias Kasongo Date: Thu, 5 Oct 2023 18:11:37 -0400 Subject: [PATCH] order by entity, then by identifier for better searching --- src/components/builder/GroupCtrlSlot.vue | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/builder/GroupCtrlSlot.vue b/src/components/builder/GroupCtrlSlot.vue index 5ed9004..b015edb 100644 --- a/src/components/builder/GroupCtrlSlot.vue +++ b/src/components/builder/GroupCtrlSlot.vue @@ -92,13 +92,17 @@ export default defineComponent({ orderedRules(): RuleDefinitionWithChain[] { const rules = [...this.groupCtrl.rules] as RuleDefinitionWithChain[]; return rules.sort((a, b) => { - if (a.chain !== undefined && b.chain !== undefined) { - if (a.chain.length > b.chain?.length) { - return 1; - } else if (a.chain?.length < b.chain?.length) { - return -1; + const aChain = a.chain || []; + const bChain = b.chain || []; + for (let i = 0; i < Math.min(aChain.length, bChain.length); i++) { + const chainComparison = aChain[i].localeCompare(bChain[i]); + if (chainComparison !== 0) { + return chainComparison; } } + if (aChain.length !== bChain.length) { + return aChain.length - bChain.length; + } return a.identifier.localeCompare(b.identifier); }); },