Expand to multi level
This commit is contained in:
parent
40d3b8fe79
commit
64633c211a
|
|
@ -108,12 +108,20 @@ export default function NavigationTree({
|
|||
const nodeMap: Record<number, any> = {};
|
||||
for (const n of query.data) nodeMap[n.pk] = n;
|
||||
|
||||
// Walk from the selected node up to the root, expanding each ancestor
|
||||
// Collect every ancestor pk into a single object, then apply in one
|
||||
// setExpandedState call to avoid closure/batching issues with expand().
|
||||
const toExpand: Record<string, boolean> = {};
|
||||
let current = nodeMap[selectedId];
|
||||
while (current?.parent) {
|
||||
treeState.expand(current.parent.toString());
|
||||
toExpand[current.parent.toString()] = true;
|
||||
current = nodeMap[current.parent];
|
||||
}
|
||||
if (Object.keys(toExpand).length) {
|
||||
treeState.setExpandedState({
|
||||
...treeState.expandedState,
|
||||
...toExpand
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [debouncedSearch, query.data, query.isFetching, selectedId]);
|
||||
|
|
|
|||
Loading…
Reference in New Issue