Expand to multi level

This commit is contained in:
Oliver Walters 2026-06-19 03:02:13 +00:00
parent 40d3b8fe79
commit 64633c211a
1 changed files with 10 additions and 2 deletions

View File

@ -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]);