updateIds migration done
This commit is contained in:
parent
cd1d3c226a
commit
ffda93ee34
3 changed files with 38 additions and 38 deletions
|
|
@ -20,8 +20,8 @@ import {
|
||||||
import { APIClassType, APITemplateType } from "../types/api";
|
import { APIClassType, APITemplateType } from "../types/api";
|
||||||
import { FlowType, NodeType } from "../types/flow";
|
import { FlowType, NodeType } from "../types/flow";
|
||||||
import { TabsContextType, TabsState } from "../types/tabs";
|
import { TabsContextType, TabsState } from "../types/tabs";
|
||||||
import { getRandomDescription, getRandomName, updateIds } from "../utils";
|
import { getRandomDescription, getRandomName } from "../utils";
|
||||||
import { updateTemplate } from "../utils/reactflowUtils";
|
import { updateIds, updateTemplate } from "../utils/reactflowUtils";
|
||||||
import { alertContext } from "./alertContext";
|
import { alertContext } from "./alertContext";
|
||||||
import { typesContext } from "./typesContext";
|
import { typesContext } from "./typesContext";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -84,41 +84,6 @@ export function checkUpperWords(str: string) {
|
||||||
return words.join(" ");
|
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) {
|
export function groupByFamily(data, baseClasses, left, type) {
|
||||||
let parentOutput: string;
|
let parentOutput: string;
|
||||||
let arrOfParent: string[] = [];
|
let arrOfParent: string[] = [];
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { Connection, ReactFlowInstance } from "reactflow";
|
import { Connection, ReactFlowInstance } from "reactflow";
|
||||||
import { APITemplateType } from "../types/api";
|
import { APITemplateType } from "../types/api";
|
||||||
import { FlowType } from "../types/flow";
|
import { FlowType, NodeType } from "../types/flow";
|
||||||
import { cleanEdgesType } from "../types/utils/reactflowUtils";
|
import { cleanEdgesType } from "../types/utils/reactflowUtils";
|
||||||
|
|
||||||
export function cleanEdges({
|
export function cleanEdges({
|
||||||
|
|
@ -124,3 +124,38 @@ export function updateTemplate(
|
||||||
}
|
}
|
||||||
return clonedObject;
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue