update utils with updateIds function
This commit is contained in:
parent
c05056c34d
commit
3a34412585
1 changed files with 25 additions and 0 deletions
|
|
@ -20,6 +20,7 @@ import { Connection, Edge, Node, ReactFlowInstance } from "reactflow";
|
|||
import { FlowType } from "./types/flow";
|
||||
import { APITemplateType, TemplateVariableType } from "./types/api";
|
||||
import _ from "lodash";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
export function classNames(...classes: Array<string>) {
|
||||
return classes.filter(Boolean).join(" ");
|
||||
|
|
@ -534,3 +535,27 @@ export function checkUpperWords(str: string) {
|
|||
|
||||
return words.join(" ");
|
||||
}
|
||||
|
||||
export function updateIds(newFLow: FlowType, baseFlow: FlowType) {
|
||||
newFLow.data.nodes.forEach((node) => {
|
||||
while (baseFlow.data.nodes.some((n) => n.id === node.id)) {
|
||||
const newId = uuidv4();
|
||||
newFLow.data.edges.forEach((edge) => {
|
||||
if (edge.source === node.id) {
|
||||
edge.source = newId;
|
||||
}
|
||||
if (edge.target === node.id) {
|
||||
edge.target = newId;
|
||||
}
|
||||
const index = edge.id.split("|").findIndex((e) => e === node.id);
|
||||
if (index != -1) {
|
||||
let tempList = edge.id.split("|");
|
||||
tempList[index] = newId;
|
||||
edge.id = tempList.concat(newId).join("|");
|
||||
}
|
||||
node.id = newId;
|
||||
});
|
||||
}
|
||||
});
|
||||
return newFLow;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue