From 32bcb08bdb32f14b0b36d68a8ffa176ef6a414b7 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Wed, 2 Aug 2023 21:41:30 -0300 Subject: [PATCH] fix(reactflowUtils.ts): refactor cleanEdges function to use JSON.parse and JSON.stringify for targetHandle and sourceHandle variables to improve readability and maintainability --- src/frontend/src/utils/reactflowUtils.ts | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index 3f65707d6..735867954 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -30,25 +30,25 @@ export function cleanEdges({ const sourceHandle = edge.sourceHandle; //right const targetHandle = edge.targetHandle; //left if (targetHandle) { - const field = targetHandle.split("|")[1]; - const id = - (targetNode.data.node.template[field]?.input_types?.join(";") ?? - targetNode.data.node.template[field]?.type) + - "|" + - field + - "|" + - targetNode.data.id; - if (id !== targetHandle) { + const targetHandleObject: targetHandleType = JSON.parse(targetHandle); + const field = targetHandleObject.fieldName; + const id: targetHandleType = { + type: targetNode.data.node.template[field]?.type, + fieldName: field, + id: targetNode.data.id, + inputTypes: targetNode.data.node.template[field]?.input_types, + }; + if (JSON.stringify(id) !== targetHandle) { newEdges = newEdges.filter((e) => e.id !== edge.id); } } if (sourceHandle) { - const id = [ - sourceNode.data.type, - sourceNode.data.id, - ...sourceNode.data.node.base_classes, - ].join("|"); - if (id !== sourceHandle) { + const id: sourceHandleType = { + id: sourceNode.data.id, + baseClasses: sourceNode.data.node.base_classes, + dataType: sourceNode.data.type, + }; + if (JSON.stringify(id) !== sourceHandle) { newEdges = newEdges.filter((e) => e.id !== edge.id); } }