From f86fc1a1795cc5dd07012589a1f8fd3c2a605ff4 Mon Sep 17 00:00:00 2001 From: medchedli Date: Tue, 3 Jun 2025 11:55:51 +0100 Subject: [PATCH 1/2] fix: prevent duplicate links in nextBlocks when updating block --- .../components/visual-editor/v2/Diagrams.tsx | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/frontend/src/components/visual-editor/v2/Diagrams.tsx b/frontend/src/components/visual-editor/v2/Diagrams.tsx index d9060e41..b530efe0 100644 --- a/frontend/src/components/visual-editor/v2/Diagrams.tsx +++ b/frontend/src/components/visual-editor/v2/Diagrams.tsx @@ -291,30 +291,34 @@ const Diagrams = () => { entity.getSourcePort().getOptions()?.label === BlockPorts.nextBlocksOutPort ) { - const nextBlocks = [ - ...(previousData?.nextBlocks || []), - ...(targetId ? [targetId] : []), - ]; + // Only add the link if targetId exists, skip if targetId is null + if (!targetId) { + return; + } + // Only add the link if targetId doesn't already exist in nextBlocks + if (!previousData?.nextBlocks?.includes(targetId)) { + const nextBlocks = [...(previousData?.nextBlocks || []), targetId]; - updateBlock( - { - id: sourceId, - params: { - nextBlocks, + updateBlock( + { + id: sourceId, + params: { + nextBlocks, + }, }, - }, - { - onSuccess(data) { - if (data.id) - updateCachedBlock({ - id: targetId, - payload: { - previousBlocks: [data.id as any], - }, - }); + { + onSuccess(data) { + if (data.id) + updateCachedBlock({ + id: targetId, + payload: { + previousBlocks: [data.id as any], + }, + }); + }, }, - }, - ); + ); + } } else if ( // @ts-expect-error undefined attr entity.getSourcePort().getOptions().label === From de6d30e854701f3832fc77f1fd487fd57749e5d4 Mon Sep 17 00:00:00 2001 From: medchedli Date: Wed, 4 Jun 2025 18:43:09 +0100 Subject: [PATCH 2/2] fix: apply feedback --- .../components/visual-editor/v2/Diagrams.tsx | 61 +++++++++++-------- 1 file changed, 34 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/visual-editor/v2/Diagrams.tsx b/frontend/src/components/visual-editor/v2/Diagrams.tsx index b530efe0..f6708e09 100644 --- a/frontend/src/components/visual-editor/v2/Diagrams.tsx +++ b/frontend/src/components/visual-editor/v2/Diagrams.tsx @@ -264,6 +264,19 @@ const Diagrams = () => { return; } + const sourceId = entity.getSourcePort().getParent().getOptions() + .id as string; + const targetId = entity.getTargetPort().getParent().getOptions() + .id as string; + const previousData = getBlockFromCache(sourceId!); + + // Only add the link if targetId doesn't already exist in nextBlocks + if (previousData?.nextBlocks?.includes(targetId)) { + model.removeLink(link); + + return; + } + link.setLocked(true); link.registerListener({ selectionChanged(event: any) { @@ -280,12 +293,6 @@ const Diagrams = () => { } }); - const sourceId = entity.getSourcePort().getParent().getOptions() - .id as string; - const targetId = entity.getTargetPort().getParent().getOptions() - .id as string; - const previousData = getBlockFromCache(sourceId!); - if ( // @ts-expect-error undefined attr entity.getSourcePort().getOptions()?.label === @@ -295,30 +302,30 @@ const Diagrams = () => { if (!targetId) { return; } - // Only add the link if targetId doesn't already exist in nextBlocks - if (!previousData?.nextBlocks?.includes(targetId)) { - const nextBlocks = [...(previousData?.nextBlocks || []), targetId]; + const nextBlocks = [ + ...(previousData?.nextBlocks || []), + ...(targetId ? [targetId] : []), + ]; - updateBlock( - { - id: sourceId, - params: { - nextBlocks, - }, + updateBlock( + { + id: sourceId, + params: { + nextBlocks, }, - { - onSuccess(data) { - if (data.id) - updateCachedBlock({ - id: targetId, - payload: { - previousBlocks: [data.id as any], - }, - }); - }, + }, + { + onSuccess(data) { + if (data.id) + updateCachedBlock({ + id: targetId, + payload: { + previousBlocks: [data.id as any], + }, + }); }, - ); - } + }, + ); } else if ( // @ts-expect-error undefined attr entity.getSourcePort().getOptions().label ===