feat: per-group sort order (defined/alpha) in group form and converter

This commit is contained in:
Falkan
2026-03-17 19:59:02 -04:00
parent 6d72242aaa
commit 1317f5e8fb
3 changed files with 18 additions and 2 deletions

View File

@@ -133,7 +133,7 @@
fromUnitId = id;
}
// ── Group units for display — single O(n) pass ──────────────────────────────
// ── Derived: results per group for display — single O(n) pass ──────────────
let orderedResults: { groupLabel: string | null; items: ResultItem[] }[] = $derived.by(() => {
// Build a Map of groupId → items in a single pass over results
const byGroup = new Map<string | null, ResultItem[]>();
@@ -147,7 +147,12 @@
const sections: { groupLabel: string | null; items: ResultItem[] }[] = [];
for (const group of groups) {
const items = byGroup.get(group.id);
if (items?.length) sections.push({ groupLabel: group.label, items });
if (items?.length) {
const sorted = group.sortOrder === 'alpha'
? [...items].sort((a, b) => a.unit.label.localeCompare(b.unit.label))
: items;
sections.push({ groupLabel: group.label, items: sorted });
}
}
const orphaned = byGroup.get(null);
if (orphaned?.length) sections.push({ groupLabel: 'Ungrouped', items: orphaned });