From 310d9e47aab6ab2335908d3cf5d4ab7e352e8d04 Mon Sep 17 00:00:00 2001 From: hexastack Date: Thu, 31 Oct 2024 17:06:28 +0100 Subject: [PATCH] fix: resolve conflicts --- api/src/chat/repositories/block.repository.ts | 16 +++++++++++++++- .../src/components/visual-editor/v2/Diagrams.tsx | 14 +++++++++++++- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/api/src/chat/repositories/block.repository.ts b/api/src/chat/repositories/block.repository.ts index 4ddb9aa..319878d 100644 --- a/api/src/chat/repositories/block.repository.ts +++ b/api/src/chat/repositories/block.repository.ts @@ -89,12 +89,26 @@ export class BlockRepository extends BaseRepository< Block, 'findOneAndUpdate' >, - _criteria: TFilterQuery, + criteria: TFilterQuery, _updates: | UpdateWithAggregationPipeline | UpdateQuery>, ): Promise { const updates: BlockUpdateDto = _updates?.['$set']; + if (updates?.category) { + const movedBlockId = criteria._id; + + // Find and update blocks that reference the moved block + await this.model.updateMany( + { nextBlocks: movedBlockId }, + { $pull: { nextBlocks: movedBlockId } }, + ); + + await this.model.updateMany( + { attachedBlock: movedBlockId }, + { $set: { attachedBlock: null } }, + ); + } this.checkDeprecatedAttachmentUrl(updates); } diff --git a/frontend/src/components/visual-editor/v2/Diagrams.tsx b/frontend/src/components/visual-editor/v2/Diagrams.tsx index 3783755..d8083d4 100644 --- a/frontend/src/components/visual-editor/v2/Diagrams.tsx +++ b/frontend/src/components/visual-editor/v2/Diagrams.tsx @@ -324,7 +324,7 @@ const Diagrams = () => { } }; const handleMoveButton = () => { - const selectedEntities = engine?.getModel().getSelectedEntities(); + const selectedEntities = engine?.getModel().getSelectedEntities().reverse(); const ids = selectedEntities?.map((model) => model.getID()); if (ids && selectedEntities) { @@ -453,10 +453,22 @@ const Diagrams = () => { if (ids) { for (const blockId of ids) { + const block = getBlockFromCache(blockId); + const updatedNextBlocks = block?.nextBlocks?.filter((nextBlockId) => + ids.includes(nextBlockId), + ); + const updatedAttachedBlock = ids.includes( + block?.attachedBlock as string, + ) + ? block?.attachedBlock + : null; + await updateBlock({ id: blockId, params: { category: newCategoryId, + nextBlocks: updatedNextBlocks, + attachedBlock: updatedAttachedBlock, }, }); }