fix: alpha sort by labelPlural primary, symbol secondary

Handles ties like 'Barrel (US fluid)' vs 'Barrel (US dry)'
This commit is contained in:
Falkan
2026-03-18 21:13:17 -04:00
parent 1c6dc7984a
commit 8ec935d238
2 changed files with 23 additions and 11 deletions

View File

@@ -7,7 +7,7 @@
"symbol": "dl",
"group": "dickloads",
"toBase": 1,
"description": "See {pound:description}"
"description": "See {pound:description}. Let's also look at {us-oil-bbl}."
},
{
"id": "pound",
@@ -19,10 +19,10 @@
"description": "My description is {dickload:description}"
},
{
"id": "barrel",
"label": "barrel",
"labelPlural": "barrels",
"symbol": "bbl",
"id": "us-oil-bbl",
"label": "oil barrel (US)",
"labelPlural": "oil barrels (US)",
"symbol": "us oil bbl",
"group": "dickloads",
"toBase": 13.3192584,
"description": "Weight is based on pure water at 4 degrees celsius.",
@@ -106,26 +106,35 @@
},
{
"id": "us-fluid-bbl",
"label": "US fluid barrel",
"labelPlural": "US fluid barrels",
"label": "barrel",
"labelPlural": "barrels",
"symbol": "us fluid bbl",
"group": "dickloads",
"toBase": 9.9894438
},
{
"id": "us-dry-bbl",
"label": "US dry barrel",
"labelPlural": "US dry barrels",
"label": "dry barrel",
"labelPlural": "dry barrels",
"symbol": "us dry bbl",
"group": "dickloads",
"toBase": 1
},
{
"id": "us-hogshead",
"label": "hogshead (US)",
"labelPlural": "hogsheads (US)",
"symbol": "us hhd",
"group": "dickloads",
"toBase": 19.9788876,
"description": "Equal to two US fluid barrels."
}
],
"groups": [
{
"id": "dickloads",
"label": "Weights and Masses",
"baseUnitId": "",
"baseUnitId": "dickload",
"toUniversal": 1,
"sortOrder": "alpha",
"hidden": false,

View File

@@ -153,7 +153,10 @@
const items = byGroup.get(group.id);
if (items?.length) {
const sorted = group.sortOrder === 'alpha'
? [...items].sort((a, b) => a.unit.label.localeCompare(b.unit.label))
? [...items].sort((a, b) => {
const labelCmp = a.unit.labelPlural.localeCompare(b.unit.labelPlural);
return labelCmp !== 0 ? labelCmp : a.unit.symbol.localeCompare(b.unit.symbol);
})
: items;
sections.push({ groupLabel: group.label, alwaysShowLabel: group.alwaysShowLabel ?? false, items: sorted });
}