Refactor ArmBotUI: enhance action retrieval by using getActionByUuid; streamline state updates by removing unnecessary dependencies in useEffect.
This commit is contained in:
parent
d29c4ce48a
commit
03fcc62238
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue