feat: per-group sort order (defined/alpha) in group form and converter
This commit is contained in:
@@ -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 });
|
||||
|
||||
Reference in New Issue
Block a user