Skip to content

Commit

Permalink
Fix radio folder behavior when nested
Browse files Browse the repository at this point in the history
  • Loading branch information
underbluewaters committed Nov 14, 2024
1 parent 472cd4f commit d9485d3
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion packages/client/src/components/TreeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export default function TreeView({
}
onChecked(ids, isChecked);
if (isChecked && item.parentId) {
const parent = data.find((i) => i.node.id === item.parentId);
const parent = findTreeNodeRecursive(data, item.parentId);
if (parent?.radioFolder) {
// Find and hide any visible siblings and their children
const siblings = parent.children.filter(
Expand Down Expand Up @@ -684,3 +684,16 @@ export function overlayLayerFragmentsToTreeItems(
}
return items;
}

function findTreeNodeRecursive(data: TreeNode[], id: string): TreeNode | null {
for (const node of data) {
if (node.node.id === id) {
return node;
}
const found = findTreeNodeRecursive(node.children, id);
if (found) {
return found;
}
}
return null;
}

0 comments on commit d9485d3

Please sign in to comment.