mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
fix: incomplete blocks removal during delete operation
This commit is contained in:
parent
485744e1e5
commit
3c34c7fecc
@ -399,48 +399,52 @@ const Diagrams = () => {
|
|||||||
} else {
|
} else {
|
||||||
// Block Delete Case
|
// Block Delete Case
|
||||||
const ids = id.includes(",") ? id.split(",") : [id];
|
const ids = id.includes(",") ? id.split(",") : [id];
|
||||||
const deletePromises = ids.map((id) => {
|
|
||||||
const block = getBlockFromCache(id);
|
|
||||||
|
|
||||||
return deleteBlock(id, {
|
for (const blockId of ids) {
|
||||||
|
const block = getBlockFromCache(blockId);
|
||||||
|
|
||||||
|
await deleteBlock(blockId, {
|
||||||
onSuccess() {
|
onSuccess() {
|
||||||
// Update all linked blocks to remove any reference to the deleted block
|
// Update all linked blocks to remove any reference to the deleted block
|
||||||
[
|
const linkedBlockIds = [
|
||||||
...(block?.nextBlocks || []),
|
...(block?.nextBlocks || []),
|
||||||
...(block?.previousBlocks || []),
|
...(block?.previousBlocks || []),
|
||||||
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
||||||
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
||||||
]
|
];
|
||||||
.map((bid) => getBlockFromCache(bid))
|
|
||||||
.filter((b) => !!b)
|
for (const linkedBlockId of linkedBlockIds) {
|
||||||
.forEach((b) => {
|
const linkedBlock = getBlockFromCache(linkedBlockId);
|
||||||
|
|
||||||
|
if (linkedBlock) {
|
||||||
updateCachedBlock({
|
updateCachedBlock({
|
||||||
id: b.id,
|
id: linkedBlock.id,
|
||||||
payload: {
|
payload: {
|
||||||
...b,
|
...linkedBlock,
|
||||||
nextBlocks: b.nextBlocks?.filter(
|
nextBlocks: linkedBlock.nextBlocks?.filter(
|
||||||
(nextBlockId) => nextBlockId !== id,
|
(nextBlockId) => nextBlockId !== blockId,
|
||||||
),
|
),
|
||||||
previousBlocks: b.previousBlocks?.filter(
|
previousBlocks: linkedBlock.previousBlocks?.filter(
|
||||||
(previousBlockId) => previousBlockId !== id,
|
(previousBlockId) => previousBlockId !== blockId,
|
||||||
),
|
),
|
||||||
attachedBlock:
|
attachedBlock:
|
||||||
b.attachedBlock === id ? undefined : b.attachedBlock,
|
linkedBlock.attachedBlock === blockId
|
||||||
attachedToBlock:
|
|
||||||
b.attachedToBlock === id
|
|
||||||
? undefined
|
? undefined
|
||||||
: b.attachedToBlock,
|
: linkedBlock.attachedBlock,
|
||||||
|
attachedToBlock:
|
||||||
|
linkedBlock.attachedToBlock === blockId
|
||||||
|
? undefined
|
||||||
|
: linkedBlock.attachedToBlock,
|
||||||
},
|
},
|
||||||
strategy: "overwrite",
|
strategy: "overwrite",
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
|
||||||
deleteCachedBlock(id);
|
deleteCachedBlock(blockId);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
await Promise.all(deletePromises);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteCallbackRef.current?.();
|
deleteCallbackRef.current?.();
|
||||||
|
Loading…
Reference in New Issue
Block a user