Skip to content

Commit 4188bd4

Browse files
committed
fix: Sorting inside the multi filter panel drawer
1 parent 77750be commit 4188bd4

File tree

3 files changed

+23
-19
lines changed

3 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ You can also check the
1111

1212
## Unreleased
1313

14-
Nothing yet.
14+
- Fixes
15+
- Filter values inside multi filter drawer are now sorted correctly
1516

1617
### 6.1.0 - 2025-10-15
1718

app/configurator/components/filters.tsx

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -182,16 +182,18 @@ const groupByParent = (node: { parents: HierarchyValue[] }) => {
182182
return joinParents(node?.parents);
183183
};
184184

185+
export const sortFilterValue = (a: HierarchyValue, b: HierarchyValue) => {
186+
return (
187+
ascending(a.position ?? 0, b.position ?? 0) ||
188+
`${a.identifier}`.localeCompare(`${b.identifier}`, undefined, {
189+
numeric: true,
190+
}) ||
191+
a.label.localeCompare(b.label)
192+
);
193+
};
194+
185195
export const sortFilterValues = (values: HierarchyValue[]) => {
186-
return values.sort((a, b) => {
187-
return (
188-
ascending(a.position ?? 0, b.position ?? 0) ||
189-
`${a.identifier}`.localeCompare(`${b.identifier}`, undefined, {
190-
numeric: true,
191-
}) ||
192-
a.label.localeCompare(b.label)
193-
);
194-
});
196+
return values.sort(sortFilterValue);
195197
};
196198

197199
const getColorConfig = (chartConfig: ChartConfig) => {
@@ -278,7 +280,8 @@ const MultiFilterContent = ({
278280
const { sortedTree, flatOptions, optionsByValue } = useMemo(() => {
279281
const sortedTree = sortHierarchy(tree);
280282
const flatOptions = getOptionsFromTree(sortedTree);
281-
const optionsByValue = keyBy(flatOptions, (x) => x.value);
283+
const optionsByValue = keyBy(flatOptions, (option) => option.value);
284+
282285
return {
283286
sortedTree,
284287
flatOptions,

app/rdf/tree-utils.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import orderBy from "lodash/orderBy";
21
import sortBy from "lodash/sortBy";
32

3+
import { sortFilterValue } from "@/configurator/components/filters";
44
import { HierarchyValue } from "@/domain/data";
55
import { bfs } from "@/utils/bfs";
66

@@ -52,15 +52,15 @@ export const pruneTree = <T extends { children?: T[] | null }>(
5252
return filterTreeHelper(tree, isUsed);
5353
};
5454

55+
const sortTree = (tree: HierarchyValue[]): HierarchyValue[] => {
56+
return tree.sort((a, b) => {
57+
return b.depth - a.depth || sortFilterValue(a, b);
58+
});
59+
};
60+
5561
/** Sorts the tree by default chain of sorters (position -> identifier -> label). */
5662
export const sortHierarchy = (tree: HierarchyValue[]): HierarchyValue[] => {
57-
const sortedTree = orderBy(
58-
tree,
59-
["depth", "position", "identifier", "label"],
60-
["desc", "asc", "asc", "asc"]
61-
) as HierarchyValue[];
62-
63-
return sortedTree.map((d) => ({
63+
return sortTree(tree).map((d) => ({
6464
...d,
6565
children: d.children ? sortHierarchy(d.children) : undefined,
6666
}));

0 commit comments

Comments
 (0)