Refactor action updates to include productId in updateAction calls across mechanics components; enhance event handling in product store and trigger management. Add clear functions for various stores to reset state. Update action and trigger management to prevent duplicates and ensure integrity. Adjust initial load actions to use consistent naming conventions.
This commit is contained in:
parent
34c30bb5a2
commit
01a03f5166
|
@ -35,7 +35,7 @@ const ActionsList: React.FC<ActionsListProps> = ({
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedAction.actionId) return;
|
if (!selectedAction.actionId) return;
|
||||||
const event = renameAction(selectedAction.actionId, newName);
|
const event = renameAction(selectedProduct.productId, selectedAction.actionId, newName);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
upsertProductOrEventApi({
|
upsertProductOrEventApi({
|
||||||
|
|
|
@ -72,7 +72,7 @@ function ConveyorMechanics() {
|
||||||
const validOption = option as | "default" | "spawn" | "swap" | "delay" | "despawn";
|
const validOption = option as | "default" | "spawn" | "swap" | "delay" | "despawn";
|
||||||
setActiveOption(validOption);
|
setActiveOption(validOption);
|
||||||
|
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
actionType: validOption,
|
actionType: validOption,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ function ConveyorMechanics() {
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, { actionName: newName });
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, { actionName: newName });
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
@ -102,7 +102,7 @@ function ConveyorMechanics() {
|
||||||
|
|
||||||
const handleSpawnCountChange = (value: string) => {
|
const handleSpawnCountChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
spawnCount: value === "inherit" ? "inherit" : parseFloat(value),
|
spawnCount: value === "inherit" ? "inherit" : parseFloat(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function ConveyorMechanics() {
|
||||||
|
|
||||||
const handleSpawnIntervalChange = (value: string) => {
|
const handleSpawnIntervalChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
spawnInterval: value === "inherit" ? "inherit" : parseFloat(value),
|
spawnInterval: value === "inherit" ? "inherit" : parseFloat(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ function ConveyorMechanics() {
|
||||||
|
|
||||||
const handleMaterialSelect = (material: string) => {
|
const handleMaterialSelect = (material: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, { material });
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, { material });
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
@ -148,7 +148,7 @@ function ConveyorMechanics() {
|
||||||
|
|
||||||
const handleDelayChange = (value: string) => {
|
const handleDelayChange = (value: string) => {
|
||||||
if (!selectedEventData || !selectedPointData) return;
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
delay: value === "inherit" ? "inherit" : parseFloat(value),
|
delay: value === "inherit" ? "inherit" : parseFloat(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -51,7 +51,7 @@ function MachineMechanics() {
|
||||||
const validOption = option as "process";
|
const validOption = option as "process";
|
||||||
setActiveOption(validOption);
|
setActiveOption(validOption);
|
||||||
|
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
actionType: validOption,
|
actionType: validOption,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,19 +67,19 @@ function MachineMechanics() {
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, { actionName: newName });
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, { actionName: newName });
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleProcessTimeChange = (value: string) => {
|
const handleProcessTimeChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
processTime: parseFloat(value),
|
processTime: parseFloat(value),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleMaterialSelect = (material: string) => {
|
const handleMaterialSelect = (material: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
swapMaterial: material,
|
swapMaterial: material,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -59,7 +59,7 @@ function RoboticArmMechanics() {
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedAction.actionId) return;
|
if (!selectedAction.actionId) return;
|
||||||
const event = updateAction(selectedAction.actionId, { actionName: newName });
|
const event = updateAction(selectedProduct.productId, selectedAction.actionId, { actionName: newName });
|
||||||
|
|
||||||
if (selectedPointData) {
|
if (selectedPointData) {
|
||||||
const updatedActions = selectedPointData.actions.map((action) =>
|
const updatedActions = selectedPointData.actions.map((action) =>
|
||||||
|
@ -101,7 +101,7 @@ function RoboticArmMechanics() {
|
||||||
if (!selectedAction.actionId || !selectedPointData) return;
|
if (!selectedAction.actionId || !selectedPointData) return;
|
||||||
const [x, y, z] = value.split(",").map(Number);
|
const [x, y, z] = value.split(",").map(Number);
|
||||||
|
|
||||||
const event = updateAction(selectedAction.actionId, {
|
const event = updateAction(selectedProduct.productId, selectedAction.actionId, {
|
||||||
process: {
|
process: {
|
||||||
startPoint: [x, y, z] as [number, number, number],
|
startPoint: [x, y, z] as [number, number, number],
|
||||||
endPoint: selectedPointData.actions.find((a) => a.actionUuid === selectedAction.actionId)?.process.endPoint || null,
|
endPoint: selectedPointData.actions.find((a) => a.actionUuid === selectedAction.actionId)?.process.endPoint || null,
|
||||||
|
@ -122,7 +122,7 @@ function RoboticArmMechanics() {
|
||||||
if (!selectedAction.actionId || !selectedPointData) return;
|
if (!selectedAction.actionId || !selectedPointData) return;
|
||||||
const [x, y, z] = value.split(",").map(Number);
|
const [x, y, z] = value.split(",").map(Number);
|
||||||
|
|
||||||
const event = updateAction(selectedAction.actionId, {
|
const event = updateAction(selectedProduct.productId, selectedAction.actionId, {
|
||||||
process: {
|
process: {
|
||||||
startPoint: selectedPointData.actions.find((a) => a.actionUuid === selectedAction.actionId)?.process.startPoint || null,
|
startPoint: selectedPointData.actions.find((a) => a.actionUuid === selectedAction.actionId)?.process.startPoint || null,
|
||||||
endPoint: [x, y, z] as [number, number, number],
|
endPoint: [x, y, z] as [number, number, number],
|
||||||
|
@ -181,7 +181,7 @@ function RoboticArmMechanics() {
|
||||||
const handleDeleteAction = (actionUuid: string) => {
|
const handleDeleteAction = (actionUuid: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
|
|
||||||
const event = removeAction(actionUuid);
|
const event = removeAction(selectedProduct.productId, actionUuid);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
|
|
@ -51,7 +51,7 @@ function StorageMechanics() {
|
||||||
const validOption = option as "store" | "spawn";
|
const validOption = option as "store" | "spawn";
|
||||||
setActiveOption(validOption);
|
setActiveOption(validOption);
|
||||||
|
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
actionType: validOption,
|
actionType: validOption,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ function StorageMechanics() {
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, { actionName: newName });
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, { actionName: newName });
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
@ -81,7 +81,7 @@ function StorageMechanics() {
|
||||||
|
|
||||||
const handleCapacityChange = (value: string) => {
|
const handleCapacityChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
storageCapacity: parseInt(value),
|
storageCapacity: parseInt(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -72,7 +72,7 @@ function VehicleMechanics() {
|
||||||
const validOption = option as "travel";
|
const validOption = option as "travel";
|
||||||
setActiveOption(validOption);
|
setActiveOption(validOption);
|
||||||
|
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
actionType: validOption,
|
actionType: validOption,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -88,7 +88,7 @@ function VehicleMechanics() {
|
||||||
|
|
||||||
const handleRenameAction = (newName: string) => {
|
const handleRenameAction = (newName: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, { actionName: newName });
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, { actionName: newName });
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
@ -102,7 +102,7 @@ function VehicleMechanics() {
|
||||||
|
|
||||||
const handleLoadCapacityChange = (value: string) => {
|
const handleLoadCapacityChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
loadCapacity: parseFloat(value),
|
loadCapacity: parseFloat(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -118,7 +118,7 @@ function VehicleMechanics() {
|
||||||
|
|
||||||
const handleUnloadDurationChange = (value: string) => {
|
const handleUnloadDurationChange = (value: string) => {
|
||||||
if (!selectedPointData) return;
|
if (!selectedPointData) return;
|
||||||
const event = updateAction(selectedPointData.action.actionUuid, {
|
const event = updateAction(selectedProduct.productId, selectedPointData.action.actionUuid, {
|
||||||
unLoadDuration: parseFloat(value),
|
unLoadDuration: parseFloat(value),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -202,7 +202,7 @@ function processLoadedModel(
|
||||||
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: "Vehicle Action",
|
actionName: "Action 1",
|
||||||
actionType: "travel",
|
actionType: "travel",
|
||||||
unLoadDuration: 5,
|
unLoadDuration: 5,
|
||||||
loadCapacity: 10,
|
loadCapacity: 10,
|
||||||
|
@ -254,7 +254,7 @@ function processLoadedModel(
|
||||||
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
rotation: [item.eventData.point?.rotation[0] || 0, item.eventData.point?.rotation[1] || 0, item.eventData.point?.rotation[2] || 0],
|
||||||
action: {
|
action: {
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: "Process Action",
|
actionName: "Action 1",
|
||||||
actionType: "process",
|
actionType: "process",
|
||||||
processTime: 10,
|
processTime: 10,
|
||||||
swapMaterial: "material-id",
|
swapMaterial: "material-id",
|
||||||
|
@ -279,7 +279,7 @@ function processLoadedModel(
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
actionUuid: THREE.MathUtils.generateUUID(),
|
actionUuid: THREE.MathUtils.generateUUID(),
|
||||||
actionName: "Pick and Place",
|
actionName: "Action 1",
|
||||||
actionType: "pickAndPlace",
|
actionType: "pickAndPlace",
|
||||||
process: {
|
process: {
|
||||||
startPoint: [0, 0, 0],
|
startPoint: [0, 0, 0],
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { upsertProductOrEventApi } from '../../../services/simulation/UpsertProd
|
||||||
import { getAllProductsApi } from '../../../services/simulation/getallProductsApi';
|
import { getAllProductsApi } from '../../../services/simulation/getallProductsApi';
|
||||||
|
|
||||||
function Products() {
|
function Products() {
|
||||||
const { products, addProduct, setProducts } = useProductStore();
|
const { addProduct, setProducts } = useProductStore();
|
||||||
const { setSelectedProduct } = useSelectedProduct();
|
const { setSelectedProduct } = useSelectedProduct();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
@ -27,9 +27,6 @@ function Products() {
|
||||||
})
|
})
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
}, [])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
|
|
|
@ -228,7 +228,7 @@ function TriggerConnector() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (firstSelectedPoint.actionUuid) {
|
if (firstSelectedPoint.actionUuid) {
|
||||||
const event = addTrigger(firstSelectedPoint.actionUuid, trigger);
|
const event = addTrigger(selectedProduct.productId, firstSelectedPoint.actionUuid, trigger);
|
||||||
|
|
||||||
if (event) {
|
if (event) {
|
||||||
updateBackend(
|
updateBackend(
|
||||||
|
@ -285,7 +285,7 @@ function TriggerConnector() {
|
||||||
};
|
};
|
||||||
|
|
||||||
if (firstSelectedPoint.actionUuid) {
|
if (firstSelectedPoint.actionUuid) {
|
||||||
addTrigger(firstSelectedPoint.actionUuid, trigger);
|
addTrigger(selectedProduct.productId, firstSelectedPoint.actionUuid, trigger);
|
||||||
}
|
}
|
||||||
setFirstSelectedPoint(null);
|
setFirstSelectedPoint(null);
|
||||||
}
|
}
|
||||||
|
@ -373,9 +373,8 @@ function TriggerConnector() {
|
||||||
|
|
||||||
const removeConnection = (connection: ConnectionLine) => {
|
const removeConnection = (connection: ConnectionLine) => {
|
||||||
if (connection.trigger.triggerUuid) {
|
if (connection.trigger.triggerUuid) {
|
||||||
const event = removeTrigger(connection.trigger.triggerUuid);
|
const event = removeTrigger(selectedProduct.productId, connection.trigger.triggerUuid);
|
||||||
if (event) {
|
if (event) {
|
||||||
console.log('event: ', event);
|
|
||||||
updateBackend(
|
updateBackend(
|
||||||
selectedProduct.productName,
|
selectedProduct.productName,
|
||||||
selectedProduct.productId,
|
selectedProduct.productId,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import React, { useEffect, useState } from "react";
|
import React, { useEffect } from "react";
|
||||||
import VehicleInstances from "./instances/vehicleInstances";
|
import VehicleInstances from "./instances/vehicleInstances";
|
||||||
import { useVehicleStore } from "../../../store/simulation/useVehicleStore";
|
import { useVehicleStore } from "../../../store/simulation/useVehicleStore";
|
||||||
import { useFloorItems } from "../../../store/store";
|
|
||||||
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
import { useSelectedEventData, useSelectedEventSphere, useSelectedProduct } from "../../../store/simulation/useSimulationStore";
|
||||||
import VehicleUI from "../ui/vehicle/vehicleUI";
|
import VehicleUI from "../ui/vehicle/vehicleUI";
|
||||||
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
import { usePlayButtonStore } from "../../../store/usePlayButtonStore";
|
||||||
|
@ -10,49 +9,38 @@ import { useProductStore } from "../../../store/simulation/useProductStore";
|
||||||
function Vehicles() {
|
function Vehicles() {
|
||||||
const { products, getProductById } = useProductStore();
|
const { products, getProductById } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
const { vehicles, addVehicle, removeVehicle } = useVehicleStore();
|
const { vehicles, addVehicle, clearvehicles } = useVehicleStore();
|
||||||
const { selectedEventSphere } = useSelectedEventSphere();
|
const { selectedEventSphere } = useSelectedEventSphere();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { floorItems } = useFloorItems();
|
|
||||||
const { isPlaying } = usePlayButtonStore();
|
const { isPlaying } = usePlayButtonStore();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedProduct.productId) {
|
if (selectedProduct.productId) {
|
||||||
const product = getProductById(selectedProduct.productId);
|
const product = getProductById(selectedProduct.productId);
|
||||||
if (product) {
|
if (product) {
|
||||||
|
clearvehicles();
|
||||||
product.eventDatas.forEach(events => {
|
product.eventDatas.forEach(events => {
|
||||||
if (events.type === 'vehicle') {
|
if (events.type === 'vehicle') {
|
||||||
removeVehicle(events.modelUuid);
|
|
||||||
addVehicle(selectedProduct.productId, events);
|
addVehicle(selectedProduct.productId, events);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedProduct]);
|
}, [selectedProduct, products]);
|
||||||
|
|
||||||
// useEffect(() => {
|
|
||||||
// vehicles.forEach(vehicle => {
|
|
||||||
// const product = getProductById(vehicle.productId);
|
|
||||||
// if (product) {
|
|
||||||
// const eventData = product.eventDatas.find(event => event.modelUuid === vehicle.modelUuid);
|
|
||||||
// if (eventData) {
|
|
||||||
// vehicle.eventData = eventData;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }, [vehicles, products]);
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
|
||||||
// console.log('vehicles: ', vehicles);
|
// console.log('vehicles: ', vehicles);
|
||||||
}, [vehicles])
|
}, [vehicles])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
||||||
<VehicleInstances />
|
<VehicleInstances />
|
||||||
|
|
||||||
{selectedEventSphere && selectedEventData?.data.type === "vehicle" && !isPlaying &&
|
{selectedEventSphere && selectedEventData?.data.type === "vehicle" && !isPlaying &&
|
||||||
< VehicleUI />
|
< VehicleUI />
|
||||||
}
|
}
|
||||||
|
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,7 @@ const RealTimeVisulization: React.FC = () => {
|
||||||
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
const { selectedZone, setSelectedZone } = useSelectedZoneStore();
|
||||||
|
|
||||||
const { setRightSelect } = useRightSelected();
|
const { setRightSelect } = useRightSelected();
|
||||||
const { editWidgetOptions, setEditWidgetOptions } =
|
const { editWidgetOptions, setEditWidgetOptions } = useEditWidgetOptionsStore();
|
||||||
useEditWidgetOptionsStore();
|
|
||||||
const { rightClickSelected, setRightClickSelected } = useRightClickSelected();
|
const { rightClickSelected, setRightClickSelected } = useRightClickSelected();
|
||||||
const [openConfirmationPopup, setOpenConfirmationPopup] = useState(false);
|
const [openConfirmationPopup, setOpenConfirmationPopup] = useState(false);
|
||||||
const { setFloatingWidget } = useFloatingWidget();
|
const { setFloatingWidget } = useFloatingWidget();
|
||||||
|
@ -76,8 +75,6 @@ const RealTimeVisulization: React.FC = () => {
|
||||||
const { setSelectedChartId } = useWidgetStore();
|
const { setSelectedChartId } = useWidgetStore();
|
||||||
const [waitingPanels, setWaitingPanels] = useState(null);
|
const [waitingPanels, setWaitingPanels] = useState(null);
|
||||||
|
|
||||||
console.log("waitingPanels: ", waitingPanels);
|
|
||||||
|
|
||||||
OuterClick({
|
OuterClick({
|
||||||
contextClassName: [
|
contextClassName: [
|
||||||
"chart-container",
|
"chart-container",
|
||||||
|
|
|
@ -10,6 +10,7 @@ interface ArmBotStore {
|
||||||
modelUuid: string,
|
modelUuid: string,
|
||||||
updates: Partial<Omit<ArmBotStatus, 'modelUuid' | 'productId'>>
|
updates: Partial<Omit<ArmBotStatus, 'modelUuid' | 'productId'>>
|
||||||
) => void;
|
) => void;
|
||||||
|
clearArmBots: () => void;
|
||||||
|
|
||||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||||
removeCurrentAction: (modelUuid: string) => void;
|
removeCurrentAction: (modelUuid: string) => void;
|
||||||
|
@ -39,6 +40,8 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||||
|
|
||||||
addArmBot: (productId, event) => {
|
addArmBot: (productId, event) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const exists = state.armBots.some(a => a.modelUuid === event.modelUuid);
|
||||||
|
if (!exists) {
|
||||||
state.armBots.push({
|
state.armBots.push({
|
||||||
...event,
|
...event,
|
||||||
productId,
|
productId,
|
||||||
|
@ -47,6 +50,7 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||||
activeTime: 0,
|
activeTime: 0,
|
||||||
state: 'idle',
|
state: 'idle',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -65,6 +69,12 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearArmBots: () => {
|
||||||
|
set((state) => {
|
||||||
|
state.armBots = [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
addCurrentAction: (modelUuid, actionUuid) => {
|
addCurrentAction: (modelUuid, actionUuid) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||||
|
|
|
@ -10,6 +10,7 @@ interface ConveyorStore {
|
||||||
modelUuid: string,
|
modelUuid: string,
|
||||||
updates: Partial<Omit<ConveyorStatus, 'modelUuid' | 'productId'>>
|
updates: Partial<Omit<ConveyorStatus, 'modelUuid' | 'productId'>>
|
||||||
) => void;
|
) => void;
|
||||||
|
clearConveyors: () => void;
|
||||||
|
|
||||||
setConveyorActive: (modelUuid: string, isActive: boolean) => void;
|
setConveyorActive: (modelUuid: string, isActive: boolean) => void;
|
||||||
setConveyorState: (modelUuid: string, newState: ConveyorStatus['state']) => void;
|
setConveyorState: (modelUuid: string, newState: ConveyorStatus['state']) => void;
|
||||||
|
@ -30,6 +31,8 @@ export const useConveyorStore = create<ConveyorStore>()(
|
||||||
|
|
||||||
addConveyor: (productId, event) => {
|
addConveyor: (productId, event) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid);
|
||||||
|
if (!exists) {
|
||||||
state.conveyors.push({
|
state.conveyors.push({
|
||||||
...event,
|
...event,
|
||||||
productId,
|
productId,
|
||||||
|
@ -38,6 +41,7 @@ export const useConveyorStore = create<ConveyorStore>()(
|
||||||
activeTime: 0,
|
activeTime: 0,
|
||||||
state: 'idle',
|
state: 'idle',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -56,6 +60,12 @@ export const useConveyorStore = create<ConveyorStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearConveyors: () => {
|
||||||
|
set((state) => {
|
||||||
|
state.conveyors = [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
setConveyorActive: (modelUuid, isActive) => {
|
setConveyorActive: (modelUuid, isActive) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
|
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
|
||||||
|
|
|
@ -49,7 +49,9 @@ export const useEventsStore = create<EventsStore>()(
|
||||||
// Event-level actions
|
// Event-level actions
|
||||||
addEvent: (event) => {
|
addEvent: (event) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
if (!state.events.some(e => 'modelUuid' in e && e.modelUuid === event.modelUuid)) {
|
||||||
state.events.push(event);
|
state.events.push(event);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -76,10 +78,15 @@ export const useEventsStore = create<EventsStore>()(
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
if (event && 'points' in event) {
|
if (event && 'points' in event) {
|
||||||
|
const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
|
||||||
|
if (!existingPoint) {
|
||||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||||
|
}
|
||||||
} else if (event && 'point' in event) {
|
} else if (event && 'point' in event) {
|
||||||
|
if (!(event as any).point || (event as any).point.uuid !== point.uuid) {
|
||||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -113,14 +120,15 @@ export const useEventsStore = create<EventsStore>()(
|
||||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
if (event && 'points' in event) {
|
if (event && 'points' in event) {
|
||||||
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
||||||
if (point) {
|
if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||||
point.action = action as any;
|
point.action = action as any;
|
||||||
}
|
}
|
||||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||||
if ('action' in (event as any).point) {
|
const point = (event as any).point;
|
||||||
(event as any).point.action = action;
|
if ('action' in point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||||
} else if ('actions' in (event as any).point) {
|
point.action = action;
|
||||||
(event as any).point.actions.push(action);
|
} else if ('actions' in point && !point.actions.some((a: any) => a.actionUuid === action.actionUuid)) {
|
||||||
|
point.actions.push(action);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -183,18 +191,22 @@ export const useEventsStore = create<EventsStore>()(
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
if (point.action && point.action.actionUuid === actionUuid) {
|
if (point.action && point.action.actionUuid === actionUuid) {
|
||||||
|
if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||||
point.action.triggers.push(trigger);
|
point.action.triggers.push(trigger);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ('point' in event) {
|
} else if ('point' in event) {
|
||||||
const point = (event as any).point;
|
const point: MachinePointSchema | VehiclePointSchema = (event as any).point;
|
||||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||||
|
if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||||
point.action.triggers.push(trigger);
|
point.action.triggers.push(trigger);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if ('actions' in point) {
|
} else if ('actions' in point) {
|
||||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
const action = (point as RoboticArmPointSchema).actions.find((a) => a.actionUuid === actionUuid);
|
||||||
if (action) {
|
if (action && !action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||||
action.triggers.push(trigger);
|
action.triggers.push(trigger);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,26 +4,23 @@ import { immer } from 'zustand/middleware/immer';
|
||||||
interface MachineStore {
|
interface MachineStore {
|
||||||
machines: MachineStatus[];
|
machines: MachineStatus[];
|
||||||
|
|
||||||
// Actions
|
|
||||||
addMachine: (productId: string, machine: MachineEventSchema) => void;
|
addMachine: (productId: string, machine: MachineEventSchema) => void;
|
||||||
removeMachine: (modelUuid: string) => void;
|
removeMachine: (modelUuid: string) => void;
|
||||||
updateMachine: (
|
updateMachine: (
|
||||||
modelUuid: string,
|
modelUuid: string,
|
||||||
updates: Partial<Omit<MachineStatus, 'modelUuid' | 'productId'>>
|
updates: Partial<Omit<MachineStatus, 'modelUuid' | 'productId'>>
|
||||||
) => void;
|
) => void;
|
||||||
|
clearMachines: () => void;
|
||||||
|
|
||||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||||
removeCurrentAction: (modelUuid: string) => void;
|
removeCurrentAction: (modelUuid: string) => void;
|
||||||
|
|
||||||
// Status updates
|
|
||||||
setMachineActive: (modelUuid: string, isActive: boolean) => void;
|
setMachineActive: (modelUuid: string, isActive: boolean) => void;
|
||||||
setMachineState: (modelUuid: string, newState: MachineStatus['state']) => void;
|
setMachineState: (modelUuid: string, newState: MachineStatus['state']) => void;
|
||||||
|
|
||||||
// Time tracking
|
|
||||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||||
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
||||||
|
|
||||||
// Helpers
|
|
||||||
getMachineById: (modelUuid: string) => MachineStatus | undefined;
|
getMachineById: (modelUuid: string) => MachineStatus | undefined;
|
||||||
getMachinesByProduct: (productId: string) => MachineStatus[];
|
getMachinesByProduct: (productId: string) => MachineStatus[];
|
||||||
getMachinesBystate: (state: string) => MachineStatus[];
|
getMachinesBystate: (state: string) => MachineStatus[];
|
||||||
|
@ -35,9 +32,10 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
immer((set, get) => ({
|
immer((set, get) => ({
|
||||||
machines: [],
|
machines: [],
|
||||||
|
|
||||||
// Actions
|
|
||||||
addMachine: (productId, machine) => {
|
addMachine: (productId, machine) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const exists = state.machines.some(m => m.modelUuid === machine.modelUuid);
|
||||||
|
if (!exists) {
|
||||||
state.machines.push({
|
state.machines.push({
|
||||||
...machine,
|
...machine,
|
||||||
productId,
|
productId,
|
||||||
|
@ -46,6 +44,7 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
activeTime: 0,
|
activeTime: 0,
|
||||||
state: 'idle',
|
state: 'idle',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -64,6 +63,11 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearMachines: () => {
|
||||||
|
set((state) => {
|
||||||
|
state.machines = [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
addCurrentAction: (modelUuid) => {
|
addCurrentAction: (modelUuid) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
@ -89,7 +93,6 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Status updates
|
|
||||||
setMachineActive: (modelUuid, isActive) => {
|
setMachineActive: (modelUuid, isActive) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
||||||
|
@ -108,7 +111,6 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Time tracking
|
|
||||||
incrementActiveTime: (modelUuid, incrementBy) => {
|
incrementActiveTime: (modelUuid, incrementBy) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
||||||
|
@ -127,7 +129,6 @@ export const useMachineStore = create<MachineStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Helpers
|
|
||||||
getMachineById: (modelUuid) => {
|
getMachineById: (modelUuid) => {
|
||||||
return get().machines.find(m => m.modelUuid === modelUuid);
|
return get().machines.find(m => m.modelUuid === modelUuid);
|
||||||
},
|
},
|
||||||
|
|
|
@ -33,27 +33,30 @@ type ProductsStore = {
|
||||||
pointUuid: string,
|
pointUuid: string,
|
||||||
action: ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']
|
action: ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']
|
||||||
) => EventsSchema | undefined;
|
) => EventsSchema | undefined;
|
||||||
removeAction: (actionUuid: string) => EventsSchema | undefined;
|
removeAction: (productId: string, actionUuid: string) => EventsSchema | undefined;
|
||||||
updateAction: (
|
updateAction: (
|
||||||
|
productId: string,
|
||||||
actionUuid: string,
|
actionUuid: string,
|
||||||
updates: Partial<ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
updates: Partial<ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
||||||
) => EventsSchema | undefined;
|
) => EventsSchema | undefined;
|
||||||
|
|
||||||
// Trigger-level actions
|
// Trigger-level actions
|
||||||
addTrigger: (
|
addTrigger: (
|
||||||
|
productId: string,
|
||||||
actionUuid: string,
|
actionUuid: string,
|
||||||
trigger: TriggerSchema
|
trigger: TriggerSchema
|
||||||
) => EventsSchema | undefined;
|
) => EventsSchema | undefined;
|
||||||
removeTrigger: (triggerUuid: string) => EventsSchema | undefined;
|
removeTrigger: (productId: string, triggerUuid: string) => EventsSchema | undefined;
|
||||||
updateTrigger: (
|
updateTrigger: (
|
||||||
|
productId: string,
|
||||||
triggerUuid: string,
|
triggerUuid: string,
|
||||||
updates: Partial<TriggerSchema>
|
updates: Partial<TriggerSchema>
|
||||||
) => void;
|
) => void;
|
||||||
|
|
||||||
// Renaming functions
|
// Renaming functions
|
||||||
renameProduct: (productId: string, newName: string) => void;
|
renameProduct: (productId: string, newName: string) => void;
|
||||||
renameAction: (actionUuid: string, newName: string) => EventsSchema | undefined;
|
renameAction: (productId: string, actionUuid: string, newName: string) => EventsSchema | undefined;
|
||||||
renameTrigger: (triggerUuid: string, newName: string) => void;
|
renameTrigger: (productId: string, triggerUuid: string, newName: string) => void;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||||
|
@ -71,12 +74,15 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
// Product-level actions
|
// Product-level actions
|
||||||
addProduct: (productName, productId) => {
|
addProduct: (productName, productId) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const existingProduct = state.products.find(p => p.productId === productId);
|
||||||
|
if (!existingProduct) {
|
||||||
const newProduct = {
|
const newProduct = {
|
||||||
productName,
|
productName,
|
||||||
productId: productId,
|
productId: productId,
|
||||||
eventDatas: []
|
eventDatas: []
|
||||||
};
|
};
|
||||||
state.products.push(newProduct);
|
state.products.push(newProduct);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -106,8 +112,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const product = state.products.find(p => p.productId === productId);
|
const product = state.products.find(p => p.productId === productId);
|
||||||
if (product) {
|
if (product) {
|
||||||
|
const existingEvent = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === event.modelUuid);
|
||||||
|
if (!existingEvent) {
|
||||||
product.eventDatas.push(event);
|
product.eventDatas.push(event);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -120,7 +129,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
deleteEvent: (modelUuid: string) => {
|
deleteEvent: (modelUuid) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
||||||
|
@ -150,11 +159,17 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
if (product) {
|
if (product) {
|
||||||
const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
if (event && 'points' in event) {
|
if (event && 'points' in event) {
|
||||||
|
const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
|
||||||
|
if (!existingPoint) {
|
||||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||||
|
}
|
||||||
} else if (event && 'point' in event) {
|
} else if (event && 'point' in event) {
|
||||||
|
const existingPoint = (event as any).point?.uuid === point.uuid;
|
||||||
|
if (!existingPoint) {
|
||||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -198,28 +213,34 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
if (event && 'points' in event) {
|
if (event && 'points' in event) {
|
||||||
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
||||||
if (point) {
|
if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||||
point.action = action as any;
|
point.action = action as any;
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
}
|
}
|
||||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||||
if ('action' in (event as any).point) {
|
if ('action' in (event as any).point) {
|
||||||
|
if (!(event as any).point.action || (event as any).point.action.actionUuid !== action.actionUuid) {
|
||||||
(event as any).point.action = action;
|
(event as any).point.action = action;
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
|
}
|
||||||
} else if ('actions' in (event as any).point) {
|
} else if ('actions' in (event as any).point) {
|
||||||
|
const existingAction = (event as any).point.actions.find((a: any) => a.actionUuid === action.actionUuid);
|
||||||
|
if (!existingAction) {
|
||||||
(event as any).point.actions.push(action);
|
(event as any).point.actions.push(action);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return updatedEvent;
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeAction: (actionUuid: string) => {
|
removeAction: (productId, actionUuid) => {
|
||||||
let updatedEvent: EventsSchema | undefined;
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
// Handle ConveyorEventSchema
|
// Handle ConveyorEventSchema
|
||||||
|
@ -248,10 +269,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
return updatedEvent;
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateAction: (actionUuid, updates) => {
|
updateAction: (productId, actionUuid, updates) => {
|
||||||
let updatedEvent: EventsSchema | undefined;
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
@ -283,30 +305,40 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
},
|
},
|
||||||
|
|
||||||
// Trigger-level actions
|
// Trigger-level actions
|
||||||
addTrigger: (actionUuid, trigger) => {
|
addTrigger: (productId, actionUuid, trigger) => {
|
||||||
let updatedEvent: EventsSchema | undefined;
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
if (point.action && point.action.actionUuid === actionUuid) {
|
if (point.action && point.action.actionUuid === actionUuid) {
|
||||||
|
const existingTrigger = point.action.triggers.find(t => t.triggerUuid === trigger.triggerUuid);
|
||||||
|
if (!existingTrigger) {
|
||||||
point.action.triggers.push(trigger);
|
point.action.triggers.push(trigger);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ('point' in event) {
|
} else if ('point' in event) {
|
||||||
const point = (event as any).point;
|
const point = (event as any).point;
|
||||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||||
|
const existingTrigger = point.action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
|
||||||
|
if (!existingTrigger) {
|
||||||
point.action.triggers.push(trigger);
|
point.action.triggers.push(trigger);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
} else if ('actions' in point) {
|
} else if ('actions' in point) {
|
||||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||||
if (action) {
|
if (action) {
|
||||||
|
const existingTrigger = action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
|
||||||
|
if (!existingTrigger) {
|
||||||
action.triggers.push(trigger);
|
action.triggers.push(trigger);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -317,26 +349,35 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
return updatedEvent;
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
removeTrigger: (triggerUuid) => {
|
removeTrigger: (productId, triggerUuid) => {
|
||||||
let updatedEvent: EventsSchema | undefined;
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
if (point.action && 'triggers' in point.action) {
|
if (point.action && 'triggers' in point.action) {
|
||||||
|
const Trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||||
|
if (Trigger) {
|
||||||
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if ('point' in event) {
|
} else if ('point' in event) {
|
||||||
const point = (event as any).point;
|
const point = (event as any).point;
|
||||||
if ('action' in point && 'triggers' in point.action) {
|
if ('action' in point && 'triggers' in point.action) {
|
||||||
|
const Trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||||
|
if (Trigger) {
|
||||||
point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
|
}
|
||||||
} else if ('actions' in point) {
|
} else if ('actions' in point) {
|
||||||
for (const action of point.actions) {
|
for (const action of point.actions) {
|
||||||
if ('triggers' in action) {
|
if ('triggers' in action) {
|
||||||
|
const Trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||||
|
if (Trigger) {
|
||||||
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||||
}
|
}
|
||||||
|
@ -345,13 +386,15 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
return updatedEvent;
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
updateTrigger: (triggerUuid, updates) => {
|
updateTrigger: (productId, triggerUuid, updates) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
@ -398,10 +441,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
renameAction: (actionUuid, newName) => {
|
renameAction: (productId, actionUuid, newName) => {
|
||||||
let updatedEvent: EventsSchema | undefined;
|
let updatedEvent: EventsSchema | undefined;
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
@ -432,9 +476,10 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
return updatedEvent;
|
return updatedEvent;
|
||||||
},
|
},
|
||||||
|
|
||||||
renameTrigger: (triggerUuid, newName) => {
|
renameTrigger: (productId, triggerUuid, newName) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
const product = state.products.find(p => p.productId === productId);
|
||||||
|
if (product) {
|
||||||
for (const event of product.eventDatas) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
|
|
@ -4,26 +4,22 @@ import { immer } from 'zustand/middleware/immer';
|
||||||
interface StorageUnitStore {
|
interface StorageUnitStore {
|
||||||
storageUnits: StorageUnitStatus[];
|
storageUnits: StorageUnitStatus[];
|
||||||
|
|
||||||
// Actions
|
|
||||||
addStorageUnit: (productId: string, storageUnit: StorageEventSchema) => void;
|
addStorageUnit: (productId: string, storageUnit: StorageEventSchema) => void;
|
||||||
removeStorageUnit: (modelUuid: string) => void;
|
removeStorageUnit: (modelUuid: string) => void;
|
||||||
updateStorageUnit: (
|
updateStorageUnit: (
|
||||||
modelUuid: string,
|
modelUuid: string,
|
||||||
updates: Partial<Omit<StorageUnitStatus, 'modelUuid' | 'productId'>>
|
updates: Partial<Omit<StorageUnitStatus, 'modelUuid' | 'productId'>>
|
||||||
) => void;
|
) => void;
|
||||||
|
clearStorageUnits: () => void;
|
||||||
|
|
||||||
// Status updates
|
|
||||||
setStorageUnitActive: (modelUuid: string, isActive: boolean) => void;
|
setStorageUnitActive: (modelUuid: string, isActive: boolean) => void;
|
||||||
setStorageUnitState: (modelUuid: string, newState: StorageUnitStatus['state']) => void;
|
setStorageUnitState: (modelUuid: string, newState: StorageUnitStatus['state']) => void;
|
||||||
|
|
||||||
// Load updates
|
|
||||||
updateStorageUnitLoad: (modelUuid: string, incrementBy: number) => void;
|
updateStorageUnitLoad: (modelUuid: string, incrementBy: number) => void;
|
||||||
|
|
||||||
// Time tracking
|
|
||||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||||
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
||||||
|
|
||||||
// Helpers
|
|
||||||
getStorageUnitById: (modelUuid: string) => StorageUnitStatus | undefined;
|
getStorageUnitById: (modelUuid: string) => StorageUnitStatus | undefined;
|
||||||
getStorageUnitsByProduct: (productId: string) => StorageUnitStatus[];
|
getStorageUnitsByProduct: (productId: string) => StorageUnitStatus[];
|
||||||
getStorageUnitsBystate: (state: string) => StorageUnitStatus[];
|
getStorageUnitsBystate: (state: string) => StorageUnitStatus[];
|
||||||
|
@ -37,9 +33,10 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
immer((set, get) => ({
|
immer((set, get) => ({
|
||||||
storageUnits: [],
|
storageUnits: [],
|
||||||
|
|
||||||
// Actions
|
|
||||||
addStorageUnit: (productId, storageUnit) => {
|
addStorageUnit: (productId, storageUnit) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid);
|
||||||
|
if (!exists) {
|
||||||
state.storageUnits.push({
|
state.storageUnits.push({
|
||||||
...storageUnit,
|
...storageUnit,
|
||||||
productId,
|
productId,
|
||||||
|
@ -49,6 +46,7 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
currentLoad: 0,
|
currentLoad: 0,
|
||||||
state: 'idle',
|
state: 'idle',
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -67,7 +65,12 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Status updates
|
clearStorageUnits: () => {
|
||||||
|
set(() => ({
|
||||||
|
storageUnits: [],
|
||||||
|
}));
|
||||||
|
},
|
||||||
|
|
||||||
setStorageUnitActive: (modelUuid, isActive) => {
|
setStorageUnitActive: (modelUuid, isActive) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||||
|
@ -86,7 +89,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Load updates
|
|
||||||
updateStorageUnitLoad: (modelUuid, incrementBy) => {
|
updateStorageUnitLoad: (modelUuid, incrementBy) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||||
|
@ -96,7 +98,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Time tracking
|
|
||||||
incrementActiveTime: (modelUuid, incrementBy) => {
|
incrementActiveTime: (modelUuid, incrementBy) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||||
|
@ -115,7 +116,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Helpers
|
|
||||||
getStorageUnitById: (modelUuid) => {
|
getStorageUnitById: (modelUuid) => {
|
||||||
return get().storageUnits.find(s => s.modelUuid === modelUuid);
|
return get().storageUnits.find(s => s.modelUuid === modelUuid);
|
||||||
},
|
},
|
||||||
|
|
|
@ -20,6 +20,7 @@ interface VehiclesStore {
|
||||||
modelUuid: string,
|
modelUuid: string,
|
||||||
updates: Partial<Omit<VehicleStatus, 'modelUuid' | 'productId'>>
|
updates: Partial<Omit<VehicleStatus, 'modelUuid' | 'productId'>>
|
||||||
) => void;
|
) => void;
|
||||||
|
clearvehicles: () => void;
|
||||||
|
|
||||||
setVehicleActive: (modelUuid: string, isActive: boolean) => void;
|
setVehicleActive: (modelUuid: string, isActive: boolean) => void;
|
||||||
updateSteeringAngle: (modelUuid: string, steeringAngle: number) => void;
|
updateSteeringAngle: (modelUuid: string, steeringAngle: number) => void;
|
||||||
|
@ -41,6 +42,8 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||||
|
|
||||||
addVehicle: (productId, event) => {
|
addVehicle: (productId, event) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
|
const exists = state.vehicles.some(v => v.modelUuid === event.modelUuid);
|
||||||
|
if (!exists) {
|
||||||
state.vehicles.push({
|
state.vehicles.push({
|
||||||
...event,
|
...event,
|
||||||
productId,
|
productId,
|
||||||
|
@ -50,6 +53,7 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||||
currentLoad: 0,
|
currentLoad: 0,
|
||||||
distanceTraveled: 0,
|
distanceTraveled: 0,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -68,6 +72,12 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
clearvehicles: () => {
|
||||||
|
set((state) => {
|
||||||
|
state.vehicles = [];
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
setVehicleActive: (modelUuid, isActive) => {
|
setVehicleActive: (modelUuid, isActive) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||||
|
|
|
@ -88,6 +88,7 @@ interface StoragePointSchema {
|
||||||
actionType: "store";
|
actionType: "store";
|
||||||
materials: { materialName: string; materialId: string; }[];
|
materials: { materialName: string; materialId: string; }[];
|
||||||
storageCapacity: number;
|
storageCapacity: number;
|
||||||
|
triggers: TriggerSchema[];
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue