fix: resolve conflicts

This commit is contained in:
hexastack 2024-10-31 17:06:28 +01:00
parent ce20bb725a
commit 310d9e47aa
2 changed files with 28 additions and 2 deletions

View File

@ -89,12 +89,26 @@ export class BlockRepository extends BaseRepository<
Block,
'findOneAndUpdate'
>,
_criteria: TFilterQuery<Block>,
criteria: TFilterQuery<Block>,
_updates:
| UpdateWithAggregationPipeline
| UpdateQuery<Document<Block, any, any>>,
): Promise<void> {
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);
}

View File

@ -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,
},
});
}