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 ArmBotUI = () => {
|
||||||
const { getEventByModelUuid, updateAction } = useProductStore();
|
const { getEventByModelUuid, updateAction, getActionByUuid } = useProductStore();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { armBots } = useArmBotStore();
|
const { armBots } = useArmBotStore();
|
||||||
|
@ -58,15 +58,14 @@ const ArmBotUI = () => {
|
||||||
if (selectedArmBot?.type === "roboticArm") {
|
if (selectedArmBot?.type === "roboticArm") {
|
||||||
setSelectedArmBotData(selectedArmBot);
|
setSelectedArmBotData(selectedArmBot);
|
||||||
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
const defaultPositions = getDefaultPositions(selectedArmBot.modelUuid);
|
||||||
const matchingAction = armBots?.flatMap((robot: ArmBotStatus) => robot.point.actions)
|
const matchingAction = getActionByUuid(selectedProduct.productId, selectedAction.actionId);
|
||||||
.find((action) => action.actionUuid === selectedAction.actionId);
|
|
||||||
if (matchingAction) {
|
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)))
|
const pickPosition = (!startPoint || (Array.isArray(startPoint) && startPoint.every(v => v === 0)))
|
||||||
? defaultPositions.pick
|
? defaultPositions.pick
|
||||||
: startPoint;
|
: 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)))
|
const dropPosition = (!endPoint || (Array.isArray(endPoint) && endPoint.every(v => v === 0)))
|
||||||
? defaultPositions.drop
|
? defaultPositions.drop
|
||||||
: endPoint;
|
: endPoint;
|
||||||
|
@ -76,7 +75,7 @@ const ArmBotUI = () => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction, armBots]);
|
}, [selectedEventData, selectedProduct, getEventByModelUuid, selectedAction]);
|
||||||
|
|
||||||
|
|
||||||
function getDefaultPositions(modelUuid: string): Positions {
|
function getDefaultPositions(modelUuid: string): Positions {
|
||||||
|
|
Loading…
Reference in New Issue