浏览代码

fix: don't show disconnected nodes on expand

Shivam 2 年之前
父节点
当前提交
f70af5806b
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      src/hooks/store/useGraph.tsx

+ 8 - 1
src/hooks/store/useGraph.tsx

@@ -43,7 +43,14 @@ const useGraph = create<Graph & GraphActions>((set, get) => ({
     );
     const childrenEdges = getChildrenEdges(childrenNodes, get().edges);
 
-    const nodeIds = childrenNodes.map(node => node.id).concat(matchingNodes);
+
+    let nodesConnectedToParent = childrenEdges.reduce((nodes: string[], edge) => {
+      edge.from && !nodes.includes(edge.from) && nodes.push(edge.from)
+      edge.to && !nodes.includes(edge.to) && nodes.push(edge.to)
+      return nodes
+    }, []);
+    const matchingNodesConnectedToParent = matchingNodes.filter(node => nodesConnectedToParent.includes(node));
+    const nodeIds = childrenNodes.map(node => node.id).concat(matchingNodesConnectedToParent);
     const edgeIds = childrenEdges.map(edge => edge.id);
 
     const collapsedParents = get().collapsedParents.filter(cp => cp !== nodeId);