From 22a71036963b16cba40e04c67763246e6ff51ba9 Mon Sep 17 00:00:00 2001 From: Bartosz Prusinowski Date: Mon, 14 Nov 2022 10:22:18 +0100 Subject: [PATCH] feat: Show hierarchy values with no parent at bottom --- app/configurator/components/filters.tsx | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/app/configurator/components/filters.tsx b/app/configurator/components/filters.tsx index 773d664d4..55abd1b8f 100644 --- a/app/configurator/components/filters.tsx +++ b/app/configurator/components/filters.tsx @@ -230,12 +230,17 @@ const MultiFilterContent = ({ const values = ( (rawValues?.type === "multi" && Object.keys(rawValues.values)) || Object.keys(optionsByValue) - ).map((v) => optionsByValue[v]); + ) + .map((v) => optionsByValue[v]) + .filter(isHierarchyOptionSelectable); const grouped = groups(values, groupByParent) - .sort( - (a, b) => - ascending(explodeParents(a[0]).length, explodeParents(b[0]).length) || - ascending(a[0], b[0]) + .sort((a, b) => + a[0].length === 0 + ? 1 + : ascending( + explodeParents(a[0]).length, + explodeParents(b[0]).length + ) || ascending(a[0], b[0]) ) .map(([parent, group]) => { return [ @@ -243,10 +248,11 @@ const MultiFilterContent = ({ group.sort( (a, b) => ascending(a.position ?? 0, b.position ?? 0) || - ascending(a.label, b.label) + ascending(a.label.toLowerCase(), b.label.toLowerCase()) ), ] as const; }); + return { values, valueGroups: grouped,