From ffda93ee3437f6e71213b4c59f99a73b836a232e Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Thu, 13 Jul 2023 19:22:18 -0300 Subject: [PATCH] updateIds migration done --- src/frontend/src/contexts/tabsContext.tsx | 4 +-- src/frontend/src/utils.ts | 35 --------------------- src/frontend/src/utils/reactflowUtils.ts | 37 ++++++++++++++++++++++- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/src/frontend/src/contexts/tabsContext.tsx b/src/frontend/src/contexts/tabsContext.tsx index c5c4264de..bbd77007d 100644 --- a/src/frontend/src/contexts/tabsContext.tsx +++ b/src/frontend/src/contexts/tabsContext.tsx @@ -20,8 +20,8 @@ import { import { APIClassType, APITemplateType } from "../types/api"; import { FlowType, NodeType } from "../types/flow"; import { TabsContextType, TabsState } from "../types/tabs"; -import { getRandomDescription, getRandomName, updateIds } from "../utils"; -import { updateTemplate } from "../utils/reactflowUtils"; +import { getRandomDescription, getRandomName } from "../utils"; +import { updateIds, updateTemplate } from "../utils/reactflowUtils"; import { alertContext } from "./alertContext"; import { typesContext } from "./typesContext"; diff --git a/src/frontend/src/utils.ts b/src/frontend/src/utils.ts index 0972d9972..c5f57bc5a 100644 --- a/src/frontend/src/utils.ts +++ b/src/frontend/src/utils.ts @@ -84,41 +84,6 @@ export function checkUpperWords(str: string) { return words.join(" "); } -export function updateIds(newFlow, getNodeId) { - let idsMap = {}; - - newFlow.nodes.forEach((n: NodeType) => { - // Generate a unique node ID - let newId = getNodeId(n.data.type); - idsMap[n.id] = newId; - n.id = newId; - n.data.id = newId; - // Add the new node to the list of nodes in state - }); - - newFlow.edges.forEach((e) => { - e.source = idsMap[e.source]; - e.target = idsMap[e.target]; - let sourceHandleSplitted = e.sourceHandle.split("|"); - e.sourceHandle = - sourceHandleSplitted[0] + - "|" + - e.source + - "|" + - sourceHandleSplitted.slice(2).join("|"); - let targetHandleSplitted = e.targetHandle.split("|"); - e.targetHandle = - targetHandleSplitted.slice(0, -1).join("|") + "|" + e.target; - e.id = - "reactflow__edge-" + - e.source + - e.sourceHandle + - "-" + - e.target + - e.targetHandle; - }); -} - export function groupByFamily(data, baseClasses, left, type) { let parentOutput: string; let arrOfParent: string[] = []; diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index c8623cf69..3183bd1af 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import { Connection, ReactFlowInstance } from "reactflow"; import { APITemplateType } from "../types/api"; -import { FlowType } from "../types/flow"; +import { FlowType, NodeType } from "../types/flow"; import { cleanEdgesType } from "../types/utils/reactflowUtils"; export function cleanEdges({ @@ -124,3 +124,38 @@ export function updateTemplate( } return clonedObject; } + +export function updateIds(newFlow, getNodeId) { + let idsMap = {}; + + newFlow.nodes.forEach((n: NodeType) => { + // Generate a unique node ID + let newId = getNodeId(n.data.type); + idsMap[n.id] = newId; + n.id = newId; + n.data.id = newId; + // Add the new node to the list of nodes in state + }); + + newFlow.edges.forEach((e) => { + e.source = idsMap[e.source]; + e.target = idsMap[e.target]; + let sourceHandleSplitted = e.sourceHandle.split("|"); + e.sourceHandle = + sourceHandleSplitted[0] + + "|" + + e.source + + "|" + + sourceHandleSplitted.slice(2).join("|"); + let targetHandleSplitted = e.targetHandle.split("|"); + e.targetHandle = + targetHandleSplitted.slice(0, -1).join("|") + "|" + e.target; + e.id = + "reactflow__edge-" + + e.source + + e.sourceHandle + + "-" + + e.target + + e.targetHandle; + }); +}