feat: Refactor event data handling and API integration; update variable names for consistency and clarity
This commit is contained in:
parent
c0e0bcb69d
commit
a1a1eacb79
|
@ -37,7 +37,7 @@ const SideBarRight: React.FC = () => {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (activeModule !== "mechanics" && selectedEventData && selectedEventSphere) {
|
if (activeModule !== "mechanics" && selectedEventData && selectedEventSphere) {
|
||||||
setSubModule("mechanics");
|
setSubModule("mechanics");
|
||||||
} else {
|
} else if (!selectedEventData && !selectedEventSphere) {
|
||||||
if (activeModule === 'simulation') {
|
if (activeModule === 'simulation') {
|
||||||
setSubModule("simulations");
|
setSubModule("simulations");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,4 @@
|
||||||
import React, { useEffect, useRef, useState } from "react";
|
import React, { useEffect, useRef, useState } from "react";
|
||||||
import InputWithDropDown from "../../../../ui/inputs/InputWithDropDown";
|
|
||||||
import LabledDropdown from "../../../../ui/inputs/LabledDropdown";
|
|
||||||
import {
|
|
||||||
AddIcon,
|
|
||||||
RemoveIcon,
|
|
||||||
ResizeHeightIcon,
|
|
||||||
} from "../../../../icons/ExportCommonIcons";
|
|
||||||
import RenameInput from "../../../../ui/inputs/RenameInput";
|
|
||||||
import { handleResize } from "../../../../../functions/handleResizePannel";
|
|
||||||
import { handleActionToggle } from "./functions/handleActionToggle";
|
|
||||||
import { handleDeleteAction } from "./functions/handleDeleteAction";
|
|
||||||
import DefaultAction from "./actions/DefaultAction";
|
|
||||||
import SpawnAction from "./actions/SpawnAction";
|
|
||||||
import SwapAction from "./actions/SwapAction";
|
|
||||||
import DespawnAction from "./actions/DespawnAction";
|
|
||||||
import TravelAction from "./actions/TravelAction";
|
|
||||||
import PickAndPlaceAction from "./actions/PickAndPlaceAction";
|
|
||||||
import ProcessAction from "./actions/ProcessAction";
|
|
||||||
import StorageAction from "./actions/StorageAction";
|
|
||||||
import Trigger from "./trigger/Trigger";
|
|
||||||
|
|
||||||
import { useSelectedEventData, useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
|
import { useSelectedEventData, useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
|
||||||
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
||||||
import ConveyorMechanics from "./mechanics/conveyorMechanics";
|
import ConveyorMechanics from "./mechanics/conveyorMechanics";
|
||||||
|
@ -29,23 +8,11 @@ import MachineMechanics from "./mechanics/machineMechanics";
|
||||||
import StorageMechanics from "./mechanics/storageMechanics";
|
import StorageMechanics from "./mechanics/storageMechanics";
|
||||||
|
|
||||||
const EventProperties: React.FC = () => {
|
const EventProperties: React.FC = () => {
|
||||||
const actionsContainerRef = useRef<HTMLDivElement>(null);
|
|
||||||
|
|
||||||
const [activeOption, setActiveOption] = useState("default");
|
|
||||||
const [selectedItem, setSelectedItem] = useState<{ item: { uuid: string; name: string } | null; }>({ item: null });
|
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { getEventByModelUuid } = useProductStore();
|
const { getEventByModelUuid } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
|
|
||||||
// State for derived values
|
|
||||||
const [currentEventData, setCurrentEventData] = useState<EventsSchema | null>(null);
|
const [currentEventData, setCurrentEventData] = useState<EventsSchema | null>(null);
|
||||||
const [assetType, setAssetType] = useState<string | null>(null);
|
const [assetType, setAssetType] = useState<string | null>(null);
|
||||||
const [availableActions, setAvailableActions] = useState({
|
|
||||||
defaultOption: "default",
|
|
||||||
options: ["default"]
|
|
||||||
});
|
|
||||||
const [actions, setActions] = useState<{ uuid: string; name: string }[]>([]);
|
|
||||||
const [speed, setSpeed] = useState("0.5");
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const event = getCurrentEventData();
|
const event = getCurrentEventData();
|
||||||
|
@ -54,18 +21,6 @@ const EventProperties: React.FC = () => {
|
||||||
const type = determineAssetType(event);
|
const type = determineAssetType(event);
|
||||||
setAssetType(type);
|
setAssetType(type);
|
||||||
|
|
||||||
const actionsConfig = determineAvailableActions(type);
|
|
||||||
setAvailableActions(actionsConfig);
|
|
||||||
|
|
||||||
const actionList = getActionList(event, type);
|
|
||||||
setActions(actionList);
|
|
||||||
|
|
||||||
if (actionList.length > 0 && !selectedItem.item) {
|
|
||||||
setSelectedItem({ item: actionList[0] });
|
|
||||||
}
|
|
||||||
|
|
||||||
const currentSpeed = getCurrentSpeed();
|
|
||||||
setSpeed(currentSpeed);
|
|
||||||
}, [selectedEventData, selectedProduct]);
|
}, [selectedEventData, selectedProduct]);
|
||||||
|
|
||||||
const getCurrentEventData = () => {
|
const getCurrentEventData = () => {
|
||||||
|
@ -86,92 +41,6 @@ const EventProperties: React.FC = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const determineAvailableActions = (type: string | null) => {
|
|
||||||
switch (type) {
|
|
||||||
case "conveyor":
|
|
||||||
return {
|
|
||||||
defaultOption: "default",
|
|
||||||
options: ["default", "spawn", "swap", "despawn"],
|
|
||||||
};
|
|
||||||
case "vehicle":
|
|
||||||
return {
|
|
||||||
defaultOption: "travel",
|
|
||||||
options: ["travel"],
|
|
||||||
};
|
|
||||||
case "roboticArm":
|
|
||||||
return {
|
|
||||||
defaultOption: "pickAndPlace",
|
|
||||||
options: ["pickAndPlace"],
|
|
||||||
};
|
|
||||||
case "machine":
|
|
||||||
return {
|
|
||||||
defaultOption: "process",
|
|
||||||
options: ["process"],
|
|
||||||
};
|
|
||||||
case "storageUnit":
|
|
||||||
return {
|
|
||||||
defaultOption: "store",
|
|
||||||
options: ["store", "spawn"],
|
|
||||||
};
|
|
||||||
default:
|
|
||||||
return {
|
|
||||||
defaultOption: "default",
|
|
||||||
options: ["default"],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getActionList = (event: EventsSchema | null, type: string | null) => {
|
|
||||||
if (!selectedEventData?.data) return [];
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case "conveyor":
|
|
||||||
return (event as ConveyorEventSchema).points
|
|
||||||
.find((point) => point.uuid === selectedEventData?.selectedPoint)
|
|
||||||
?.action?.triggers.map((trigger) => ({
|
|
||||||
uuid: trigger.triggerUuid,
|
|
||||||
name: trigger.triggerName,
|
|
||||||
})) || [];
|
|
||||||
case "vehicle":
|
|
||||||
return (event as VehicleEventSchema).point.action.triggers.map(
|
|
||||||
(trigger) => ({
|
|
||||||
uuid: trigger.triggerUuid,
|
|
||||||
name: trigger.triggerName,
|
|
||||||
})
|
|
||||||
) || [];
|
|
||||||
case "roboticArm":
|
|
||||||
return (event as RoboticArmEventSchema).point.actions.flatMap(
|
|
||||||
(action) =>
|
|
||||||
action.triggers.map((trigger) => ({
|
|
||||||
uuid: trigger.triggerUuid,
|
|
||||||
name: trigger.triggerName,
|
|
||||||
}))
|
|
||||||
) || [];
|
|
||||||
case "machine":
|
|
||||||
return (event as MachineEventSchema).point.action.triggers.map(
|
|
||||||
(trigger) => ({
|
|
||||||
uuid: trigger.triggerUuid,
|
|
||||||
name: trigger.triggerName,
|
|
||||||
})
|
|
||||||
) || [];
|
|
||||||
case "storageUnit":
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
uuid: (event as StorageEventSchema).point.action.actionUuid,
|
|
||||||
name: (event as StorageEventSchema).point.action.actionName,
|
|
||||||
},
|
|
||||||
];
|
|
||||||
default:
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const getCurrentSpeed = () => {
|
|
||||||
if (!selectedEventData) return "0.5";
|
|
||||||
if ("speed" in selectedEventData.data) return selectedEventData.data.speed.toString();
|
|
||||||
return "0.5";
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div className="event-proprties-wrapper">
|
<div className="event-proprties-wrapper">
|
||||||
|
|
|
@ -1,20 +1,28 @@
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import InputWithDropDown from "../../../../../ui/inputs/InputWithDropDown";
|
import InputWithDropDown from "../../../../../ui/inputs/InputWithDropDown";
|
||||||
|
|
||||||
const StorageAction: React.FC = () => {
|
interface StorageActionProps {
|
||||||
return (
|
value: string;
|
||||||
<InputWithDropDown
|
min: number;
|
||||||
label="Storage Capacity"
|
max: number;
|
||||||
value=""
|
defaultValue: string;
|
||||||
min={0}
|
onChange: (value: string) => void;
|
||||||
step={0.1}
|
}
|
||||||
max={10}
|
|
||||||
defaultValue="0"
|
const StorageAction: React.FC<StorageActionProps> = ({ value, min, max, defaultValue, onChange }) => {
|
||||||
activeOption="s"
|
return (
|
||||||
onClick={() => {}}
|
<InputWithDropDown
|
||||||
onChange={(value) => console.log(value)}
|
label="Storage Capacity"
|
||||||
/>
|
value={value}
|
||||||
);
|
min={min}
|
||||||
|
step={1}
|
||||||
|
max={max}
|
||||||
|
defaultValue={defaultValue}
|
||||||
|
activeOption="s"
|
||||||
|
onClick={() => { }}
|
||||||
|
onChange={onChange}
|
||||||
|
/>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export default StorageAction;
|
export default StorageAction;
|
||||||
|
|
|
@ -96,7 +96,6 @@ function MachineMechanics() {
|
||||||
defaultOption="process"
|
defaultOption="process"
|
||||||
options={availableActions.options}
|
options={availableActions.options}
|
||||||
onSelect={handleActionTypeChange}
|
onSelect={handleActionTypeChange}
|
||||||
disabled={true}
|
|
||||||
/>
|
/>
|
||||||
{activeOption === "process" &&
|
{activeOption === "process" &&
|
||||||
<ProcessAction
|
<ProcessAction
|
||||||
|
|
|
@ -7,44 +7,98 @@ import { useProductStore } from "../../../../../../store/simulation/useProductSt
|
||||||
import StorageAction from '../actions/StorageAction';
|
import StorageAction from '../actions/StorageAction';
|
||||||
|
|
||||||
function StorageMechanics() {
|
function StorageMechanics() {
|
||||||
const [activeOption, setActiveOption] = useState("default");
|
const [activeOption, setActiveOption] = useState<"default" | "store" | "spawn">("default");
|
||||||
const [selectedPointData, setSelectedPointData] = useState<PointsScheme | undefined>();
|
const [selectedPointData, setSelectedPointData] = useState<StoragePointSchema | undefined>();
|
||||||
const { selectedEventData } = useSelectedEventData();
|
const { selectedEventData } = useSelectedEventData();
|
||||||
const { getPointByUuid } = useProductStore();
|
const { getPointByUuid, updateAction } = useProductStore();
|
||||||
const { selectedProduct } = useSelectedProduct();
|
const { selectedProduct } = useSelectedProduct();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedEventData) {
|
if (selectedEventData) {
|
||||||
const point = getPointByUuid(selectedProduct.productId, selectedEventData?.data.modelUuid, selectedEventData?.selectedPoint);
|
const point = getPointByUuid(
|
||||||
|
selectedProduct.productId,
|
||||||
|
selectedEventData?.data.modelUuid,
|
||||||
|
selectedEventData?.selectedPoint
|
||||||
|
) as StoragePointSchema | undefined;
|
||||||
if (point && 'action' in point) {
|
if (point && 'action' in point) {
|
||||||
setSelectedPointData(point as PointsScheme & { action: { actionType: string } });
|
setSelectedPointData(point);
|
||||||
setActiveOption((point as PointsScheme & { action: { actionType: string } }).action.actionType);
|
setActiveOption(point.action.actionType as "store" | "spawn");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [selectedProduct, selectedEventData])
|
}, [selectedProduct, selectedEventData])
|
||||||
|
|
||||||
|
const handleActionTypeChange = (option: string) => {
|
||||||
|
if (!selectedEventData || !selectedPointData) return;
|
||||||
|
const validOption = option as "store" | "spawn";
|
||||||
|
setActiveOption(validOption);
|
||||||
|
|
||||||
|
updateAction(
|
||||||
|
selectedPointData.action.actionUuid,
|
||||||
|
{ actionType: validOption }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleRenameAction = (newName: string) => {
|
||||||
|
if (!selectedPointData) return;
|
||||||
|
updateAction(
|
||||||
|
selectedPointData.action.actionUuid,
|
||||||
|
{ actionName: newName }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleCapacityChange = (value: string) => {
|
||||||
|
if (!selectedPointData) return;
|
||||||
|
updateAction(
|
||||||
|
selectedPointData.action.actionUuid,
|
||||||
|
{ storageCapacity: parseInt(value) }
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Get current values from store
|
||||||
|
const currentActionName = selectedPointData
|
||||||
|
? selectedPointData.action.actionName
|
||||||
|
: "Action Name";
|
||||||
|
|
||||||
|
const currentCapacity = selectedPointData
|
||||||
|
? selectedPointData.action.storageCapacity.toString()
|
||||||
|
: "0";
|
||||||
|
|
||||||
const availableActions = {
|
const availableActions = {
|
||||||
defaultOption: "store",
|
defaultOption: "store",
|
||||||
options: ["store", "spawn"],
|
options: ["store", "spawn"],
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{selectedEventData &&
|
{selectedEventData &&
|
||||||
<>
|
<>
|
||||||
<div className="selected-actions-details">
|
<div className="selected-actions-details">
|
||||||
<div className="selected-actions-header">
|
<div className="selected-actions-header">
|
||||||
<RenameInput value="Action Name" />
|
<RenameInput
|
||||||
|
value={currentActionName}
|
||||||
|
onRename={handleRenameAction}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="selected-actions-list">
|
<div className="selected-actions-list">
|
||||||
<LabledDropdown
|
<LabledDropdown
|
||||||
defaultOption={selectedPointData && 'action' in selectedPointData
|
defaultOption={activeOption}
|
||||||
? (selectedPointData as PointsScheme & { action: { actionType: string } }).action.actionType
|
|
||||||
: "default"}
|
|
||||||
options={availableActions.options}
|
options={availableActions.options}
|
||||||
onSelect={(option) => setActiveOption(option)}
|
onSelect={handleActionTypeChange}
|
||||||
/>
|
/>
|
||||||
{activeOption === "store" && <StorageAction />}
|
{activeOption === "store" &&
|
||||||
|
<StorageAction
|
||||||
|
value={currentCapacity}
|
||||||
|
defaultValue="0"
|
||||||
|
min={0}
|
||||||
|
max={20}
|
||||||
|
onChange={handleCapacityChange}
|
||||||
|
/>
|
||||||
|
}
|
||||||
|
{activeOption === "spawn" && (
|
||||||
|
<div className="spawn-options">
|
||||||
|
<p>Spawn configuration options would go here</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="tirgger">
|
<div className="tirgger">
|
||||||
|
|
|
@ -90,7 +90,7 @@ const Simulations: React.FC = () => {
|
||||||
(product) => product.productId === selectedProduct.productId
|
(product) => product.productId === selectedProduct.productId
|
||||||
);
|
);
|
||||||
|
|
||||||
const events: Event[] = selectedProductData?.eventsData.map((event) => ({
|
const events: Event[] = selectedProductData?.eventDatas.map((event) => ({
|
||||||
pathName: event.modelName,
|
pathName: event.modelName,
|
||||||
})) || [];
|
})) || [];
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,10 @@ function RoboticArmInstances() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{
|
|
||||||
armBots?.map((robot) => (
|
{armBots?.map((robot) => (
|
||||||
<RoboticArmInstance key={robot.modelUuid} armdetals={robot} />
|
<RoboticArmInstance key={robot.modelUuid} armdetals={robot} />
|
||||||
))
|
))}
|
||||||
}
|
|
||||||
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const addProductOrEventApi = async (body: any) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/v2/UpsertProductOrEvent`, {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to add product or event");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
} else {
|
||||||
|
throw new Error("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,26 @@
|
||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const deleteEventDataApi = async (body: any) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/v2/EventDataDelete`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify(body),
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to delete event data");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
} else {
|
||||||
|
throw new Error("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,25 @@
|
||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const deleteProductDataApi = async (productId: string, organization: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/v2/productDataDelete?productId=${productId}&organization=${organization}`, {
|
||||||
|
method: "PATCH",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to delete product data");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
} else {
|
||||||
|
throw new Error("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,25 @@
|
||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const getProductApi = async (productId: string, organization: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/v2/productDatas?productId=${productId}&organization=${organization}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch product data");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
} else {
|
||||||
|
throw new Error("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -0,0 +1,25 @@
|
||||||
|
let url_Backend_dwinzo = `http://${process.env.REACT_APP_SERVER_REST_API_BASE_URL}`;
|
||||||
|
|
||||||
|
export const getAllProductsApi = async ( organization: string) => {
|
||||||
|
try {
|
||||||
|
const response = await fetch(`${url_Backend_dwinzo}/api/v2/AllProducts/${organization}`, {
|
||||||
|
method: "GET",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
throw new Error("Failed to fetch all products data");
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await response.json();
|
||||||
|
return result;
|
||||||
|
} catch (error) {
|
||||||
|
if (error instanceof Error) {
|
||||||
|
throw new Error(error.message);
|
||||||
|
} else {
|
||||||
|
throw new Error("An unknown error occurred");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
|
@ -7,7 +7,7 @@ type ProductsStore = {
|
||||||
// Product-level actions
|
// Product-level actions
|
||||||
addProduct: (productName: string, productId: string) => void;
|
addProduct: (productName: string, productId: string) => void;
|
||||||
removeProduct: (productId: string) => void;
|
removeProduct: (productId: string) => void;
|
||||||
updateProduct: (productId: string, updates: Partial<{ productName: string; eventsData: EventsSchema[] }>) => void;
|
updateProduct: (productId: string, updates: Partial<{ productName: string; eventDatas: EventsSchema[] }>) => void;
|
||||||
|
|
||||||
// Event-level actions
|
// Event-level actions
|
||||||
addEvent: (productId: string, event: EventsSchema) => void;
|
addEvent: (productId: string, event: EventsSchema) => void;
|
||||||
|
@ -54,7 +54,7 @@ type ProductsStore = {
|
||||||
renameTrigger: (triggerUuid: string, newName: string) => void;
|
renameTrigger: (triggerUuid: string, newName: string) => void;
|
||||||
|
|
||||||
// Helper functions
|
// Helper functions
|
||||||
getProductById: (productId: string) => { productName: string; productId: string; eventsData: EventsSchema[] } | undefined;
|
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||||
getEventByModelUuid: (productId: string, modelUuid: string) => EventsSchema | undefined;
|
getEventByModelUuid: (productId: string, modelUuid: string) => EventsSchema | undefined;
|
||||||
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
getPointByUuid: (productId: string, modelUuid: string, pointUuid: string) => ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema | undefined;
|
||||||
getActionByUuid: (productId: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
getActionByUuid: (productId: string, actionUuid: string) => (ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']) | undefined;
|
||||||
|
@ -72,7 +72,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const newProduct = {
|
const newProduct = {
|
||||||
productName,
|
productName,
|
||||||
productId: productId,
|
productId: productId,
|
||||||
eventsData: []
|
eventDatas: []
|
||||||
};
|
};
|
||||||
state.products.push(newProduct);
|
state.products.push(newProduct);
|
||||||
});
|
});
|
||||||
|
@ -98,7 +98,7 @@ 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) {
|
||||||
product.eventsData.push(event);
|
product.eventDatas.push(event);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -107,7 +107,7 @@ 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) {
|
||||||
product.eventsData = product.eventsData.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
@ -116,7 +116,7 @@ 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 event = product.eventsData.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
const event = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
if (event) {
|
if (event) {
|
||||||
Object.assign(event, updates);
|
Object.assign(event, updates);
|
||||||
}
|
}
|
||||||
|
@ -129,7 +129,7 @@ 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 event = product.eventsData.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) {
|
||||||
(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) {
|
||||||
|
@ -143,7 +143,7 @@ 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 event = product.eventsData.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) {
|
||||||
(event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
|
(event as ConveyorEventSchema).points = (event as ConveyorEventSchema).points.filter(p => p.uuid !== pointUuid);
|
||||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||||
|
@ -157,7 +157,7 @@ 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 event = product.eventsData.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) {
|
||||||
|
@ -175,7 +175,7 @@ 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 event = product.eventsData.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) {
|
||||||
|
@ -195,7 +195,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
removeAction: (actionUuid: string) => {
|
removeAction: (actionUuid: string) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
for (const event of product.eventDatas) {
|
||||||
if ('points' in event) {
|
if ('points' in event) {
|
||||||
// Handle ConveyorEventSchema
|
// Handle ConveyorEventSchema
|
||||||
for (const point of (event as ConveyorEventSchema).points) {
|
for (const point of (event as ConveyorEventSchema).points) {
|
||||||
|
@ -219,7 +219,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
updateAction: (actionUuid, updates) => {
|
updateAction: (actionUuid, updates) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -249,7 +249,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
addTrigger: (actionUuid, trigger) => {
|
addTrigger: (actionUuid, trigger) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -278,7 +278,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
removeTrigger: (triggerUuid) => {
|
removeTrigger: (triggerUuid) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -305,7 +305,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
updateTrigger: (triggerUuid, updates) => {
|
updateTrigger: (triggerUuid, updates) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -354,7 +354,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
renameAction: (actionUuid, newName) => {
|
renameAction: (actionUuid, newName) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -383,7 +383,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
renameTrigger: (triggerUuid, newName) => {
|
renameTrigger: (triggerUuid, newName) => {
|
||||||
set((state) => {
|
set((state) => {
|
||||||
for (const product of state.products) {
|
for (const product of state.products) {
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
|
@ -427,7 +427,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
getEventByModelUuid: (productId, modelUuid) => {
|
getEventByModelUuid: (productId, modelUuid) => {
|
||||||
const product = get().getProductById(productId);
|
const product = get().getProductById(productId);
|
||||||
if (!product) return undefined;
|
if (!product) return undefined;
|
||||||
return product.eventsData.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
},
|
},
|
||||||
|
|
||||||
getPointByUuid: (productId, modelUuid, pointUuid) => {
|
getPointByUuid: (productId, modelUuid, pointUuid) => {
|
||||||
|
@ -446,7 +446,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const product = get().products.find(p => p.productId === productId);
|
const product = get().products.find(p => p.productId === productId);
|
||||||
if (!product) return undefined;
|
if (!product) return undefined;
|
||||||
|
|
||||||
for (const event of product.eventsData) {
|
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?.actionUuid === actionUuid) {
|
if (point.action?.actionUuid === actionUuid) {
|
||||||
|
@ -470,7 +470,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
const product = get().products.find(p => p.productId === productId);
|
const product = get().products.find(p => p.productId === productId);
|
||||||
if (!product) return undefined;
|
if (!product) return undefined;
|
||||||
|
|
||||||
for (const event of product.eventsData) {
|
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) {
|
||||||
for (const trigger of point.action?.triggers || []) {
|
for (const trigger of point.action?.triggers || []) {
|
||||||
|
@ -504,7 +504,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||||
getIsEventInProduct: (productId, modelUuid) => {
|
getIsEventInProduct: (productId, modelUuid) => {
|
||||||
const product = get().getProductById(productId);
|
const product = get().getProductById(productId);
|
||||||
if (!product) return false;
|
if (!product) return false;
|
||||||
return product.eventsData.some(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
return product.eventDatas.some(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
|
@ -126,7 +126,7 @@ type EventsSchema = ConveyorEventSchema | VehicleEventSchema | RoboticArmEventSc
|
||||||
type productsSchema = {
|
type productsSchema = {
|
||||||
productName: string;
|
productName: string;
|
||||||
productId: string;
|
productId: string;
|
||||||
eventsData: EventsSchema[];
|
eventDatas: EventsSchema[];
|
||||||
}[]
|
}[]
|
||||||
|
|
||||||
|
|
||||||
|
@ -135,6 +135,7 @@ interface ConveyorStatus extends ConveyorEventSchema {
|
||||||
isActive: boolean;
|
isActive: boolean;
|
||||||
idleTime: number;
|
idleTime: number;
|
||||||
activeTime: number;
|
activeTime: number;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface MachineStatus extends MachineEventSchema {
|
interface MachineStatus extends MachineEventSchema {
|
||||||
|
|
Loading…
Reference in New Issue