mirror of
https://github.com/hexastack/hexabot
synced 2025-05-06 05:44:37 +00:00
fix: address feedback
This commit is contained in:
parent
82e47f23dd
commit
8f815d468c
@ -131,11 +131,12 @@ export class BlockRepository extends BaseRepository<
|
|||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
if (criteria._id?.$in && updates?.$set?.category) {
|
if (criteria._id?.$in && updates?.$set?.category) {
|
||||||
const ids: string[] = criteria._id?.$in || [];
|
const ids: string[] = criteria._id?.$in || [];
|
||||||
const objIds = ids.map((b) => {
|
|
||||||
return new mongoose.Types.ObjectId(b);
|
|
||||||
});
|
|
||||||
const category: string = updates.$set.category;
|
const category: string = updates.$set.category;
|
||||||
const objCategory = new mongoose.Types.ObjectId(category);
|
|
||||||
|
// Step 1: Map IDs and Category
|
||||||
|
const { objIds, objCategory } = this.mapIdsAndCategory(ids, category);
|
||||||
|
|
||||||
|
// Step 2: Find other blocks
|
||||||
const otherBlocks = await this.model.find({
|
const otherBlocks = await this.model.find({
|
||||||
_id: { $nin: objIds },
|
_id: { $nin: objIds },
|
||||||
category: { $ne: objCategory },
|
category: { $ne: objCategory },
|
||||||
@ -145,11 +146,35 @@ export class BlockRepository extends BaseRepository<
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Step 3: Update blocks in the provided scope
|
||||||
|
await this.updateBlocksInScope(objCategory, ids);
|
||||||
|
|
||||||
|
// Step 4: Update external blocks
|
||||||
|
await this.updateExternalBlocks(otherBlocks, objIds);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private mapIdsAndCategory(
|
||||||
|
ids: string[],
|
||||||
|
category: string,
|
||||||
|
): {
|
||||||
|
objIds: mongoose.Types.ObjectId[];
|
||||||
|
objCategory: mongoose.Types.ObjectId;
|
||||||
|
} {
|
||||||
|
const objIds = ids.map((id) => new mongoose.Types.ObjectId(id));
|
||||||
|
const objCategory = new mongoose.Types.ObjectId(category);
|
||||||
|
return { objIds, objCategory };
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateBlocksInScope(
|
||||||
|
objCategory: mongoose.Types.ObjectId,
|
||||||
|
ids: string[],
|
||||||
|
): Promise<void> {
|
||||||
for (const id of ids) {
|
for (const id of ids) {
|
||||||
const oldState = await this.model.findOne({
|
const oldState = await this.model.findOne({
|
||||||
_id: new mongoose.Types.ObjectId(id),
|
_id: new mongoose.Types.ObjectId(id),
|
||||||
});
|
});
|
||||||
if (oldState.category.toString() !== category) {
|
if (oldState.category.toString() !== objCategory.toString()) {
|
||||||
const updatedNextBlocks = oldState.nextBlocks.filter((nextBlock) =>
|
const updatedNextBlocks = oldState.nextBlocks.filter((nextBlock) =>
|
||||||
ids.includes(nextBlock.toString()),
|
ids.includes(nextBlock.toString()),
|
||||||
);
|
);
|
||||||
@ -169,30 +194,32 @@ export class BlockRepository extends BaseRepository<
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async updateExternalBlocks(
|
||||||
|
otherBlocks,
|
||||||
|
objIds: Types.ObjectId[],
|
||||||
|
): Promise<void> {
|
||||||
for (const block of otherBlocks) {
|
for (const block of otherBlocks) {
|
||||||
if (ids.includes(block.attachedBlock?.toString())) {
|
if (
|
||||||
await this.model.updateOne(
|
objIds.some((id) => id.toString() === block.attachedBlock?.toString())
|
||||||
{ _id: block.id },
|
) {
|
||||||
{
|
await this.model.updateOne({ _id: block.id }, { attachedBlock: null });
|
||||||
attachedBlock: null,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
if (block.nextBlocks.some((item) => ids.includes(item.toString()))) {
|
|
||||||
const updatedNextBlocks = block.nextBlocks.filter(
|
const updatedNextBlocks = block.nextBlocks.filter(
|
||||||
(nextBlock) => !ids.includes(nextBlock.toString()),
|
(nextBlock) =>
|
||||||
|
!objIds.some((id) => id.toString() === nextBlock.toString()),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (updatedNextBlocks.length !== block.nextBlocks.length) {
|
||||||
await this.model.updateOne(
|
await this.model.updateOne(
|
||||||
{ _id: block.id },
|
{ _id: block.id },
|
||||||
{
|
{ nextBlocks: updatedNextBlocks },
|
||||||
nextBlocks: updatedNextBlocks,
|
|
||||||
},
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Post-processing logic after deleting a block.
|
* Post-processing logic after deleting a block.
|
||||||
|
@ -6,12 +6,11 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Add } from "@mui/icons-material";
|
import { Add, MoveUp } from "@mui/icons-material";
|
||||||
import DeleteIcon from "@mui/icons-material/Delete";
|
import DeleteIcon from "@mui/icons-material/Delete";
|
||||||
import EditIcon from "@mui/icons-material/Edit";
|
import EditIcon from "@mui/icons-material/Edit";
|
||||||
import FitScreenIcon from "@mui/icons-material/FitScreen";
|
import FitScreenIcon from "@mui/icons-material/FitScreen";
|
||||||
import RestartAltIcon from "@mui/icons-material/RestartAlt";
|
import RestartAltIcon from "@mui/icons-material/RestartAlt";
|
||||||
import MoveIcon from "@mui/icons-material/Swipe";
|
|
||||||
import ZoomInIcon from "@mui/icons-material/ZoomIn";
|
import ZoomInIcon from "@mui/icons-material/ZoomIn";
|
||||||
import ZoomOutIcon from "@mui/icons-material/ZoomOut";
|
import ZoomOutIcon from "@mui/icons-material/ZoomOut";
|
||||||
import {
|
import {
|
||||||
@ -622,7 +621,7 @@ const Diagrams = () => {
|
|||||||
<Button
|
<Button
|
||||||
size="small"
|
size="small"
|
||||||
variant="contained"
|
variant="contained"
|
||||||
startIcon={<MoveIcon />}
|
startIcon={<MoveUp />}
|
||||||
onClick={handleMoveButton}
|
onClick={handleMoveButton}
|
||||||
disabled={!selectedBlockId || selectedBlockId.length !== 24}
|
disabled={!selectedBlockId || selectedBlockId.length !== 24}
|
||||||
>
|
>
|
||||||
|
Loading…
Reference in New Issue
Block a user