diff --git a/src/hooks/useContextMenu.js b/src/hooks/useContextMenu.js index 842cad28..f1cb43e4 100644 --- a/src/hooks/useContextMenu.js +++ b/src/hooks/useContextMenu.js @@ -706,12 +706,68 @@ export function useContextMenu() { { id: 'moduleVerticalCenterAlign', name: getMessage('contextmenu.module.vertical.align'), - fn: () => alignModule(MODULE_ALIGN_TYPE.VERTICAL, currentObject.arrayData ?? [currentObject]), + fn: () => { + if (currentObject.arrayData) { + let existCircuit = false + currentObject.arrayData.forEach((surface) => { + surface.modules.forEach((module) => { + if (module.circuit) existCircuit = true + }) + }) + if (existCircuit) { + swalFire({ + title: getMessage('can.not.move.module'), + icon: 'error', + type: 'alert', + }) + return + } + } else { + const allocatedModules = currentObject.modules.filter((module) => module.circuit !== null) + if (allocatedModules.length > 0) { + swalFire({ + title: getMessage('can.not.move.module'), + icon: 'error', + type: 'alert', + }) + return + } + } + alignModule(MODULE_ALIGN_TYPE.VERTICAL, currentObject.arrayData ?? [currentObject]) + }, }, { id: 'moduleHorizonCenterAlign', name: getMessage('contextmenu.module.horizon.align'), - fn: () => alignModule(MODULE_ALIGN_TYPE.HORIZONTAL, currentObject.arrayData ?? [currentObject]), + fn: () => { + if (currentObject.arrayData) { + let existCircuit = false + currentObject.arrayData.forEach((surface) => { + surface.modules.forEach((module) => { + if (module.circuit) existCircuit = true + }) + }) + if (existCircuit) { + swalFire({ + title: getMessage('can.not.move.module'), + icon: 'error', + type: 'alert', + }) + return + } + } else { + const allocatedModules = currentObject.modules.filter((module) => module.circuit !== null) + if (allocatedModules.length > 0) { + swalFire({ + title: getMessage('can.not.move.module'), + icon: 'error', + type: 'alert', + }) + return + } + } + alignModule(MODULE_ALIGN_TYPE.HORIZONTAL, currentObject.arrayData ?? [currentObject]) + }, }, { id: 'moduleRemove',