From 46c538c4a7f0fd5854ae5ec6cefa93a2c2eba03b Mon Sep 17 00:00:00 2001 From: Lucas Oliveira Date: Fri, 13 Oct 2023 00:23:56 -0300 Subject: [PATCH] Recursive ID updating implemented on nodes --- src/frontend/src/contexts/tabsContext.tsx | 25 +++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index 4a583c55c..282cdb008 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -427,6 +427,26 @@ export function TabsProvider({ children }: { children: ReactNode }) { let newId = getNodeId(node.data.type); idsMap[node.id] = newId; + let data = { + ..._.cloneDeep(node.data), + id: newId, + }; + + if (data.node?.flow) { + let internNodes = []; + data.node.flow.data!.nodes.map((node) => { + internNodes = updateNodeId( + node, + idsMap, + internNodes, + insidePosition, + minimumX, + minimumY + ); + }); + data.node.flow.data!.nodes = internNodes; + } + // Create a new node object const newNode: NodeType = { id: newId, @@ -435,10 +455,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { x: insidePosition.x + node.position!.x - minimumX, y: insidePosition.y + node.position!.y - minimumY, }, - data: { - ..._.cloneDeep(node.data), - id: newId, - }, + data, }; // Add the new node to the list of nodes in state