updateIds migration done

This commit is contained in:
anovazzi1 2023-07-13 19:22:18 -03:00
commit ffda93ee34
3 changed files with 38 additions and 38 deletions

View file

@ -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";

View file

@ -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[] = [];

View file

@ -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;
});
}