ui improvement
This commit is contained in:
@@ -196,3 +196,44 @@ export function aisleIdForCategory(
|
||||
if (!aisle) return 0;
|
||||
return aisleIds.get(aisle.toLowerCase()) ?? FALLBACK_AISLE_IDS[aisle];
|
||||
}
|
||||
|
||||
/**
|
||||
* The aisle name to PRINT for a product, on a row or in a drawer.
|
||||
*
|
||||
* This exists because the table and the drawer each grew their own version of
|
||||
* it and they disagreed: the row fell back to `categoryname` when the platform
|
||||
* list had no entry for the product's `subcategoryid`, and the drawer did not —
|
||||
* so the same product read "Dairy" in the list and "Uncategorized" the moment
|
||||
* you opened it. There is one answer to "where does the app show this", and it
|
||||
* is here.
|
||||
*
|
||||
* Blank is treated as absent, which `??` alone does not do. `categoryname` is
|
||||
* empty on every row `getlocationproducts` returns — the app's category 2 has
|
||||
* no row in `productcategories` — and falling back to an empty string printed a
|
||||
* blank cell where "Uncategorized" is the truth: it is the heading the customer
|
||||
* app will actually render for a product with no aisle.
|
||||
*/
|
||||
export function aisleLabelOf(
|
||||
product: {
|
||||
subcategoryid?: number | undefined;
|
||||
categoryname?: string | undefined;
|
||||
Subcategoryname?: string | undefined;
|
||||
},
|
||||
aisleNames: ReadonlyMap<number, string>,
|
||||
): string {
|
||||
const named = aisleNames.get(product.subcategoryid ?? 0);
|
||||
return (
|
||||
firstFilled(named, product.categoryname, product.Subcategoryname) ?? UNCATEGORISED_AISLE
|
||||
);
|
||||
}
|
||||
|
||||
/** The heading the customer app prints for anything with no aisle. */
|
||||
export const UNCATEGORISED_AISLE = 'Uncategorized';
|
||||
|
||||
function firstFilled(...values: (string | undefined)[]): string | undefined {
|
||||
for (const value of values) {
|
||||
const trimmed = value?.trim();
|
||||
if (trimmed) return trimmed;
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user