@mohasinac/appkit 4.42.10 → 4.42.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -49,11 +49,32 @@ export function useCategoriesFiltered(params = {}) {
|
|
|
49
49
|
items = items.filter((c) => (c.productCount ?? 0) >= minProductCount);
|
|
50
50
|
if (maxProductCount !== undefined)
|
|
51
51
|
items = items.filter((c) => (c.productCount ?? 0) <= maxProductCount);
|
|
52
|
+
/*
|
|
53
|
+
* 🛑 This comparator is the ONLY thing that orders the category index —
|
|
54
|
+
* `sort` is never sent to the API (the request is `?flat=true` and nothing
|
|
55
|
+
* else), so an unrecognised value does not fall back to a server ordering,
|
|
56
|
+
* it falls through to name ASC right here. That is how the tier sort
|
|
57
|
+
* shipped "fixed" and stayed broken: CategoriesIndexListing declared
|
|
58
|
+
* DEFAULT_SORT = tier ASC and offered a "Top level first" option, both
|
|
59
|
+
* correct, and this switch had never heard of tier — so the roots stayed
|
|
60
|
+
* off page 1 while four source reads said the code was right.
|
|
61
|
+
*
|
|
62
|
+
* Add a case here for every value in SORT_OPTIONS, or the option is
|
|
63
|
+
* decoration.
|
|
64
|
+
*/
|
|
52
65
|
items = [...items].sort((a, b) => {
|
|
53
66
|
if (sort === "-productCount")
|
|
54
67
|
return (b.productCount ?? 0) - (a.productCount ?? 0);
|
|
68
|
+
if (sort === "productCount")
|
|
69
|
+
return (a.productCount ?? 0) - (b.productCount ?? 0);
|
|
55
70
|
if (sort === "-name")
|
|
56
71
|
return b.name.localeCompare(a.name);
|
|
72
|
+
/* Tier ascending puts the roots first; name breaks ties within a tier. */
|
|
73
|
+
if (sort === "tier" || sort === "-tier") {
|
|
74
|
+
const dir = sort === "tier" ? 1 : -1;
|
|
75
|
+
const d = (a.tier ?? 0) - (b.tier ?? 0);
|
|
76
|
+
return d !== 0 ? d * dir : a.name.localeCompare(b.name);
|
|
77
|
+
}
|
|
57
78
|
return a.name.localeCompare(b.name);
|
|
58
79
|
});
|
|
59
80
|
const total = items.length;
|