mirror of
https://github.com/hexastack/hexabot
synced 2024-11-24 04:53:41 +00:00
refactor: minor changes
This commit is contained in:
parent
4f5280ff9c
commit
ee024afa05
@ -372,23 +372,21 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
const handleBlockDeletion = async (id: string) => {
|
const handleBlockDeletion = async (blockIds: string[]) => {
|
||||||
const ids = id.split(",");
|
if (blockIds.length > 1) {
|
||||||
|
await deleteMultipleBlocks(blockIds);
|
||||||
if (ids.length > 1) {
|
|
||||||
await deleteMultipleBlocks(ids);
|
|
||||||
} else {
|
} else {
|
||||||
await deleteSingleBlock(ids[0]);
|
await deleteSingleBlock(blockIds[0]);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const deleteMultipleBlocks = async (ids: string[]) => {
|
const deleteMultipleBlocks = async (blockIds: string[]) => {
|
||||||
await deleteBlocks(ids, {
|
await deleteBlocks(blockIds, {
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
ids.forEach((blockId) => {
|
blockIds.forEach((blockId) => {
|
||||||
const block = getBlockFromCache(blockId);
|
const block = getBlockFromCache(blockId);
|
||||||
|
|
||||||
if (block) {
|
if (block) {
|
||||||
updateLinkedBlocks(block, ids);
|
updateLinkedBlocks(block, blockIds);
|
||||||
deleteCachedBlock(blockId);
|
deleteCachedBlock(blockId);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -407,13 +405,14 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
const getLinkedBlockIds = (block: IBlock): string[] => [
|
||||||
|
...(block?.nextBlocks || []),
|
||||||
|
...(block?.previousBlocks || []),
|
||||||
|
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
||||||
|
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
||||||
|
];
|
||||||
const updateLinkedBlocks = (block: IBlock, deletedIds: string[]) => {
|
const updateLinkedBlocks = (block: IBlock, deletedIds: string[]) => {
|
||||||
const linkedBlockIds = [
|
const linkedBlockIds = getLinkedBlockIds(block);
|
||||||
...(block?.nextBlocks || []),
|
|
||||||
...(block?.previousBlocks || []),
|
|
||||||
...(block?.attachedBlock ? [block.attachedBlock] : []),
|
|
||||||
...(block?.attachedToBlock ? [block.attachedToBlock] : []),
|
|
||||||
];
|
|
||||||
|
|
||||||
linkedBlockIds.forEach((linkedBlockId) => {
|
linkedBlockIds.forEach((linkedBlockId) => {
|
||||||
const linkedBlock = getBlockFromCache(linkedBlockId);
|
const linkedBlock = getBlockFromCache(linkedBlockId);
|
||||||
@ -478,11 +477,12 @@ const Diagrams = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isLink = id.length === 36;
|
const isLink = id.length === 36;
|
||||||
|
const listIds = id.split(",");
|
||||||
|
|
||||||
if (isLink) {
|
if (isLink) {
|
||||||
await handleLinkDeletion(id);
|
await handleLinkDeletion(listIds[0]);
|
||||||
} else {
|
} else {
|
||||||
await handleBlockDeletion(id);
|
await handleBlockDeletion(listIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
cleanupAfterDeletion();
|
cleanupAfterDeletion();
|
||||||
|
Loading…
Reference in New Issue
Block a user