migrate old edges id format to new edges id fromat on ungroup node

This commit is contained in:
anovazzi1 2023-09-13 17:04:07 -03:00
commit 07f5342aa8

View file

@ -796,42 +796,40 @@ export function expandGroupNode(
const targetHandle:targetHandleType = newEdge.data.targetHandle; const targetHandle:targetHandleType = newEdge.data.targetHandle;
if (targetHandle.proxy) { if (targetHandle.proxy) {
let type = targetHandle.type; let type = targetHandle.type;
let field = newEdge.targetHandle.split("|")[4]; let field = targetHandle.proxy.field;
let proxy = newEdge.targetHandle.split("|")[3]; let proxyId = targetHandle.proxy.id;
let node = gNodes.find((n) => n.id === proxy); let inputTypes = targetHandle.inputTypes;
console.log(node); let node:NodeType = gNodes.find((n) => n.id === proxyId)!;
if (node) { if (node) {
newEdge.target = proxy; newEdge.target = proxyId;
if (node.type === "groupNode") { let newTargetHandle: targetHandleType = {
newEdge.targetHandle = fieldName: field,
type + type,
"|" + id: proxyId}
field + if (node.data.node?.flow) {
"|" + newTargetHandle.proxy =
proxy + {field:node.data.node.template[field].proxy?.field!,
"|" + id:node.data.node.template[field].proxy?.id!}
node.data.node.template[field].proxy.id + }
"|" + if(inputTypes){
node.data.node.template[field].proxy.field; newTargetHandle.inputTypes = inputTypes;
} else { }
newEdge.targetHandle = type + "|" + field + "|" + proxy; newEdge.targetHandle = scapedJSONStringfy(newTargetHandle);
} }
updatedEdges.push(newEdge);
} }
} }
}
if (newEdge.source === groupNode.id) { if (newEdge.source === groupNode.id) {
const lastNode = _.cloneDeep(findLastNode(flow.data)); const lastNode = _.cloneDeep(findLastNode(flow!.data!));
newEdge.source = lastNode.id; newEdge.source = lastNode!.id;
let sourceHandle = newEdge.sourceHandle.split("|"); let newSourceHandle: sourceHandleType = scapeJSONParse(newEdge.sourceHandle!);
sourceHandle[1] = lastNode.id; newSourceHandle.id = lastNode!.id;
newEdge.sourceHandle = sourceHandle.join("|"); newEdge.sourceHandle = scapedJSONStringfy(newSourceHandle);
updatedEdges.push(newEdge);
} }
updatedEdges.push(newEdge);
}); });
//update template values
Object.keys(template).forEach((key) => { Object.keys(template).forEach((key) => {
let { field, id } = template[key].proxy; let { field, id } = template[key].proxy!;
let nodeIndex = gNodes.findIndex((n) => n.id === id); let nodeIndex = gNodes.findIndex((n) => n.id === id);
if (nodeIndex !== -1) { if (nodeIndex !== -1) {
let display_name: string; let display_name: string;
@ -863,6 +861,7 @@ export function expandGroupNode(
ReactFlowInstance.setNodes(nodes); ReactFlowInstance.setNodes(nodes);
ReactFlowInstance.setEdges(edges); ReactFlowInstance.setEdges(edges);
} }
export function processFLow(FlowObject: ReactFlowJsonObject) { export function processFLow(FlowObject: ReactFlowJsonObject) {
let clonedFLow = _.cloneDeep(FlowObject); let clonedFLow = _.cloneDeep(FlowObject);
clonedFLow.nodes.forEach((node: NodeType) => { clonedFLow.nodes.forEach((node: NodeType) => {