refactor(reactflowUtils.ts): add type definitions for updateEdgesHandleIdsType to improve code readability and maintainability
feat(reactflowUtils.ts): implement updateEdgesHandleIds function to update handle ids in edges based on node changes
This commit is contained in:
parent
1e3c918880
commit
75c4d3e85c
2 changed files with 44 additions and 2 deletions
|
|
@ -8,3 +8,9 @@ export type cleanEdgesType = {
|
||||||
};
|
};
|
||||||
updateEdge: (edge: Edge[]) => void;
|
updateEdge: (edge: Edge[]) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type updateEdgesHandleIdsType = {
|
||||||
|
nodes: NodeType[];
|
||||||
|
edges: Edge[];
|
||||||
|
setEdges: (edges: Edge[]) => void;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,16 @@
|
||||||
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, NodeType } from "../types/flow";
|
import {
|
||||||
import { cleanEdgesType } from "../types/utils/reactflowUtils";
|
FlowType,
|
||||||
|
NodeType,
|
||||||
|
sourceHandleType,
|
||||||
|
targetHandleType,
|
||||||
|
} from "../types/flow";
|
||||||
|
import {
|
||||||
|
cleanEdgesType,
|
||||||
|
updateEdgesHandleIdsType,
|
||||||
|
} from "../types/utils/reactflowUtils";
|
||||||
import { toNormalCase } from "./utils";
|
import { toNormalCase } from "./utils";
|
||||||
|
|
||||||
export function cleanEdges({
|
export function cleanEdges({
|
||||||
|
|
@ -232,3 +240,31 @@ export function addVersionToDuplicates(flow: FlowType, flows: FlowType[]) {
|
||||||
|
|
||||||
return newName;
|
return newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function updateEdgesHandleIds({
|
||||||
|
edges,
|
||||||
|
nodes,
|
||||||
|
setEdges,
|
||||||
|
}: updateEdgesHandleIdsType) {
|
||||||
|
let newEdges = _.cloneDeep(edges);
|
||||||
|
newEdges.forEach((edge) => {
|
||||||
|
const sourceNode = edge.source;
|
||||||
|
const targetNode = edge.target;
|
||||||
|
let source = edge.sourceHandle;
|
||||||
|
let target = edge.targetHandle;
|
||||||
|
//right
|
||||||
|
let newSource: sourceHandleType;
|
||||||
|
//left
|
||||||
|
let newTarget: targetHandleType;
|
||||||
|
if (target) {
|
||||||
|
let splittedtarget = target.split("|");
|
||||||
|
let inputTypes: string[];
|
||||||
|
if (splittedtarget[0].split(";").length > 1) {
|
||||||
|
newTarget.inputTypes = splittedtarget[0].split(";");
|
||||||
|
} else {
|
||||||
|
newTarget.type = splittedtarget[0];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
setEdges(newEdges);
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue