From 1317f5e8fbbe185be71add11135f1425e843ecc9 Mon Sep 17 00:00:00 2001 From: Falkan Date: Tue, 17 Mar 2026 19:59:02 -0400 Subject: [PATCH] feat: per-group sort order (defined/alpha) in group form and converter --- src/lib/types.ts | 2 ++ src/routes/+page.svelte | 9 +++++++-- src/routes/admin/+page.svelte | 9 +++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/lib/types.ts b/src/lib/types.ts index 6118920..8997951 100644 --- a/src/lib/types.ts +++ b/src/lib/types.ts @@ -37,6 +37,8 @@ export interface Group { baseUnitId: string; /** Relative scale for cross-group YOLO conversions. */ toUniversal: number; + /** Display order for units in the converter. Defaults to 'defined'. */ + sortOrder?: 'defined' | 'alpha'; } /** Full data payload for units and groups. */ diff --git a/src/routes/+page.svelte b/src/routes/+page.svelte index 59ae9f8..0f196ad 100644 --- a/src/routes/+page.svelte +++ b/src/routes/+page.svelte @@ -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(); @@ -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 }); diff --git a/src/routes/admin/+page.svelte b/src/routes/admin/+page.svelte index a93d8af..d3ba651 100644 --- a/src/routes/admin/+page.svelte +++ b/src/routes/admin/+page.svelte @@ -803,6 +803,15 @@ Relative scale for cross-group (YOLO) conversions. Arbitrary. +
{#if !groupFormNew}