From fbca8497d6d9aa7250e9f3daad43009cc09cfb29 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 26 Jul 2023 18:28:27 -0300 Subject: [PATCH] refactor(reactflowUtils.ts): improve variable names and add type checking for source and target nodes in updateEdgesHandleIds function fix(reactflowUtils.ts): fix assignment of newTarget in updateEdgesHandleIds function to correctly set type, fieldName, id, and inputTypes properties fix(reactflowUtils.ts): fix assignment of newSource in updateEdgesHandleIds function to correctly set dataType, id, and baseClasses properties fix(reactflowUtils.ts): fix assignment of sourceHandle and targetHandle in updateEdgesHandleIds function to correctly stringify newSource and newTarget objects --- src/frontend/src/utils/reactflowUtils.ts | 31 ++++++++++++++++-------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index d08204685..3f65707d6 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -248,23 +248,34 @@ export function updateEdgesHandleIds({ }: updateEdgesHandleIdsType) { let newEdges = _.cloneDeep(edges); newEdges.forEach((edge) => { - const sourceNode = edge.source; - const targetNode = edge.target; + const sourceNodeId = edge.source; + const targetNodeId = edge.target; + const sourceNode = nodes.find((node) => node.id === sourceNodeId); + const targetNode = nodes.find((node) => node.id === targetNodeId); 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]; - } + if (target && targetNode) { + let field = target.split("|")[1]; + newTarget = { + type: targetNode.data.node.template[field].type, + fieldName: field, + id: targetNode.data.id, + inputTypes: targetNode.data.node.template[field].input_types, + }; } + if (source && sourceNode) { + newSource = { + dataType: sourceNode.data.type, + id: sourceNode.data.id, + baseClasses: sourceNode.data.node.base_classes, + }; + } + edge.sourceHandle = JSON.stringify(newSource); + edge.targetHandle = JSON.stringify(newTarget); }); setEdges(newEdges); }