fix: revert moving link

This commit is contained in:
hexastack 2024-10-30 09:56:48 +01:00 committed by abdou6666
parent 55fe415fd8
commit 066124acc5

View File

@ -344,6 +344,61 @@ const Diagrams = () => {
const id = deleteDialogCtl?.data;
if (id) {
// Handle link deletion
if (id.length === 36) {
const link = model?.getLink(id) as any;
const sourceId = link?.sourcePort.parent.options.id;
const targetId = link?.targetPort.parent.options.id;
if (link?.sourcePort.options.label === BlockPorts.nextBlocksOutPort) {
const previousData = getBlockFromCache(sourceId);
const nextBlocks = [...(previousData?.nextBlocks || [])];
await updateBlock(
{
id: sourceId,
params: {
nextBlocks: nextBlocks.filter((block) => block !== targetId),
},
},
{
onSuccess() {
updateCachedBlock({
id: targetId,
preprocess: ({ previousBlocks = [], ...rest }) => ({
...rest,
previousBlocks: previousBlocks.filter(
(previousBlock) => previousBlock !== sourceId,
),
}),
});
},
},
);
} else if (
link?.sourcePort.options.label === BlockPorts.attachmentOutPort
) {
await updateBlock(
{
id: sourceId,
params: {
attachedBlock: null,
},
},
{
onSuccess() {
updateCachedBlock({
id: targetId,
preprocess: (oldData) => ({
...oldData,
attachedToBlock: null,
}),
});
},
},
);
}
} else {
const ids = id.split(",");
if (ids.length > 1) {
@ -439,6 +494,7 @@ const Diagrams = () => {
},
});
}
}
deleteCallbackRef.current?.();
deleteCallbackRef.current = () => {};