Skip to content

Commit

Permalink
Merge pull request #18 from newera-systems/hotfix/rulesOrder
Browse files Browse the repository at this point in the history
order by entity, then by identifier for better searching
  • Loading branch information
sadortun authored Oct 5, 2023
2 parents 9db00c6 + 4139e15 commit c2b062b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/components/builder/GroupCtrlSlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
},
Expand Down

0 comments on commit c2b062b

Please sign in to comment.