mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge e211aa36ba
into 3e1a20bfc8
This commit is contained in:
commit
0a37959377
@ -140,12 +140,12 @@ export class BlockRepository extends BaseRepository<
|
|||||||
|
|
||||||
// Step 1: Map IDs and Category
|
// Step 1: Map IDs and Category
|
||||||
const objIds = ids.map((id) => new Types.ObjectId(id));
|
const objIds = ids.map((id) => new Types.ObjectId(id));
|
||||||
const objCategoryId = new Types.ObjectId(categoryId);
|
const sourceCategoryId = movedBlocks[0].category;
|
||||||
|
|
||||||
// Step 2: Find other blocks
|
// Step 2: Find blocks in source category that reference the moved blocks
|
||||||
const otherBlocks = await this.find({
|
const otherBlocks = await this.find({
|
||||||
_id: { $nin: objIds },
|
_id: { $nin: objIds },
|
||||||
category: { $ne: objCategoryId },
|
category: sourceCategoryId,
|
||||||
$or: [
|
$or: [
|
||||||
{ attachedBlock: { $in: objIds } },
|
{ attachedBlock: { $in: objIds } },
|
||||||
{ nextBlocks: { $in: objIds } },
|
{ nextBlocks: { $in: objIds } },
|
||||||
@ -154,7 +154,7 @@ export class BlockRepository extends BaseRepository<
|
|||||||
// Step 3: Update blocks in the provided scope
|
// Step 3: Update blocks in the provided scope
|
||||||
await this.prepareBlocksInCategoryUpdateScope(categoryId, ids);
|
await this.prepareBlocksInCategoryUpdateScope(categoryId, ids);
|
||||||
|
|
||||||
// Step 4: Update external blocks
|
// Step 4: Update blocks in source category
|
||||||
await this.prepareBlocksOutOfCategoryUpdateScope(otherBlocks, ids);
|
await this.prepareBlocksOutOfCategoryUpdateScope(otherBlocks, ids);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -178,6 +178,7 @@ export class BlockRepository extends BaseRepository<
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
for (const { id, nextBlocks, attachedBlock } of blocks) {
|
||||||
|
try {
|
||||||
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
const updatedNextBlocks = nextBlocks.filter((nextBlock) =>
|
||||||
ids.includes(nextBlock),
|
ids.includes(nextBlock),
|
||||||
);
|
);
|
||||||
@ -186,10 +187,18 @@ export class BlockRepository extends BaseRepository<
|
|||||||
? attachedBlock
|
? attachedBlock
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
await this.updateOne(id, {
|
const updates: Partial<Block> = {
|
||||||
nextBlocks: updatedNextBlocks,
|
nextBlocks: updatedNextBlocks,
|
||||||
attachedBlock: updatedAttachedBlock,
|
attachedBlock: updatedAttachedBlock,
|
||||||
});
|
};
|
||||||
|
|
||||||
|
await this.updateOne(id, updates);
|
||||||
|
} catch (error) {
|
||||||
|
this.logger?.error(
|
||||||
|
`Failed to update block ${id} during in-category scope update.`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -206,16 +215,33 @@ export class BlockRepository extends BaseRepository<
|
|||||||
ids: string[],
|
ids: string[],
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
for (const block of otherBlocks) {
|
for (const block of otherBlocks) {
|
||||||
if (block.attachedBlock && ids.includes(block.attachedBlock)) {
|
try {
|
||||||
await this.updateOne(block.id, { attachedBlock: null });
|
const updates: Partial<Block> = {};
|
||||||
}
|
|
||||||
|
|
||||||
const nextBlocks = block.nextBlocks?.filter(
|
// Check if the block has an attachedBlock
|
||||||
|
if (block.attachedBlock) {
|
||||||
|
if (ids.includes(block.attachedBlock)) {
|
||||||
|
updates.attachedBlock = null;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Only check nextBlocks if there is no attachedBlock
|
||||||
|
const filteredNextBlocks = block.nextBlocks?.filter(
|
||||||
(nextBlock) => !ids.includes(nextBlock),
|
(nextBlock) => !ids.includes(nextBlock),
|
||||||
);
|
);
|
||||||
|
|
||||||
if (nextBlocks?.length) {
|
if (filteredNextBlocks?.length !== block.nextBlocks?.length) {
|
||||||
await this.updateOne(block.id, { nextBlocks });
|
updates.nextBlocks = filteredNextBlocks || [];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Object.keys(updates).length > 0) {
|
||||||
|
await this.updateOne(block.id, updates);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
this.logger?.error(
|
||||||
|
`Failed to update block ${block.id} during out-of-category scope update.`,
|
||||||
|
error,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -118,6 +118,7 @@
|
|||||||
"logout_failed": "Something went wrong during logout",
|
"logout_failed": "Something went wrong during logout",
|
||||||
"duplicate_labels_not_allowed": "Duplicate labels are not allowed",
|
"duplicate_labels_not_allowed": "Duplicate labels are not allowed",
|
||||||
"duplicate_block_error": "Something went wrong while duplicating block",
|
"duplicate_block_error": "Something went wrong while duplicating block",
|
||||||
|
"move_block_error": "Something went wrong. Unable to move block",
|
||||||
"image_error": "Image not found",
|
"image_error": "Image not found",
|
||||||
"file_error": "File not found",
|
"file_error": "File not found",
|
||||||
"audio_error": "Audio not found",
|
"audio_error": "Audio not found",
|
||||||
|
@ -118,6 +118,7 @@
|
|||||||
"logout_failed": "Une erreur s'est produite lors de la déconnexion",
|
"logout_failed": "Une erreur s'est produite lors de la déconnexion",
|
||||||
"duplicate_labels_not_allowed": "Les étiquettes en double ne sont pas autorisées",
|
"duplicate_labels_not_allowed": "Les étiquettes en double ne sont pas autorisées",
|
||||||
"duplicate_block_error": "Une erreur est survenue lors de la duplication du bloc",
|
"duplicate_block_error": "Une erreur est survenue lors de la duplication du bloc",
|
||||||
|
"move_block_error": "Une erreur est survenue. Impossible de déplacer le bloc",
|
||||||
"image_error": "Image introuvable",
|
"image_error": "Image introuvable",
|
||||||
"file_error": "Fichier introuvable",
|
"file_error": "Fichier introuvable",
|
||||||
"audio_error": "Audio introuvable",
|
"audio_error": "Audio introuvable",
|
||||||
|
@ -559,9 +559,14 @@ const Diagrams = () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
onCategoryChange(
|
const targetCategoryIndex = categories.findIndex(
|
||||||
categories.findIndex(({ id }) => id === targetCategoryId),
|
({ id }) => id === targetCategoryId,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
onCategoryChange(targetCategoryIndex);
|
||||||
|
},
|
||||||
|
onError: () => {
|
||||||
|
toast.error(t("message.move_block_error"));
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user