From 23570d7007f0c6fb98846b64a7a7581295c5a12b Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Fri, 5 Sep 2025 15:54:38 +0530 Subject: [PATCH] integerated product context to scene context --- .../layout/scenes/ComparisonScene.tsx | 7 +- .../components/layout/scenes/MainScene.tsx | 9 +- .../eventProperties/EventProperties.tsx | 224 ++-- .../components/ActionsList.tsx | 84 +- .../mechanics/conveyorMechanics.tsx | 164 +-- .../mechanics/craneMechanics.tsx | 76 +- .../mechanics/humanMechanics.tsx | 184 +-- .../mechanics/machineMechanics.tsx | 98 +- .../mechanics/roboticArmMechanics.tsx | 133 +-- .../mechanics/storageMechanics.tsx | 165 +-- .../mechanics/vehicleMechanics.tsx | 142 +-- .../eventProperties/trigger/Trigger.tsx | 185 +-- .../sidebarRight/simulation/Simulations.tsx | 122 +- app/src/hooks/useResetStates.ts | 6 +- .../eventHandlers/useModelEventHandlers.ts | 188 ++- .../selection3D/moveControls3D.tsx | 11 +- .../selection3D/rotateControls3D.tsx | 11 +- .../selection3D/selectionControls3D.tsx | 7 +- .../selection3D/transformControls3D.tsx | 11 +- .../transformControls/transformControls.tsx | 11 +- .../handlers/use3DRedoHandler.ts | 177 ++- .../handlers/use3DUndoHandler.ts | 213 ++-- .../conveyor/actionHandler/useSpawnHandler.ts | 119 +- .../actionHandler/usePickAndDropHandler.ts | 35 +- .../actionHandler/useManufacturerHandler.ts | 35 +- .../human/actionHandler/useWorkerHandler.ts | 35 +- .../actionHandler/useProcessHandler.ts | 39 +- .../actionHandler/usePickAndPlaceHandler.ts | 36 +- .../actionHandler/useRetrieveHandler.ts | 303 ++--- .../actionHandler/useStoreHandler.ts | 37 +- .../vehicle/actionHandler/useTravelHandler.ts | 33 +- .../simulation/analysis/ROI/roiData.tsx | 58 +- .../analysis/throughPut/throughPutData.tsx | 81 +- .../conveyorInstance/conveyorInstance.tsx | 26 +- .../eventManager/useCraneEventManager.ts | 53 +- .../instances/animator/pillarJibAnimator.tsx | 158 ++- .../instances/instance/pillarJibInstance.tsx | 107 +- .../simulation/events/arrows/arrows.tsx | 7 +- .../events/points/creator/pointsCreator.tsx | 5 +- .../instances/instance/pointInstance.tsx | 7 +- .../points/instances/pointInstances.tsx | 21 +- .../triggerConnections/triggerConnector.tsx | 9 +- .../eventManager/useHumanEventManager.ts | 56 +- .../animator/manufacturerAnimator.tsx | 37 +- .../instances/animator/materialAnimator.tsx | 36 +- .../instances/animator/operatorAnimator.tsx | 43 +- .../instances/animator/workerAnimator.tsx | 57 +- .../instance/actions/manufacturerInstance.tsx | 139 +-- .../instance/actions/operatorInstance.tsx | 145 ++- .../instance/actions/workerInstance.tsx | 384 +++--- .../instances/instance/humanInstance.tsx | 42 +- .../human/instances/instance/humanUi.tsx | 5 +- .../machineInstance/machineInstance.tsx | 59 +- .../instances/instance/materialInstance.tsx | 45 +- .../simulation/products/productContext.tsx | 37 - .../modules/simulation/products/products.tsx | 121 +- .../instances/animator/roboticArmAnimator.tsx | 94 +- .../armInstance/roboticArmInstance.tsx | 184 ++- .../simulation/simulator/simulator.tsx | 28 +- .../simulation/spatialUI/arm/armBotUI.tsx | 5 +- .../spatialUI/arm/useDraggableGLTF.ts | 36 +- .../spatialUI/vehicle/vehicleUI.tsx | 5 +- .../triggerHandler/useTriggerHandler.ts | 1063 +++++++---------- .../instances/instance/vehicleInstance.tsx | 296 ++--- app/src/pages/Project.tsx | 9 +- app/src/store/simulation/useProductStore.ts | 384 +++--- .../store/simulation/useSimulationStore.ts | 28 - 67 files changed, 2573 insertions(+), 4197 deletions(-) delete mode 100644 app/src/modules/simulation/products/productContext.tsx diff --git a/app/src/components/layout/scenes/ComparisonScene.tsx b/app/src/components/layout/scenes/ComparisonScene.tsx index 2938f27..b09e53e 100644 --- a/app/src/components/layout/scenes/ComparisonScene.tsx +++ b/app/src/components/layout/scenes/ComparisonScene.tsx @@ -1,5 +1,4 @@ import { useParams } from "react-router-dom"; -import { useProductContext } from "../../../modules/simulation/products/productContext"; import { useCompareProductDataStore, useLoadingProgress, useSaveVersion } from "../../../store/builder/store"; import { useComparisonProduct, useMainProduct } from "../../../store/simulation/useSimulationStore"; import { usePlayButtonStore } from "../../../store/ui/usePlayButtonStore"; @@ -16,17 +15,15 @@ function ComparisonScene() { const { isPlaying } = usePlayButtonStore(); const { productStore, versionStore } = useSceneContext(); const { versionHistory, selectedVersion, setSelectedVersion, setVersions } = versionStore(); - const { products } = productStore(); + const { products, selectedProduct } = productStore(); const { isVersionSaved } = useSaveVersion(); const { activeModule } = useModuleStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); const { comparisonProduct, setComparisonProduct } = useComparisonProduct(); const { mainProduct } = useMainProduct(); const { loadingProgress } = useLoadingProgress(); const { compareProductsData } = useCompareProductDataStore(); const [shouldShowComparisonResult, setShouldShowComparisonResult] = useState(false); - const { projectId } = useParams() + const { projectId } = useParams(); const handleSelectVersion = (option: string) => { const version = versionHistory.find((version) => version.versionName === option); diff --git a/app/src/components/layout/scenes/MainScene.tsx b/app/src/components/layout/scenes/MainScene.tsx index 34a1672..5db82a5 100644 --- a/app/src/components/layout/scenes/MainScene.tsx +++ b/app/src/components/layout/scenes/MainScene.tsx @@ -1,4 +1,5 @@ import { useEffect } from "react"; +import { useParams } from "react-router-dom"; import { useLoadingProgress, useRenameModeStore, useSaveVersion, useSelectedComment, useSocketStore, useWidgetSubOption } from "../../../store/builder/store"; import useModuleStore, { useThreeDStore } from "../../../store/ui/useModuleStore"; import { usePlayButtonStore } from "../../../store/ui/usePlayButtonStore"; @@ -7,11 +8,8 @@ import { useFloatingWidget } from "../../../store/visualization/useDroppedObject import { useSelectedUserStore } from "../../../store/collaboration/useCollabStore"; import { createHandleDrop } from "../../../modules/visualization/functions/handleUiDrop"; import { useComparisonProduct, useMainProduct } from "../../../store/simulation/useSimulationStore"; -import { useProductContext } from "../../../modules/simulation/products/productContext"; -import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../modules/scene/sceneContext"; import { useBuilderStore } from "../../../store/builder/useBuilderStore"; -import { getUserData } from "../../../functions/getUserData"; import useRestStates from "../../../hooks/useResetStates"; import KeyPressListener from "../../../utils/shortcutkeys/handleShortcutKeys"; import LoadingPage from "../../templates/LoadingPage"; @@ -31,14 +29,13 @@ import Footer from "../../footer/Footer"; import ThreadChat from "../../ui/collaboration/ThreadChat"; import Scene from "../../../modules/scene/scene"; +import { getUserData } from "../../../functions/getUserData"; import { recentlyViewed } from "../../../services/dashboard/recentlyViewed"; import { setAssetsApi } from "../../../services/factoryBuilder/asset/floorAsset/setAssetsApi"; import { getVersionHistoryApi } from "../../../services/factoryBuilder/versionControl/getVersionHistoryApi"; function MainScene() { const { setMainProduct } = useMainProduct(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); const { isVersionSaved, setIsVersionSaved } = useSaveVersion(); const { activeModule } = useModuleStore(); const { selectedUser } = useSelectedUserStore(); @@ -52,7 +49,7 @@ function MainScene() { const { clearComparisonProduct } = useComparisonProduct(); const { selectedFloorAsset, setSelectedFloorAsset } = useBuilderStore(); const { assetStore, productStore, versionStore } = useSceneContext(); - const { products } = productStore(); + const { products, selectedProduct } = productStore(); const { versionHistory, setVersions, selectedVersion, setSelectedVersion } = versionStore(); const { setName, selectedAssets, setSelectedAssets } = assetStore(); const { projectId } = useParams(); diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx index 1ac963f..402c2a0 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/EventProperties.tsx @@ -1,8 +1,5 @@ import React, { useEffect, useState } from "react"; -import { - useSelectedEventData, - useSelectedEventSphere, -} from "../../../../../store/simulation/useSimulationStore"; +import { useSelectedEventData, useSelectedEventSphere } from "../../../../../store/simulation/useSimulationStore"; import ConveyorMechanics from "./mechanics/conveyorMechanics"; import VehicleMechanics from "./mechanics/vehicleMechanics"; import RoboticArmMechanics from "./mechanics/roboticArmMechanics"; @@ -11,134 +8,117 @@ import StorageMechanics from "./mechanics/storageMechanics"; import HumanMechanics from "./mechanics/humanMechanics"; import { AddIcon } from "../../../../icons/ExportCommonIcons"; import { handleAddEventToProduct } from "../../../../../modules/simulation/events/points/functions/handleAddEventToProduct"; -import { useProductContext } from "../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../modules/scene/sceneContext"; import CraneMechanics from "./mechanics/craneMechanics"; const EventProperties: React.FC = () => { - const { selectedEventData } = useSelectedEventData(); - const { selectedProductStore } = useProductContext(); - const { eventStore, productStore, versionStore } = useSceneContext(); - const { selectedProduct } = selectedProductStore(); - const [currentEventData, setCurrentEventData] = useState(null); - const [assetType, setAssetType] = useState(null); - const { products, addEvent, getEventByModelUuid } = productStore(); - const { selectedEventSphere } = useSelectedEventSphere(); - const { selectedVersion } = versionStore(); - const { projectId } = useParams(); + const { selectedEventData } = useSelectedEventData(); + const { eventStore, productStore, versionStore } = useSceneContext(); + const [currentEventData, setCurrentEventData] = useState(null); + const [assetType, setAssetType] = useState(null); + const { products, addEvent, getEventByModelUuid, selectedProduct } = productStore(); + const { selectedEventSphere } = useSelectedEventSphere(); + const { selectedVersion } = versionStore(); + const { projectId } = useParams(); - useEffect(() => { - const event = getCurrentEventData(); - setCurrentEventData(event); + useEffect(() => { + const event = getCurrentEventData(); + setCurrentEventData(event); - const type = determineAssetType(event); - setAssetType(type); - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [selectedEventData, selectedProduct]); + const type = determineAssetType(event); + setAssetType(type); + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [selectedEventData, selectedProduct]); + + const getCurrentEventData = () => { + if (!selectedEventData?.data || !selectedProduct) return null; + return getEventByModelUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid) ?? null; + }; + + const determineAssetType = (event: EventsSchema | null) => { + if (!event) return null; + + switch (event.type) { + case "transfer": + return "conveyor"; + case "vehicle": + return "vehicle"; + case "roboticArm": + return "roboticArm"; + case "machine": + return "machine"; + case "storageUnit": + return "storageUnit"; + case "human": + return "human"; + case "crane": + return "crane"; + default: + return null; + } + }; - const getCurrentEventData = () => { - if (!selectedEventData?.data || !selectedProduct) return null; return ( - getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid - ) ?? null +
+ {currentEventData && ( + <> +
+
{selectedEventData?.data.modelName}
+
+ {assetType === "conveyor" && } + {assetType === "vehicle" && } + {assetType === "roboticArm" && } + {assetType === "machine" && } + {assetType === "storageUnit" && } + {assetType === "human" && } + {assetType === "crane" && } + + )} + {!currentEventData && selectedEventSphere && ( +
+

+ Oops! It looks like this object doesn't have an event assigned yet. To continue, please link it to one of the products below. +

+ +
+

+ Here are some products you can add it to: +

+
+ {products.map((product) => ( + + ))} +
+
+
+ )} + {!selectedEventSphere && ( +
+

+ Oops! It looks like you haven't selected an event point yet. Please select an event to view its properties. +

+
+ )} +
); - }; - - const determineAssetType = (event: EventsSchema | null) => { - if (!event) return null; - - switch (event.type) { - case "transfer": - return "conveyor"; - case "vehicle": - return "vehicle"; - case "roboticArm": - return "roboticArm"; - case "machine": - return "machine"; - case "storageUnit": - return "storageUnit"; - case "human": - return "human"; - case "crane": - return "crane"; - default: - return null; - } - }; - - return ( -
- {currentEventData && ( - <> -
-
- {selectedEventData?.data.modelName} -
-
- {assetType === "conveyor" && } - {assetType === "vehicle" && } - {assetType === "roboticArm" && } - {assetType === "machine" && } - {assetType === "storageUnit" && } - {assetType === "human" && } - {assetType === "crane" && } - - )} - {!currentEventData && selectedEventSphere && ( -
-

- Oops! It looks like this object doesn't have an - event assigned yet. To continue, please link it to one of the - products below. -

- -
-

- Here are some products you can add it to: -

-
- {products.map((product) => ( - - ))} -
-
-
- )} - {!selectedEventSphere && ( -
-

- Oops! It looks like you haven't selected an event - point yet. Please select an event to view its properties. -

-
- )} -
- ); }; export default EventProperties; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx index 284c29e..f71eb9a 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/components/ActionsList.tsx @@ -1,16 +1,9 @@ import React, { useRef } from "react"; -import { - AddIcon, - RemoveIcon, - ResizeHeightIcon, -} from "../../../../../icons/ExportCommonIcons"; +import { AddIcon, RemoveIcon, ResizeHeightIcon } from "../../../../../icons/ExportCommonIcons"; import RenameInput from "../../../../../ui/inputs/RenameInput"; import { handleResize } from "../../../../../../functions/handleResizePannel"; -import { - useSelectedAction, -} from "../../../../../../store/simulation/useSimulationStore"; +import { useSelectedAction } from "../../../../../../store/simulation/useSimulationStore"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -21,31 +14,20 @@ interface ActionsListProps { handleDeleteAction?: (actionUuid: string) => void; } -const ActionsList: React.FC = ({ - selectedPointData, - multipleAction = false, - handleAddAction, - handleDeleteAction, -}) => { +const ActionsList: React.FC = ({ selectedPointData, multipleAction = false, handleAddAction, handleDeleteAction }) => { const actionsContainerRef = useRef(null); // store const { productStore, versionStore } = useSceneContext(); - const { renameAction } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { renameAction, selectedProduct } = productStore(); const { selectedAction, setSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); const handleRenameAction = (newName: string) => { if (!selectedAction.actionId) return; - const event = renameAction( - selectedProduct.productUuid, - selectedAction.actionId, - newName - ); + const event = renameAction(selectedProduct.productUuid, selectedAction.actionId, newName); setSelectedAction(selectedAction.actionId, newName); if (event) { upsertProductOrEventApi({ @@ -53,7 +35,7 @@ const ActionsList: React.FC = ({ productUuid: selectedProduct.productUuid, projectId, eventDatas: event, - versionId: selectedVersion?.versionId || '', + versionId: selectedVersion?.versionId || "", }); } }; @@ -81,32 +63,13 @@ const ActionsList: React.FC = ({ Add -
+
{multipleAction && selectedPointData?.actions?.map((action: any) => ( -
- {selectedPointData?.actions?.length > 1 && (
))} {!multipleAction && selectedPointData?.action && ( -
-
)}
{multipleAction && ( - )} diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx index 45f9aa1..5a492fd 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/conveyorMechanics.tsx @@ -11,7 +11,6 @@ import Trigger from "../trigger/Trigger"; import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -27,25 +26,16 @@ function ConveyorMechanics() { const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, updateEvent, updateAction, getEventByModelUuid } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, updateEvent, updateAction, getEventByModelUuid, selectedProduct } = productStore(); const { setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { if (selectedEventData) { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData?.data.modelUuid, - selectedEventData?.selectedPoint - ) as ConveyorPointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData?.data.modelUuid, selectedEventData?.selectedPoint) as ConveyorPointSchema | undefined; - const event = getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData?.data.modelUuid - ) as ConveyorEventSchema | undefined; + const event = getEventByModelUuid(selectedProduct.productUuid, selectedEventData?.data.modelUuid) as ConveyorEventSchema | undefined; if (point && "action" in point && event) { setSelectedPointData(point); @@ -63,12 +53,7 @@ function ConveyorMechanics() { } }, [selectedProduct, selectedEventData]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -84,19 +69,10 @@ function ConveyorMechanics() { const numericValue = parseFloat(value); if (isNaN(numericValue)) return; - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - { speed: numericValue } - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, { speed: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSpeed(value); }; @@ -107,19 +83,10 @@ function ConveyorMechanics() { const validOption = option as "default" | "spawn" | "swap" | "delay" | "despawn"; setActiveOption(validOption); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { actionType: validOption } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { actionType: validOption }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -130,19 +97,10 @@ function ConveyorMechanics() { if (isNaN(numericValue)) return; setSpawnCount(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { spawnCount: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { spawnCount: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -153,19 +111,10 @@ function ConveyorMechanics() { if (isNaN(numericValue)) return; setSpawnInterval(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { spawnInterval: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { spawnInterval: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -173,19 +122,10 @@ function ConveyorMechanics() { if (!selectedPointData) return; setMaterial(selectedMaterial); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { material: selectedMaterial } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { material: selectedMaterial }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -196,19 +136,10 @@ function ConveyorMechanics() { if (isNaN(numericValue)) return; setDelay(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { delay: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { delay: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -222,17 +153,7 @@ function ConveyorMechanics() {
- { }} - onChange={handleSpeedChange} - /> + {}} onChange={handleSpeedChange} />
@@ -241,60 +162,23 @@ function ConveyorMechanics() {
- +
- + {activeOption === "default" && } - {activeOption === "spawn" && ( - - )} - {activeOption === "swap" && ( - - )} + {activeOption === "spawn" && } + {activeOption === "swap" && } {activeOption === "despawn" && } - {activeOption === "delay" && ( - - )} + {activeOption === "delay" && }
- +
); } -export default ConveyorMechanics; \ No newline at end of file +export default ConveyorMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/craneMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/craneMechanics.tsx index 8c667a4..b594256 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/craneMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/craneMechanics.tsx @@ -6,7 +6,6 @@ import Trigger from "../trigger/Trigger"; import { useSelectedEventData, useSelectedAction } from "../../../../../../store/simulation/useSimulationStore"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -16,20 +15,14 @@ function CraneMechanics() { const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, addAction, removeAction } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, addAction, removeAction, selectedProduct } = productStore(); const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { if (selectedEventData) { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as CranePointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as CranePointSchema | undefined; if (point?.actions) { setSelectedPointData(point); @@ -45,12 +38,7 @@ function CraneMechanics() { } }, [selectedEventData, selectedProduct]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -71,20 +59,10 @@ function CraneMechanics() { triggers: [] as TriggerSchema[], }; - const event = addAction( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint, - newAction - ); + const event = addAction(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint, newAction); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData({ @@ -97,22 +75,14 @@ function CraneMechanics() { const handleDeleteAction = (actionUuid: string) => { if (!selectedPointData) return; - const event = removeAction( - selectedProduct.productUuid, - actionUuid - ); + const event = removeAction(selectedProduct.productUuid, actionUuid); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } - const index = selectedPointData.actions.findIndex(a => a.actionUuid === actionUuid); - const newActions = selectedPointData.actions.filter(a => a.actionUuid !== actionUuid); + const index = selectedPointData.actions.findIndex((a) => a.actionUuid === actionUuid); + const newActions = selectedPointData.actions.filter((a) => a.actionUuid !== actionUuid); setSelectedPointData({ ...selectedPointData, @@ -134,39 +104,23 @@ function CraneMechanics() { options: ["pickAndDrop"], }; - const currentAction = selectedPointData?.actions.find(a => a.actionUuid === selectedAction.actionId); + const currentAction = selectedPointData?.actions.find((a) => a.actionUuid === selectedAction.actionId); return ( <>
- + {selectedAction.actionId && currentAction && (
- +
- { }} - disabled={true} - /> + {}} disabled={true} />
- +
)} @@ -175,4 +129,4 @@ function CraneMechanics() { ); } -export default CraneMechanics \ No newline at end of file +export default CraneMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/humanMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/humanMechanics.tsx index 2dc1431..d69f72d 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/humanMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/humanMechanics.tsx @@ -11,7 +11,6 @@ import ManufactureAction from "../actions/ManufactureAction"; import { useSelectedEventData, useSelectedAction } from "../../../../../../store/simulation/useSimulationStore"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; import { useParams } from "react-router-dom"; @@ -27,32 +26,21 @@ function HumanMechanics() { const [selectedPointData, setSelectedPointData] = useState(); const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, updateEvent, updateAction, addAction, removeAction, getEventByModelUuid, getActionByUuid } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, updateEvent, updateAction, addAction, removeAction, getEventByModelUuid, getActionByUuid, selectedProduct } = productStore(); const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { if (selectedEventData && selectedEventData.data.type === "human") { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as HumanPointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as HumanPointSchema | undefined; if (point?.actions?.length) { setSelectedPointData(point); const firstAction = point.actions[0]; setSelectedAction(firstAction.actionUuid, firstAction.actionName); setCurrentAction(firstAction); - setSpeed(( - getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData?.data.modelUuid || "" - ) as HumanEventSchema | undefined - )?.speed?.toString() || "1"); + setSpeed((getEventByModelUuid(selectedProduct.productUuid, selectedEventData?.data.modelUuid || "") as HumanEventSchema | undefined)?.speed?.toString() || "1"); setLoadCapacity(firstAction.loadCapacity.toString()); setActiveOption(firstAction.actionType); setLoadCount(firstAction.loadCount || 0); @@ -67,17 +55,13 @@ function HumanMechanics() { useEffect(() => { if (selectedEventData && selectedEventData.data.type === "human") { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as HumanPointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as HumanPointSchema | undefined; - const actionUuid = selectedAction.actionId || point?.actions[0].actionUuid || ''; + const actionUuid = selectedAction.actionId || point?.actions[0].actionUuid || ""; const newCurrentAction = getActionByUuid(selectedProduct.productUuid, actionUuid); - if (newCurrentAction && (newCurrentAction.actionType === 'manufacturer' || newCurrentAction?.actionType === 'worker' || newCurrentAction?.actionType === "operator")) { + if (newCurrentAction && (newCurrentAction.actionType === "manufacturer" || newCurrentAction?.actionType === "worker" || newCurrentAction?.actionType === "operator")) { if (!selectedAction.actionId) { setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName); } @@ -87,7 +71,7 @@ function HumanMechanics() { setLoadCount(newCurrentAction.loadCount || 0); setManufactureCount(newCurrentAction.manufactureCount || 0); - if (newCurrentAction.actionType === 'manufacturer') { + if (newCurrentAction.actionType === "manufacturer") { setProcessTime(newCurrentAction.processTime || 10); setSwappedMaterial(newCurrentAction.swapMaterial || "Default material"); } @@ -98,12 +82,7 @@ function HumanMechanics() { } }, [selectedAction, selectedProduct, selectedEventData]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -117,17 +96,13 @@ function HumanMechanics() { if (!selectedAction.actionId || !currentAction || !selectedPointData) return; const updatedAction = { ...currentAction, actionType: actionType as "worker" | "manufacturer" | "operator" | "assembler" }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -141,17 +116,13 @@ function HumanMechanics() { if (isNaN(numericValue)) return; const updatedEvent = { - speed: numericValue + speed: numericValue, } as HumanEventSchema; - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - updatedEvent - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, updatedEvent); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSpeed(value); @@ -161,17 +132,13 @@ function HumanMechanics() { if (!currentAction || !selectedPointData || !selectedAction.actionId) return; const updatedAction = { ...currentAction, loadCapacity: parseInt(value) }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -183,17 +150,13 @@ function HumanMechanics() { if (!currentAction || !selectedPointData || !selectedAction.actionId) return; const updatedAction = { ...currentAction, loadCount: value }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -205,17 +168,13 @@ function HumanMechanics() { if (!currentAction || !selectedPointData || !selectedAction.actionId) return; const updatedAction = { ...currentAction, manufactureCount: value }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -227,17 +186,13 @@ function HumanMechanics() { if (!currentAction || !selectedPointData || !selectedAction.actionId) return; const updatedAction = { ...currentAction, processTime: value }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -249,17 +204,13 @@ function HumanMechanics() { if (!currentAction || !selectedPointData || !selectedAction.actionId) return; const updatedAction = { ...currentAction, swapMaterial: value }; - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -272,24 +223,20 @@ function HumanMechanics() { const updatedAction: HumanAction = JSON.parse(JSON.stringify(currentAction)); - if (updatedAction.actionType === 'manufacturer') { - updatedAction.manufacturePoint = { position: null, rotation: null, } + if (updatedAction.actionType === "manufacturer") { + updatedAction.manufacturePoint = { position: null, rotation: null }; } else { - updatedAction.pickUpPoint = { position: null, rotation: null, }; - updatedAction.dropPoint = { position: null, rotation: null, } + updatedAction.pickUpPoint = { position: null, rotation: null }; + updatedAction.dropPoint = { position: null, rotation: null }; } - const updatedActions = selectedPointData.actions.map(action => action.actionUuid === updatedAction.actionUuid ? updatedAction : action); + const updatedActions = selectedPointData.actions.map((action) => (action.actionUuid === updatedAction.actionUuid ? updatedAction : action)); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentAction(updatedAction); @@ -306,8 +253,8 @@ function HumanMechanics() { loadCount: 1, assemblyCount: 1, assemblyCondition: { - conditionType: 'material', - materialType: "Default material" + conditionType: "material", + materialType: "Default material", }, manufactureCount: 1, loadCapacity: 1, @@ -318,15 +265,10 @@ function HumanMechanics() { const updatedActions = [...(selectedPointData.actions || []), newAction]; const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = addAction( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint, - newAction - ); + const event = addAction(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint, newAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData(updatedPoint); @@ -336,16 +278,13 @@ function HumanMechanics() { const handleDeleteAction = (actionUuid: string) => { if (!selectedPointData || !actionUuid) return; - const updatedActions = selectedPointData.actions.filter(action => action.actionUuid !== actionUuid); + const updatedActions = selectedPointData.actions.filter((action) => action.actionUuid !== actionUuid); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = removeAction( - selectedProduct.productUuid, - actionUuid - ); + const event = removeAction(selectedProduct.productUuid, actionUuid); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData(updatedPoint); @@ -369,27 +308,12 @@ function HumanMechanics() {
- { }} - onChange={handleSpeedChange} - /> + {}} onChange={handleSpeedChange} />
- + {selectedAction.actionId && currentAction && (
@@ -397,15 +321,9 @@ function HumanMechanics() {
- +
- {(currentAction.actionType === 'worker' || currentAction.actionType === "operator") && + {(currentAction.actionType === "worker" || currentAction.actionType === "operator") && ( - } - {currentAction.actionType === 'manufacturer' && + )} + {currentAction.actionType === "manufacturer" && ( - } + )}
@@ -461,4 +379,4 @@ function HumanMechanics() { ); } -export default HumanMechanics; \ No newline at end of file +export default HumanMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx index 60a8f95..43c4f6f 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/machineMechanics.tsx @@ -6,7 +6,6 @@ import { useSelectedAction, useSelectedEventData } from "../../../../../../store import ProcessAction from "../actions/ProcessAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -19,20 +18,14 @@ function MachineMechanics() { const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, updateAction } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, updateAction, selectedProduct } = productStore(); const { setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { if (selectedEventData) { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData?.data.modelUuid, - selectedEventData?.selectedPoint - ) as MachinePointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData?.data.modelUuid, selectedEventData?.selectedPoint) as MachinePointSchema | undefined; if (point && "action" in point) { setSelectedPointData(point); @@ -47,12 +40,7 @@ function MachineMechanics() { } }, [selectedProduct, selectedEventData]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -68,19 +56,10 @@ function MachineMechanics() { const validOption = option as "process"; setActiveOption(validOption); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { actionType: validOption } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { actionType: validOption }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -88,19 +67,10 @@ function MachineMechanics() { if (!selectedPointData) return; setActionName(newName); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { actionName: newName } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { actionName: newName }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -111,19 +81,10 @@ function MachineMechanics() { if (isNaN(numericValue)) return; setProcessTime(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { processTime: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { processTime: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -131,19 +92,10 @@ function MachineMechanics() { if (!selectedPointData) return; setMaterial(selectedMaterial); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { swapMaterial: selectedMaterial } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { swapMaterial: selectedMaterial }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -158,34 +110,16 @@ function MachineMechanics() {
- +
- - {activeOption === "process" && ( - - )} + + {activeOption === "process" && }
- +
)} @@ -193,4 +127,4 @@ function MachineMechanics() { ); } -export default MachineMechanics; \ No newline at end of file +export default MachineMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx index 110af2d..24fd497 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/roboticArmMechanics.tsx @@ -8,7 +8,6 @@ import { useSelectedEventData, useSelectedAction } from "../../../../../../store import PickAndPlaceAction from "../actions/PickAndPlaceAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -19,29 +18,18 @@ function RoboticArmMechanics() { const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction, selectedProduct } = productStore(); const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { - if (selectedEventData && selectedEventData.data.type === 'roboticArm') { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as RoboticArmPointSchema | undefined; + if (selectedEventData && selectedEventData.data.type === "roboticArm") { + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as RoboticArmPointSchema | undefined; if (point?.actions) { setSelectedPointData(point); - setSpeed( - (getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid - ) as RoboticArmEventSchema | undefined)?.speed?.toString() || "0.5" - ); + setSpeed((getEventByModelUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid) as RoboticArmEventSchema | undefined)?.speed?.toString() || "0.5"); if (point.actions.length > 0) { const firstAction = point.actions[0]; @@ -54,12 +42,7 @@ function RoboticArmMechanics() { } }, [selectedEventData, selectedProduct]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -76,43 +59,25 @@ function RoboticArmMechanics() { if (isNaN(numericValue)) return; setSpeed(value); - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - { speed: numericValue } - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, { speed: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; const handleClearPoints = () => { if (!selectedAction.actionId || !selectedPointData) return; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - { - process: { - startPoint: null, - endPoint: null, - }, - } - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, { + process: { + startPoint: null, + endPoint: null, + }, + }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -130,20 +95,10 @@ function RoboticArmMechanics() { triggers: [] as TriggerSchema[], }; - const event = addAction( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint, - newAction - ); + const event = addAction(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint, newAction); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData({ @@ -156,22 +111,14 @@ function RoboticArmMechanics() { const handleDeleteAction = (actionUuid: string) => { if (!selectedPointData) return; - const event = removeAction( - selectedProduct.productUuid, - actionUuid - ); + const event = removeAction(selectedProduct.productUuid, actionUuid); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } - const index = selectedPointData.actions.findIndex(a => a.actionUuid === actionUuid); - const newActions = selectedPointData.actions.filter(a => a.actionUuid !== actionUuid); + const index = selectedPointData.actions.findIndex((a) => a.actionUuid === actionUuid); + const newActions = selectedPointData.actions.filter((a) => a.actionUuid !== actionUuid); setSelectedPointData({ ...selectedPointData, @@ -193,57 +140,31 @@ function RoboticArmMechanics() { options: ["pickAndPlace"], }; - const currentAction = selectedPointData?.actions.find(a => a.actionUuid === selectedAction.actionId); + const currentAction = selectedPointData?.actions.find((a) => a.actionUuid === selectedAction.actionId); return ( <>
- { }} - onChange={handleSpeedChange} - /> + {}} onChange={handleSpeedChange} />
- + {selectedAction.actionId && currentAction && (
- +
- { }} - disabled={true} - /> + {}} disabled={true} />
- +
)} @@ -252,4 +173,4 @@ function RoboticArmMechanics() { ); } -export default RoboticArmMechanics; \ No newline at end of file +export default RoboticArmMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx index c0ad4d8..460438a 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/storageMechanics.tsx @@ -7,7 +7,6 @@ import StorageAction from "../actions/StorageAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; import { useSelectedAction, useSelectedEventData } from "../../../../../../store/simulation/useSimulationStore"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; @@ -19,29 +18,20 @@ function StorageMechanics() { const [selectedPointData, setSelectedPointData] = useState(); const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid, getActionByUuid, addAction, removeAction } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, updateAction, updateEvent, getEventByModelUuid, getActionByUuid, addAction, removeAction, selectedProduct } = productStore(); const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); useEffect(() => { if (selectedEventData && selectedEventData.data.type === "storageUnit") { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as StoragePointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as StoragePointSchema | undefined; if (point?.actions?.length) { setSelectedPointData(point); const firstAction = point.actions[0]; - const eventData = getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid - ) as StorageEventSchema | undefined; + const eventData = getEventByModelUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid) as StorageEventSchema | undefined; setCurrentCapacity(eventData?.storageCapacity?.toString() || "1"); setSpawnedCount(eventData?.storageCount?.toString() || "0"); @@ -56,17 +46,13 @@ function StorageMechanics() { useEffect(() => { if (selectedEventData && selectedEventData.data.type === "storageUnit" && selectedAction.actionId) { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as StoragePointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as StoragePointSchema | undefined; - const actionUuid = selectedAction.actionId || point?.actions[0].actionUuid || ''; + const actionUuid = selectedAction.actionId || point?.actions[0].actionUuid || ""; const newCurrentAction = getActionByUuid(selectedProduct.productUuid, actionUuid); - if (newCurrentAction && (newCurrentAction.actionType === 'store' || newCurrentAction.actionType === 'retrieve')) { + if (newCurrentAction && (newCurrentAction.actionType === "store" || newCurrentAction.actionType === "retrieve")) { if (!selectedAction.actionId) { setSelectedAction(newCurrentAction.actionUuid, newCurrentAction.actionName); } @@ -78,20 +64,15 @@ function StorageMechanics() { } }, [selectedAction, selectedProduct, selectedEventData]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName: productName, productUuid: productUuid, projectId: projectId, eventDatas: eventData, - versionId: selectedVersion?.versionId || '', - }) - } + versionId: selectedVersion?.versionId || "", + }); + }; const handleActionTypeChange = (option: string) => { if (!selectedAction.actionId || !selectedPointData) return; @@ -99,31 +80,24 @@ function StorageMechanics() { const internalOption = option === "spawn" ? "retrieve" : "store"; const updatedAction = { - actionType: internalOption as "store" | "retrieve" + actionType: internalOption as "store" | "retrieve", }; - const updatedActions = selectedPointData.actions.map(action => - action.actionUuid === selectedAction.actionId ? { - ...action, - actionType: updatedAction.actionType - } : action + const updatedActions = selectedPointData.actions.map((action) => + action.actionUuid === selectedAction.actionId + ? { + ...action, + actionType: updatedAction.actionType, + } + : action ); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = updateAction( - selectedProduct.productUuid, - selectedAction.actionId, - updatedAction - ); + const event = updateAction(selectedProduct.productUuid, selectedAction.actionId, updatedAction); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData(updatedPoint); @@ -137,7 +111,7 @@ function StorageMechanics() { if (isNaN(numericValue)) return; const updatedEvent = { - storageCapacity: numericValue + storageCapacity: numericValue, } as StorageEventSchema; const currentCount = parseInt(spawnedCount); @@ -146,19 +120,10 @@ function StorageMechanics() { setSpawnedCount(numericValue.toString()); } - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - updatedEvent - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, updatedEvent); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setCurrentCapacity(value); @@ -174,22 +139,13 @@ function StorageMechanics() { if (numericValue > maxCapacity) return; const updatedEvent = { - storageCount: numericValue + storageCount: numericValue, } as StorageEventSchema; - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - updatedEvent - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, updatedEvent); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSpawnedCount(value); @@ -199,22 +155,13 @@ function StorageMechanics() { if (!selectedEventData) return; const updatedEvent = { - materialType: value + materialType: value, } as StorageEventSchema; - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - updatedEvent - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, updatedEvent); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSpawnedMaterial(value); @@ -233,15 +180,10 @@ function StorageMechanics() { const updatedActions = [...(selectedPointData.actions || []), newAction]; const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = addAction( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint, - newAction - ); + const event = addAction(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint, newAction); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData(updatedPoint); @@ -251,16 +193,13 @@ function StorageMechanics() { const handleDeleteAction = (actionUuid: string) => { if (!selectedPointData || !actionUuid) return; - const updatedActions = selectedPointData.actions.filter(action => action.actionUuid !== actionUuid); + const updatedActions = selectedPointData.actions.filter((action) => action.actionUuid !== actionUuid); const updatedPoint = { ...selectedPointData, actions: updatedActions }; - const event = removeAction( - selectedProduct.productUuid, - actionUuid - ); + const event = removeAction(selectedProduct.productUuid, actionUuid); if (event) { - updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || '', event); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } setSelectedPointData(updatedPoint); @@ -279,45 +218,21 @@ function StorageMechanics() { {selectedEventData && selectedEventData.data.type === "storageUnit" && ( <>
- +
- + {selectedAction.actionId && (
- +
- +
- +
)} @@ -328,4 +243,4 @@ function StorageMechanics() { ); } -export default StorageMechanics; \ No newline at end of file +export default StorageMechanics; diff --git a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx index b10e4b1..732f8e7 100644 --- a/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx +++ b/app/src/components/layout/sidebarRight/properties/eventProperties/mechanics/vehicleMechanics.tsx @@ -7,7 +7,6 @@ import { useSelectedAction, useSelectedEventData } from "../../../../../../store import TravelAction from "../actions/TravelAction"; import ActionsList from "../components/ActionsList"; import { upsertProductOrEventApi } from "../../../../../../services/simulation/products/UpsertProductOrEventApi"; -import { useProductContext } from "../../../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../../../modules/scene/sceneContext"; import { useSelectedPath } from "../../../../../../store/builder/store"; @@ -22,9 +21,7 @@ function VehicleMechanics() { const { selectedEventData } = useSelectedEventData(); const { productStore, versionStore } = useSceneContext(); - const { getPointByUuid, updateEvent, updateAction, getEventByModelUuid } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct } = selectedProductStore(); + const { getPointByUuid, updateEvent, updateAction, getEventByModelUuid, selectedProduct } = productStore(); const { setSelectedAction, clearSelectedAction } = useSelectedAction(); const { selectedVersion } = versionStore(); const { projectId } = useParams(); @@ -32,22 +29,13 @@ function VehicleMechanics() { useEffect(() => { if (selectedEventData && selectedEventData.data.type === "vehicle") { - const point = getPointByUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - selectedEventData.selectedPoint - ) as VehiclePointSchema | undefined; + const point = getPointByUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid, selectedEventData.selectedPoint) as VehiclePointSchema | undefined; if (point) { setSelectedPointData(point); setActiveOption(point.action.actionType as "travel"); setActionName(point.action.actionName); - setSpeed( - (getEventByModelUuid( - selectedProduct.productUuid, - selectedEventData.data.modelUuid - ) as VehicleEventSchema | undefined)?.speed?.toString() || "0.5" - ); + setSpeed((getEventByModelUuid(selectedProduct.productUuid, selectedEventData.data.modelUuid) as VehicleEventSchema | undefined)?.speed?.toString() || "0.5"); setLoadCapacity(point.action.loadCapacity?.toString() || "1"); setUnloadDuration(point.action.unLoadDuration?.toString() || "1"); setSelectedAction(point.action.actionUuid, point.action.actionName); @@ -57,12 +45,7 @@ function VehicleMechanics() { } }, [selectedProduct, selectedEventData]); - const updateBackend = ( - productName: string, - productUuid: string, - projectId: string, - eventData: EventsSchema - ) => { + const updateBackend = (productName: string, productUuid: string, projectId: string, eventData: EventsSchema) => { upsertProductOrEventApi({ productName, productUuid, @@ -79,19 +62,10 @@ function VehicleMechanics() { if (isNaN(numericValue)) return; setSpeed(value); - const event = updateEvent( - selectedProduct.productUuid, - selectedEventData.data.modelUuid, - { speed: numericValue } - ); + const event = updateEvent(selectedProduct.productUuid, selectedEventData.data.modelUuid, { speed: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -101,19 +75,10 @@ function VehicleMechanics() { const validOption = option as "travel"; setActiveOption(validOption); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { actionType: validOption } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { actionType: validOption }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -124,19 +89,10 @@ function VehicleMechanics() { if (isNaN(numericValue)) return; setLoadCapacity(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { loadCapacity: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { loadCapacity: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -147,42 +103,24 @@ function VehicleMechanics() { if (isNaN(numericValue)) return; setUnloadDuration(value); - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { unLoadDuration: numericValue } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { unLoadDuration: numericValue }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; const handleClearPoints = () => { if (!selectedPointData) return; - const event = updateAction( - selectedProduct.productUuid, - selectedPointData.action.actionUuid, - { - pickUpPoint: null, - unLoadPoint: null, - steeringAngle: 0, - } - ); + const event = updateAction(selectedProduct.productUuid, selectedPointData.action.actionUuid, { + pickUpPoint: null, + unLoadPoint: null, + steeringAngle: 0, + }); if (event) { - updateBackend( - selectedProduct.productName, - selectedProduct.productUuid, - projectId || '', - event - ); + updateBackend(selectedProduct.productName, selectedProduct.productUuid, projectId || "", event); } }; @@ -198,17 +136,7 @@ function VehicleMechanics() {
- { }} - onChange={handleSpeedChange} - /> + {}} onChange={handleSpeedChange} />
@@ -216,17 +144,10 @@ function VehicleMechanics() {
- +
- + {activeOption === "travel" && (
- +
-
+
-
+
{triggers.map((trigger) => ( -
setSelectedTrigger(trigger)} - > +
setSelectedTrigger(trigger)}>
))}
-
@@ -410,16 +307,8 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => { /> `Point ${option.uuid.slice(0, 4)}` - ), - ]} + defaultOption={triggeredPoint?.uuid ? `Point ${triggeredPoint?.uuid.slice(0, 4)}` : ""} + options={[...pointOptions.map((option) => `Point ${option.uuid.slice(0, 4)}`)]} onSelect={(option) => { handlePointSelect(option, selectedTrigger.triggerUuid); }} @@ -427,9 +316,7 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => { option.actionName), - ]} + options={[...actionOptions.map((option: any) => option.actionName)]} onSelect={(option) => { handleActionSelect(option, selectedTrigger.triggerUuid); }} diff --git a/app/src/components/layout/sidebarRight/simulation/Simulations.tsx b/app/src/components/layout/sidebarRight/simulation/Simulations.tsx index f6eb49b..ac33667 100644 --- a/app/src/components/layout/sidebarRight/simulation/Simulations.tsx +++ b/app/src/components/layout/sidebarRight/simulation/Simulations.tsx @@ -1,5 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; -import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon, } from "../../../icons/ExportCommonIcons"; +import { AddIcon, ArrowIcon, RemoveIcon, ResizeHeightIcon } from "../../../icons/ExportCommonIcons"; import RenameInput from "../../../ui/inputs/RenameInput"; import { handleResize } from "../../../../functions/handleResizePannel"; import { useMainProduct, useSelectedAsset } from "../../../../store/simulation/useSimulationStore"; @@ -13,9 +13,8 @@ import { deleteProductApi } from "../../../../services/simulation/products/delet import { renameProductApi } from "../../../../services/simulation/products/renameProductApi"; import { determineExecutionMachineSequences } from "../../../../modules/simulation/simulator/functions/determineExecutionMachineSequences"; import ComparePopUp from "../../../ui/compareVersion/Compare"; -import { useCompareStore, useSaveVersion, } from "../../../../store/builder/store"; +import { useCompareStore, useSaveVersion } from "../../../../store/builder/store"; import { useToggleStore } from "../../../../store/ui/useUIToggleStore"; -import { useProductContext } from "../../../../modules/simulation/products/productContext"; import { useParams } from "react-router-dom"; import { useSceneContext } from "../../../../modules/scene/sceneContext"; @@ -39,9 +38,7 @@ const List: React.FC = ({ val }) => { const Simulations: React.FC = () => { const productsContainerRef = useRef(null); const { eventStore, productStore, versionStore } = useSceneContext(); - const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById, } = productStore(); - const { selectedProductStore } = useProductContext(); - const { selectedProduct, setSelectedProduct } = selectedProductStore(); + const { products, addProduct, removeProduct, renameProduct, addEvent, removeEvent, getProductById, selectedProduct, setSelectedProduct } = productStore(); const { getEventByModelUuid } = eventStore(); const { selectedAsset, clearSelectedAsset } = useSelectedAsset(); const [openObjects, setOpenObjects] = useState(true); @@ -67,7 +64,7 @@ const Simulations: React.FC = () => { productName: name, productUuid: id, projectId: projectId, - versionId: selectedVersion?.versionId || '', + versionId: selectedVersion?.versionId || "", }); }; @@ -83,14 +80,8 @@ const Simulations: React.FC = () => { if (currentIndex >= updatedProducts.length) { newSelectedIndex = updatedProducts.length - 1; } - setSelectedProduct( - updatedProducts[newSelectedIndex].productUuid, - updatedProducts[newSelectedIndex].productName - ); - setMainProduct( - updatedProducts[newSelectedIndex].productUuid, - updatedProducts[newSelectedIndex].productName - ); + setSelectedProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName); + setMainProduct(updatedProducts[newSelectedIndex].productUuid, updatedProducts[newSelectedIndex].productName); } else { setSelectedProduct("", ""); setMainProduct("", ""); @@ -100,14 +91,14 @@ const Simulations: React.FC = () => { removeProduct(productUuid); deleteProductApi({ productUuid, - versionId: selectedVersion?.versionId || '', - projectId + versionId: selectedVersion?.versionId || "", + projectId, }); }; const handleRenameProduct = (productUuid: string, newName: string) => { renameProduct(productUuid, newName); - renameProductApi({ productName: newName, productUuid, projectId: projectId || '', versionId: selectedVersion?.versionId || '' }); + renameProductApi({ productName: newName, productUuid, projectId: projectId || "", versionId: selectedVersion?.versionId || "" }); if (selectedProduct.productUuid === productUuid) { setSelectedProduct(productUuid, newName); setMainProduct(productUuid, newName); @@ -116,11 +107,10 @@ const Simulations: React.FC = () => { const handleRemoveEventFromProduct = () => { if (selectedAsset) { - deleteEventDataApi({ productUuid: selectedProduct.productUuid, modelUuid: selectedAsset.modelUuid, - versionId: selectedVersion?.versionId || '', + versionId: selectedVersion?.versionId || "", projectId: projectId, }); removeEvent(selectedProduct.productUuid, selectedAsset.modelUuid); @@ -133,21 +123,18 @@ const Simulations: React.FC = () => { const selectedProductData = getProductById(selectedProduct.productUuid); if (selectedProductData) { - determineExecutionMachineSequences([selectedProductData]).then( - (sequences) => { - sequences.forEach((sequence) => { - const events: Event[] = - sequence.map((event) => ({ - modelName: event.modelName, - modelId: event.modelUuid, - })) || []; - processes.push(events); - }); - setProcesses(processes); - } - ); + determineExecutionMachineSequences([selectedProductData]).then((sequences) => { + sequences.forEach((sequence) => { + const events: Event[] = + sequence.map((event) => ({ + modelName: event.modelName, + modelId: event.modelUuid, + })) || []; + processes.push(events); + }); + setProcesses(processes); + }); } - }, [selectedProduct.productUuid, products]); return ( @@ -157,77 +144,41 @@ const Simulations: React.FC = () => {
Products
-
-
+
{products.map((product, index) => ( -
+
{/* eslint-disable-next-line */}
{ - setSelectedProduct(product.productUuid, product.productName) - setMainProduct(product.productUuid, product.productName) + setSelectedProduct(product.productUuid, product.productName); + setMainProduct(product.productUuid, product.productName); }} > - - - handleRenameProduct(product.productUuid, newName) - } - /> + + handleRenameProduct(product.productUuid, newName)} />
{products.length > 1 && ( - )}
))}
-
-