mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
fix: revert moving link
This commit is contained in:
parent
55fe415fd8
commit
066124acc5
@ -344,100 +344,156 @@ const Diagrams = () => {
|
|||||||
const id = deleteDialogCtl?.data;
|
const id = deleteDialogCtl?.data;
|
||||||
|
|
||||||
if (id) {
|
if (id) {
|
||||||
const ids = id.split(",");
|
// 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 (ids.length > 1) {
|
if (link?.sourcePort.options.label === BlockPorts.nextBlocksOutPort) {
|
||||||
await deleteBlocks(ids, {
|
const previousData = getBlockFromCache(sourceId);
|
||||||
onSuccess: () => {
|
const nextBlocks = [...(previousData?.nextBlocks || [])];
|
||||||
ids.forEach((blockId) => {
|
|
||||||
const block = getBlockFromCache(blockId);
|
|
||||||
|
|
||||||
if (block) {
|
await updateBlock(
|
||||||
// Update all linked blocks to remove references to deleted blocks
|
{
|
||||||
const linkedBlockIds = [
|
id: sourceId,
|
||||||
...(block?.nextBlocks || []),
|
params: {
|
||||||
...(block?.previousBlocks || []),
|
nextBlocks: nextBlocks.filter((block) => block !== targetId),
|
||||||
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
},
|
||||||
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
},
|
||||||
];
|
{
|
||||||
|
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(",");
|
||||||
|
|
||||||
linkedBlockIds.forEach((linkedBlockId) => {
|
if (ids.length > 1) {
|
||||||
const linkedBlock = getBlockFromCache(linkedBlockId);
|
await deleteBlocks(ids, {
|
||||||
|
onSuccess: () => {
|
||||||
|
ids.forEach((blockId) => {
|
||||||
|
const block = getBlockFromCache(blockId);
|
||||||
|
|
||||||
if (linkedBlock) {
|
if (block) {
|
||||||
updateCachedBlock({
|
// Update all linked blocks to remove references to deleted blocks
|
||||||
id: linkedBlock.id,
|
const linkedBlockIds = [
|
||||||
payload: {
|
...(block?.nextBlocks || []),
|
||||||
...linkedBlock,
|
...(block?.previousBlocks || []),
|
||||||
nextBlocks: linkedBlock.nextBlocks?.filter(
|
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
||||||
(nextBlockId) => !ids.includes(nextBlockId),
|
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
||||||
),
|
];
|
||||||
previousBlocks: linkedBlock.previousBlocks?.filter(
|
|
||||||
(previousBlockId) => !ids.includes(previousBlockId),
|
linkedBlockIds.forEach((linkedBlockId) => {
|
||||||
),
|
const linkedBlock = getBlockFromCache(linkedBlockId);
|
||||||
attachedBlock: ids.includes(
|
|
||||||
linkedBlock.attachedBlock || "",
|
if (linkedBlock) {
|
||||||
)
|
updateCachedBlock({
|
||||||
|
id: linkedBlock.id,
|
||||||
|
payload: {
|
||||||
|
...linkedBlock,
|
||||||
|
nextBlocks: linkedBlock.nextBlocks?.filter(
|
||||||
|
(nextBlockId) => !ids.includes(nextBlockId),
|
||||||
|
),
|
||||||
|
previousBlocks: linkedBlock.previousBlocks?.filter(
|
||||||
|
(previousBlockId) => !ids.includes(previousBlockId),
|
||||||
|
),
|
||||||
|
attachedBlock: ids.includes(
|
||||||
|
linkedBlock.attachedBlock || "",
|
||||||
|
)
|
||||||
|
? undefined
|
||||||
|
: linkedBlock.attachedBlock,
|
||||||
|
attachedToBlock: ids.includes(
|
||||||
|
linkedBlock.attachedToBlock || "",
|
||||||
|
)
|
||||||
|
? undefined
|
||||||
|
: linkedBlock.attachedToBlock,
|
||||||
|
},
|
||||||
|
strategy: "overwrite",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
deleteCachedBlock(blockId);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const blockId = ids[0];
|
||||||
|
const block = getBlockFromCache(blockId);
|
||||||
|
|
||||||
|
await deleteBlock(blockId, {
|
||||||
|
onSuccess() {
|
||||||
|
const linkedBlockIds = [
|
||||||
|
...(block?.nextBlocks || []),
|
||||||
|
...(block?.previousBlocks || []),
|
||||||
|
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
||||||
|
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
||||||
|
];
|
||||||
|
|
||||||
|
linkedBlockIds.forEach((linkedBlockId) => {
|
||||||
|
const linkedBlock = getBlockFromCache(linkedBlockId);
|
||||||
|
|
||||||
|
if (linkedBlock) {
|
||||||
|
updateCachedBlock({
|
||||||
|
id: linkedBlock.id,
|
||||||
|
payload: {
|
||||||
|
...linkedBlock,
|
||||||
|
nextBlocks: linkedBlock.nextBlocks?.filter(
|
||||||
|
(nextBlockId) => nextBlockId !== blockId,
|
||||||
|
),
|
||||||
|
previousBlocks: linkedBlock.previousBlocks?.filter(
|
||||||
|
(previousBlockId) => previousBlockId !== blockId,
|
||||||
|
),
|
||||||
|
attachedBlock:
|
||||||
|
linkedBlock.attachedBlock === blockId
|
||||||
? undefined
|
? undefined
|
||||||
: linkedBlock.attachedBlock,
|
: linkedBlock.attachedBlock,
|
||||||
attachedToBlock: ids.includes(
|
attachedToBlock:
|
||||||
linkedBlock.attachedToBlock || "",
|
linkedBlock.attachedToBlock === blockId
|
||||||
)
|
|
||||||
? undefined
|
? undefined
|
||||||
: linkedBlock.attachedToBlock,
|
: linkedBlock.attachedToBlock,
|
||||||
},
|
},
|
||||||
strategy: "overwrite",
|
strategy: "overwrite",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
deleteCachedBlock(blockId);
|
deleteCachedBlock(blockId);
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
}
|
||||||
});
|
|
||||||
} else {
|
|
||||||
const blockId = ids[0];
|
|
||||||
const block = getBlockFromCache(blockId);
|
|
||||||
|
|
||||||
await deleteBlock(blockId, {
|
|
||||||
onSuccess() {
|
|
||||||
const linkedBlockIds = [
|
|
||||||
...(block?.nextBlocks || []),
|
|
||||||
...(block?.previousBlocks || []),
|
|
||||||
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
|
||||||
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
|
||||||
];
|
|
||||||
|
|
||||||
linkedBlockIds.forEach((linkedBlockId) => {
|
|
||||||
const linkedBlock = getBlockFromCache(linkedBlockId);
|
|
||||||
|
|
||||||
if (linkedBlock) {
|
|
||||||
updateCachedBlock({
|
|
||||||
id: linkedBlock.id,
|
|
||||||
payload: {
|
|
||||||
...linkedBlock,
|
|
||||||
nextBlocks: linkedBlock.nextBlocks?.filter(
|
|
||||||
(nextBlockId) => nextBlockId !== blockId,
|
|
||||||
),
|
|
||||||
previousBlocks: linkedBlock.previousBlocks?.filter(
|
|
||||||
(previousBlockId) => previousBlockId !== blockId,
|
|
||||||
),
|
|
||||||
attachedBlock:
|
|
||||||
linkedBlock.attachedBlock === blockId
|
|
||||||
? undefined
|
|
||||||
: linkedBlock.attachedBlock,
|
|
||||||
attachedToBlock:
|
|
||||||
linkedBlock.attachedToBlock === blockId
|
|
||||||
? undefined
|
|
||||||
: linkedBlock.attachedToBlock,
|
|
||||||
},
|
|
||||||
strategy: "overwrite",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
deleteCachedBlock(blockId);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCallbackRef.current?.();
|
deleteCallbackRef.current?.();
|
||||||
|
Loading…
Reference in New Issue
Block a user