Browse Source

fix: collapsed parent node disappears when expand

victorbrambati 2 years ago
parent
commit
b7492c1c55
1 changed files with 6 additions and 1 deletions
  1. 6 1
      src/utils/getOutgoers.ts

+ 6 - 1
src/utils/getOutgoers.ts

@@ -6,9 +6,14 @@ export const getOutgoers = (
 ): [NodeData[], string[]] => {
 ): [NodeData[], string[]] => {
   const outgoerNodes: NodeData[] = [];
   const outgoerNodes: NodeData[] = [];
   const matchingNodes: string[] = [];
   const matchingNodes: string[] = [];
-
   const runner = (nodeId: string) => {
   const runner = (nodeId: string) => {
     const outgoerIds = edges.filter(e => e.from === nodeId).map(e => e.to);
     const outgoerIds = edges.filter(e => e.from === nodeId).map(e => e.to);
+
+    if (parent.includes(nodeId)) {
+      const initialParentNode = nodes.find(n => n.id === nodeId);
+      if (initialParentNode) outgoerNodes.push(initialParentNode);
+    }
+
     const nodeList = nodes.filter(n => {
     const nodeList = nodes.filter(n => {
       if (parent.includes(n.id) && !matchingNodes.includes(n.id))
       if (parent.includes(n.id) && !matchingNodes.includes(n.id))
         matchingNodes.push(n.id);
         matchingNodes.push(n.id);