Skip to content

Commit af9851b

Browse files
committed
filtered link select for context hooks
1 parent 1914fea commit af9851b

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

src/app/components/StateRoute/ComponentMap/LinkControls.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,49 @@ const LinkControls = ({
2121
return nodeList;
2222
};
2323

24-
const nodeList = collectNodes(snapShots);
24+
const shouldIncludeNode = (node) => {
25+
// Return false if node has any context properties
26+
if (node?.componentData?.context && Object.keys(node.componentData.context).length > 0) {
27+
return false;
28+
}
29+
// Return false if node name ends with 'Provider'
30+
if (node?.name && node.name.endsWith('Provider')) {
31+
return false;
32+
}
33+
return true;
34+
};
35+
36+
const processTreeData = (node) => {
37+
if (!node) return null;
38+
39+
// Create a new node
40+
const newNode = { ...node };
41+
42+
if (node.children) {
43+
// Process all children first
44+
const processedChildren = node.children
45+
.map((child) => processTreeData(child))
46+
.filter(Boolean); // Remove null results
47+
48+
// For each child that shouldn't be included, replace it with its children
49+
newNode.children = processedChildren.reduce((acc, child) => {
50+
if (shouldIncludeNode(child)) {
51+
// If child should be included, add it directly
52+
acc.push(child);
53+
} else {
54+
// If child should be filtered out, add its children instead
55+
if (child.children) {
56+
acc.push(...child.children);
57+
}
58+
}
59+
return acc;
60+
}, []);
61+
}
62+
63+
return newNode;
64+
};
65+
const filtered = processTreeData(snapShots);
66+
const nodeList = collectNodes(filtered);
2567

2668
return (
2769
<div className='link-controls'>

0 commit comments

Comments
 (0)