Refactor multiple components: streamline action handling in ActionsList, RoboticArmMechanics, and Trigger; update vehicle and robotic arm data management in Products and Vehicles; unify action naming in loadInitialFloorItems, copyPasteControls, and duplicationControls; enhance ArmBotUI with selected event sphere integration.
This commit is contained in:
@@ -36,7 +36,7 @@ const ActionsList: React.FC<ActionsListProps> = ({
|
||||
const handleRenameAction = (newName: string) => {
|
||||
if (!selectedAction.actionId) return;
|
||||
const event = renameAction(selectedProduct.productId, selectedAction.actionId, newName);
|
||||
|
||||
setSelectedAction(selectedAction.actionId, newName);
|
||||
if (event) {
|
||||
upsertProductOrEventApi({
|
||||
productName: selectedProduct.productName,
|
||||
|
||||
@@ -14,7 +14,7 @@ function RoboticArmMechanics() {
|
||||
const [activeOption, setActiveOption] = useState<"default" | "pickAndPlace">("default");
|
||||
const [selectedPointData, setSelectedPointData] = useState<RoboticArmPointSchema | undefined>();
|
||||
const { selectedEventData } = useSelectedEventData();
|
||||
const { getPointByUuid, getEventByModelUuid, updateEvent, updateAction, addAction, removeAction } = useProductStore();
|
||||
const { getPointByUuid, getEventByModelUuid, getActionByUuid, updateEvent, updateAction, addAction, removeAction } = useProductStore();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { selectedAction, setSelectedAction, clearSelectedAction } = useSelectedAction();
|
||||
|
||||
@@ -28,20 +28,28 @@ function RoboticArmMechanics() {
|
||||
selectedEventData.data.modelUuid,
|
||||
selectedEventData.selectedPoint
|
||||
) as RoboticArmPointSchema | undefined;
|
||||
if (point?.actions) {
|
||||
setSelectedPointData(point);
|
||||
setActiveOption(point.actions[0].actionType as "default" | "pickAndPlace");
|
||||
if (point.actions.length > 0 && !selectedAction.actionId) {
|
||||
setSelectedAction(
|
||||
point.actions[0].actionUuid,
|
||||
point.actions[0].actionName
|
||||
);
|
||||
const action = getActionByUuid(selectedProduct.productId, selectedAction.actionId) as RoboticArmPointSchema["actions"][0] | undefined;
|
||||
if (action) {
|
||||
if (point?.actions) {
|
||||
setSelectedPointData(point);
|
||||
if (point.actions.length > 0 && action) {
|
||||
setActiveOption(action.actionType as "default" | "pickAndPlace");
|
||||
setSelectedAction(selectedAction.actionId, selectedAction.actionName);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (point?.actions) {
|
||||
setSelectedPointData(point);
|
||||
if (point.actions.length > 0) {
|
||||
setActiveOption(point.actions[0].actionType as "default" | "pickAndPlace");
|
||||
setSelectedAction(point.actions[0].actionUuid, point.actions[0].actionName);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
clearSelectedAction();
|
||||
}
|
||||
}, [clearSelectedAction, getPointByUuid, selectedAction.actionId, selectedEventData, selectedProduct, setSelectedAction,]);
|
||||
}, [selectedAction, selectedEventData, selectedProduct]);
|
||||
|
||||
const updateBackend = (
|
||||
productName: string,
|
||||
@@ -280,7 +288,7 @@ function RoboticArmMechanics() {
|
||||
/>
|
||||
</div>
|
||||
<div className="tirgger">
|
||||
<Trigger selectedPointData={selectedPointData as any} type= {'RoboticArm'} />
|
||||
<Trigger selectedPointData={selectedPointData as any} type={'RoboticArm'} />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -20,7 +20,7 @@ type TriggerProps = {
|
||||
const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||
const [currentAction, setCurrentAction] = useState<string | undefined>();
|
||||
const { selectedProduct } = useSelectedProduct();
|
||||
const { getActionByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById } = useProductStore();
|
||||
const { getActionByUuid, getEventByModelUuid, getPointByUuid, addTrigger, removeTrigger, updateTrigger, renameTrigger, getProductById } = useProductStore();
|
||||
const [triggers, setTriggers] = useState<TriggerSchema[]>([]);
|
||||
const [selectedTrigger, setSelectedTrigger] = useState<TriggerSchema | undefined>();
|
||||
const [activeOption, setActiveOption] = useState<"onComplete" | "onStart" | "onStop" | "delay" | "onError">("onComplete");
|
||||
@@ -107,14 +107,14 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||
});
|
||||
};
|
||||
|
||||
const triggeredModel = selectedTrigger?.triggeredAsset?.triggeredModel || { modelName: "Select Model", modelUuid: "" };
|
||||
const triggeredPoint = selectedTrigger?.triggeredAsset?.triggeredPoint || { pointName: "Select Point", pointUuid: "" };
|
||||
const triggeredAction = selectedTrigger?.triggeredAsset?.triggeredAction || { actionName: "Select Action", actionUuid: "" };
|
||||
const triggeredModel = getEventByModelUuid(selectedProduct.productId, selectedTrigger?.triggeredAsset?.triggeredModel?.modelUuid || "");
|
||||
const triggeredPoint = getPointByUuid(selectedProduct.productId, triggeredModel?.modelUuid || '', selectedTrigger?.triggeredAsset?.triggeredPoint?.pointUuid || "");
|
||||
const triggeredAction = getActionByUuid(selectedProduct.productId, selectedTrigger?.triggeredAsset?.triggeredAction?.actionUuid || '');
|
||||
|
||||
const modelOptions = getProductById(selectedProduct.productId)?.eventDatas || [];
|
||||
|
||||
const pointOptions: PointsScheme[] = useMemo(() => {
|
||||
if (!triggeredModel.modelUuid) return [];
|
||||
if (!triggeredModel) return [];
|
||||
|
||||
const model = modelOptions.find(m => m.modelUuid === triggeredModel.modelUuid);
|
||||
if (!model) return [];
|
||||
@@ -125,11 +125,11 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||
return [(model as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point];
|
||||
}
|
||||
return [];
|
||||
}, [triggeredModel.modelUuid, modelOptions]);
|
||||
}, [triggeredModel, modelOptions]);
|
||||
|
||||
const actionOptions: any = useMemo(() => {
|
||||
if (!triggeredPoint.pointUuid) return [];
|
||||
const point = pointOptions.find((p) => p.uuid === triggeredPoint.pointUuid);
|
||||
if (!triggeredPoint) return [];
|
||||
const point = pointOptions.find((p) => p.uuid === triggeredPoint.uuid);
|
||||
if (!point) return [];
|
||||
|
||||
if ('action' in point) {
|
||||
@@ -140,7 +140,7 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||
return typedPoint.actions;
|
||||
}
|
||||
return [];
|
||||
}, [triggeredPoint.pointUuid, pointOptions]);
|
||||
}, [triggeredPoint, pointOptions]);
|
||||
|
||||
const handleModelSelect = (option: string, triggerUuid: string) => {
|
||||
if (!selectedProduct) return;
|
||||
@@ -296,19 +296,19 @@ const Trigger = ({ selectedPointData, type }: TriggerProps) => {
|
||||
<div className="trigger-options">
|
||||
<LabledDropdown
|
||||
label="Triggered Object"
|
||||
defaultOption={triggeredModel.modelName}
|
||||
defaultOption={triggeredModel?.modelName || ""}
|
||||
options={[...modelOptions.map((option) => (option.modelName))]}
|
||||
onSelect={(option) => { handleModelSelect(option, selectedTrigger.triggerUuid) }}
|
||||
/>
|
||||
<LabledDropdown
|
||||
label="Triggered Point"
|
||||
defaultOption={triggeredPoint.pointName}
|
||||
options={[...pointOptions.map((option) => (`Point ${option.uuid.slice(0, 5)}`))]}
|
||||
defaultOption={`Point ${triggeredPoint?.uuid.slice(0, 4)}`}
|
||||
options={[...pointOptions.map((option) => (`Point ${option.uuid.slice(0, 4)}`))]}
|
||||
onSelect={(option) => { handlePointSelect(option, selectedTrigger.triggerUuid) }}
|
||||
/>
|
||||
<LabledDropdown
|
||||
label="Triggered Action"
|
||||
defaultOption={triggeredAction.actionName}
|
||||
defaultOption={triggeredAction?.actionName || ''}
|
||||
options={[...actionOptions.map((option: any) => (option.actionName))]}
|
||||
onSelect={(option) => { handleActionSelect(option, selectedTrigger.triggerUuid) }}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user