From 03fcc6223890786f255a9a3db6a734333c7b1284 Mon Sep 17 00:00:00 2001 From: Jerald-Golden-B Date: Sat, 3 May 2025 10:39:12 +0530 Subject: [PATCH] Refactor ArmBotUI: enhance action retrieval by using getActionByUuid; streamline state updates by removing unnecessary dependencies in useEffect. --- app/src/modules/simulation/ui/arm/armBotUI.tsx | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/app/src/modules/simulation/ui/arm/armBotUI.tsx b/app/src/modules/simulation/ui/arm/armBotUI.tsx index 01e631e..2d83147 100644 --- a/app/src/modules/simulation/ui/arm/armBotUI.tsx +++ b/app/src/modules/simulation/ui/arm/armBotUI.tsx @@ -19,7 +19,7 @@ type Positions = { }; const ArmBotUI = () => { - const { getEventByModelUuid, updateAction } = useProductStore(); + const { getEventByModelUuid, updateAction, getActionByUuid } = useProductStore(); const { selectedEventData } = useSelectedEventData(); const { selectedProduct } = useSelectedProduct(); const { armBots } = useArmBotStore(); @@ -58,15 +58,14 @@ const ArmBotUI = () => { if (selectedArmBot?.type === "roboticArm") { setSelectedArmBotData(selectedArmBot); const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid); - const matchingAction = armBots?.flatMap((robot: ArmBotStatus) => robot.point.actions) - .find((action) => action.actionUuid === selectedAction.actionId); + const matchingAction = getActionByUuid(selectedProduct.productId, selectedAction.actionId); if (matchingAction) { - const startPoint = matchingAction.process.startPoint; + const startPoint = (matchingAction as RoboticArmPointSchema["actions"][0]).process.startPoint; const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0))) ? defaultPositions.pick : startPoint; - const endPoint = matchingAction.process.endPoint; + const endPoint = (matchingAction as RoboticArmPointSchema["actions"][0]).process.endPoint; const dropPosition = (!endPoint || (Array.isArray(endPoint) && endPoint.every(v => v === 0))) ? defaultPositions.drop : endPoint; @@ -76,7 +75,7 @@ const ArmBotUI = () => { } } } - }, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction, armBots]); + }, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction]); function getDefaultPositions(modelUuid: string): Positions {