merged with orgin/v2
This commit is contained in:
@@ -1,17 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface ArmBotStatus extends RoboticArmEventSchema {
|
||||
productId: string;
|
||||
isActive: boolean;
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentAction?: {
|
||||
actionUuid: string;
|
||||
actionName: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface ArmBotStore {
|
||||
armBots: ArmBotStatus[];
|
||||
|
||||
@@ -22,9 +11,14 @@ interface ArmBotStore {
|
||||
updates: Partial<Omit<ArmBotStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
|
||||
startAction: (modelUuid: string, actionUuid: string) => void;
|
||||
completeAction: (modelUuid: string) => void;
|
||||
cancelAction: (modelUuid: string) => void;
|
||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||
removeCurrentAction: (modelUuid: string) => void;
|
||||
|
||||
addAction: (modelUuid: string, action: RoboticArmPointSchema['actions'][number]) => void;
|
||||
removeAction: (modelUuid: string, actionUuid: string) => void;
|
||||
|
||||
updateStartPoint: (modelUuid: string, actionUuid: string, startPoint: [number, number, number] | null) => void;
|
||||
updateEndPoint: (modelUuid: string, actionUuid: string, endPoint: [number, number, number] | null) => void;
|
||||
|
||||
setArmBotActive: (modelUuid: string, isActive: boolean) => void;
|
||||
|
||||
@@ -71,7 +65,7 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
startAction: (modelUuid, actionUuid) => {
|
||||
addCurrentAction: (modelUuid, actionUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
@@ -87,22 +81,54 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
completeAction: (modelUuid) => {
|
||||
removeCurrentAction: (modelUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot && armBot.currentAction) {
|
||||
if (armBot) {
|
||||
armBot.currentAction = undefined;
|
||||
armBot.isActive = false;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
cancelAction: (modelUuid) => {
|
||||
addAction: (modelUuid, action) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
armBot.currentAction = undefined;
|
||||
armBot.isActive = false;
|
||||
armBot.point.actions.push(action);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeAction: (modelUuid, actionUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
armBot.point.actions = armBot.point.actions.filter(a => a.actionUuid !== actionUuid);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateStartPoint: (modelUuid, actionUuid, startPoint) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.process.startPoint = startPoint;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
updateEndPoint: (modelUuid, actionUuid, endPoint) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
const action = armBot.point.actions.find(a => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.process.endPoint = endPoint;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface ConveyorStatus extends ConveyorEventSchema {
|
||||
productId: string;
|
||||
isActive: boolean;
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
}
|
||||
|
||||
interface ConveyorStore {
|
||||
conveyors: ConveyorStatus[];
|
||||
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface MachineStatus extends MachineEventSchema {
|
||||
productId: string;
|
||||
isActive: boolean;
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
}
|
||||
|
||||
interface MachineStore {
|
||||
machines: MachineStatus[];
|
||||
|
||||
|
||||
76
app/src/store/simulation/useMaterialStore.ts
Normal file
76
app/src/store/simulation/useMaterialStore.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
type MaterialsStore = {
|
||||
materials: MaterialsSchema;
|
||||
|
||||
addMaterial: (material: MaterialSchema) => void;
|
||||
removeMaterial: (materialId: string) => void;
|
||||
updateMaterial: (materialId: string, updates: Partial<MaterialSchema>) => void;
|
||||
|
||||
setStartTime: (materialId: string, startTime: string) => void;
|
||||
setEndTime: (materialId: string, endTime: string) => void;
|
||||
setCost: (materialId: string, cost: number) => void;
|
||||
setWeight: (materialId: string, weight: number) => void;
|
||||
|
||||
getMaterialById: (materialId: string) => MaterialSchema | undefined;
|
||||
};
|
||||
|
||||
export const useMaterialStore = create<MaterialsStore>()(
|
||||
immer((set, get) => ({
|
||||
materials: [],
|
||||
|
||||
addMaterial: (material) => {
|
||||
set((state) => {
|
||||
state.materials.push(material);
|
||||
});
|
||||
},
|
||||
|
||||
removeMaterial: (materialId) => {
|
||||
set((state) => {
|
||||
state.materials = state.materials.filter(m => m.materialId !== materialId);
|
||||
});
|
||||
},
|
||||
|
||||
updateMaterial: (materialId, updates) => {
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) {
|
||||
Object.assign(material, updates);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setStartTime: (materialId, startTime) => {
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) material.startTime = startTime;
|
||||
});
|
||||
},
|
||||
|
||||
setEndTime: (materialId, endTime) => {
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) material.endTime = endTime;
|
||||
});
|
||||
},
|
||||
|
||||
setCost: (materialId, cost) => {
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) material.cost = cost;
|
||||
});
|
||||
},
|
||||
|
||||
setWeight: (materialId, weight) => {
|
||||
set((state) => {
|
||||
const material = state.materials.find(m => m.materialId === materialId);
|
||||
if (material) material.weight = weight;
|
||||
});
|
||||
},
|
||||
|
||||
getMaterialById: (materialId) => {
|
||||
return get().materials.find(m => m.materialId === materialId);
|
||||
},
|
||||
}))
|
||||
);
|
||||
@@ -7,7 +7,7 @@ type ProductsStore = {
|
||||
// Product-level actions
|
||||
addProduct: (productName: string, 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
|
||||
addEvent: (productId: string, event: EventsSchema) => void;
|
||||
@@ -48,8 +48,18 @@ type ProductsStore = {
|
||||
updates: Partial<TriggerSchema>
|
||||
) => void;
|
||||
|
||||
// Renaming functions
|
||||
renameProduct: (productId: string, newName: string) => void;
|
||||
renameAction: (actionUuid: string, newName: string) => void;
|
||||
renameTrigger: (triggerUuid: string, newName: string) => void;
|
||||
|
||||
// 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;
|
||||
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;
|
||||
getTriggerByUuid: (productId: string, triggerUuid: string) => TriggerSchema | undefined;
|
||||
getIsEventInProduct: (productId: string, modelUuid: string) => boolean;
|
||||
};
|
||||
|
||||
export const useProductStore = create<ProductsStore>()(
|
||||
@@ -62,7 +72,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
const newProduct = {
|
||||
productName,
|
||||
productId: productId,
|
||||
eventsData: []
|
||||
eventDatas: []
|
||||
};
|
||||
state.products.push(newProduct);
|
||||
});
|
||||
@@ -88,7 +98,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
product.eventsData.push(event);
|
||||
product.eventDatas.push(event);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -97,7 +107,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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);
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -106,7 +116,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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) {
|
||||
Object.assign(event, updates);
|
||||
}
|
||||
@@ -119,7 +129,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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) {
|
||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||
} else if (event && 'point' in event) {
|
||||
@@ -133,7 +143,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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) {
|
||||
(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) {
|
||||
@@ -147,7 +157,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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) {
|
||||
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
if (point) {
|
||||
@@ -165,7 +175,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
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) {
|
||||
const point = (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
if (point) {
|
||||
@@ -185,7 +195,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
removeAction: (actionUuid: string) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
// Handle ConveyorEventSchema
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
@@ -209,7 +219,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
updateAction: (actionUuid, updates) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
@@ -239,7 +249,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
addTrigger: (actionUuid, trigger) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
@@ -268,7 +278,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
removeTrigger: (triggerUuid) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
@@ -295,7 +305,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
updateTrigger: (triggerUuid, updates) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventsData) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
@@ -331,9 +341,170 @@ export const useProductStore = create<ProductsStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Renaming functions
|
||||
renameProduct: (productId, newName) => {
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
product.productName = newName;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
renameAction: (actionUuid, newName) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
point.action.actionName = newName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
point.action.actionName = newName;
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.actionName = newName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
renameTrigger: (triggerUuid, newName) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
trigger.triggerName = newName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
trigger.triggerName = newName;
|
||||
return;
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (trigger) {
|
||||
trigger.triggerName = newName;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
// Helper functions
|
||||
getProductById: (productId) => {
|
||||
return get().products.find(p => p.productId === productId);
|
||||
},
|
||||
|
||||
getEventByModelUuid: (productId, modelUuid) => {
|
||||
const product = get().getProductById(productId);
|
||||
if (!product) return undefined;
|
||||
return product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
getPointByUuid: (productId, modelUuid, pointUuid) => {
|
||||
const event = get().getEventByModelUuid(productId, modelUuid);
|
||||
if (!event) return undefined;
|
||||
|
||||
if ('points' in event) {
|
||||
return (event as ConveyorEventSchema).points.find(p => p.uuid === pointUuid);
|
||||
} else if ('point' in event && (event as any).point.uuid === pointUuid) {
|
||||
return (event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point;
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getActionByUuid: (productId, actionUuid) => {
|
||||
const product = get().products.find(p => p.productId === productId);
|
||||
if (!product) return undefined;
|
||||
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action?.actionUuid === actionUuid) {
|
||||
return point.action;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action?.actionUuid === actionUuid) {
|
||||
return point.action;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getTriggerByUuid: (productId, triggerUuid) => {
|
||||
const product = get().products.find(p => p.productId === productId);
|
||||
if (!product) return undefined;
|
||||
|
||||
for (const event of product.eventDatas) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
for (const trigger of point.action?.triggers || []) {
|
||||
if (trigger.triggerUuid === triggerUuid) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point) {
|
||||
for (const trigger of point.action?.triggers || []) {
|
||||
if (trigger.triggerUuid === triggerUuid) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
for (const trigger of action.triggers || []) {
|
||||
if (trigger.triggerUuid === triggerUuid) {
|
||||
return trigger;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
},
|
||||
|
||||
getIsEventInProduct: (productId, modelUuid) => {
|
||||
const product = get().getProductById(productId);
|
||||
if (!product) return false;
|
||||
return product.eventDatas.some(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
}
|
||||
}))
|
||||
);
|
||||
|
||||
117
app/src/store/simulation/useSimulationStore.ts
Normal file
117
app/src/store/simulation/useSimulationStore.ts
Normal file
@@ -0,0 +1,117 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
import * as THREE from 'three';
|
||||
|
||||
interface SelectedEventSphereState {
|
||||
selectedEventSphere: THREE.Mesh | null;
|
||||
setSelectedEventSphere: (mesh: THREE.Mesh | null) => void;
|
||||
clearSelectedEventSphere: () => void;
|
||||
}
|
||||
|
||||
export const useSelectedEventSphere = create<SelectedEventSphereState>()(
|
||||
immer((set) => ({
|
||||
selectedEventSphere: null,
|
||||
setSelectedEventSphere: (mesh) => {
|
||||
set((state) => {
|
||||
state.selectedEventSphere = mesh;
|
||||
});
|
||||
},
|
||||
clearSelectedEventSphere: () => {
|
||||
set((state) => {
|
||||
state.selectedEventSphere = null;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface SelectedEventDataState {
|
||||
selectedEventData: { data: EventsSchema; selectedPoint: string } | undefined;
|
||||
setSelectedEventData: (data: EventsSchema, selectedPoint: string) => void;
|
||||
clearSelectedEventData: () => void;
|
||||
}
|
||||
|
||||
export const useSelectedEventData = create<SelectedEventDataState>()(
|
||||
immer((set) => ({
|
||||
selectedEventData: undefined,
|
||||
setSelectedEventData: (data, selectedPoint) => {
|
||||
set((state) => {
|
||||
state.selectedEventData = { data, selectedPoint };
|
||||
});
|
||||
},
|
||||
clearSelectedEventData: () => {
|
||||
set((state) => {
|
||||
state.selectedEventData = undefined;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface SelectedAssetState {
|
||||
selectedAsset: EventsSchema | undefined;
|
||||
setSelectedAsset: (EventData: EventsSchema) => void;
|
||||
clearSelectedAsset: () => void;
|
||||
}
|
||||
|
||||
export const useSelectedAsset = create<SelectedAssetState>()(
|
||||
immer((set) => ({
|
||||
selectedAsset: undefined,
|
||||
setSelectedAsset: (EventData) => {
|
||||
set((state) => {
|
||||
state.selectedAsset = EventData;
|
||||
});
|
||||
},
|
||||
clearSelectedAsset: () => {
|
||||
set((state) => {
|
||||
state.selectedAsset = undefined;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface SelectedProductState {
|
||||
selectedProduct: { productId: string; productName: string };
|
||||
setSelectedProduct: (productId: string, productName: string) => void;
|
||||
clearSelectedProduct: () => void;
|
||||
}
|
||||
|
||||
export const useSelectedProduct = create<SelectedProductState>()(
|
||||
immer((set) => ({
|
||||
selectedProduct: { productId: '', productName: '' },
|
||||
setSelectedProduct: (productId, productName) => {
|
||||
set((state) => {
|
||||
state.selectedProduct.productId = productId;
|
||||
state.selectedProduct.productName = productName;
|
||||
});
|
||||
},
|
||||
clearSelectedProduct: () => {
|
||||
set((state) => {
|
||||
state.selectedProduct.productId = '';
|
||||
state.selectedProduct.productName = '';
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface SelectedActionState {
|
||||
selectedAction: { actionId: string; actionName: string };
|
||||
setSelectedAction: (actionId: string, actionName: string) => void;
|
||||
clearSelectedAction: () => void;
|
||||
}
|
||||
|
||||
export const useSelectedAction = create<SelectedActionState>()(
|
||||
immer((set) => ({
|
||||
selectedAction: { actionId: '', actionName: '' },
|
||||
setSelectedAction: (actionId, actionName) => {
|
||||
set((state) => {
|
||||
state.selectedAction.actionId = actionId;
|
||||
state.selectedAction.actionName = actionName;
|
||||
});
|
||||
},
|
||||
clearSelectedAction: () => {
|
||||
set((state) => {
|
||||
state.selectedAction.actionId = '';
|
||||
state.selectedAction.actionName = '';
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
@@ -1,14 +1,6 @@
|
||||
import { create } from 'zustand';
|
||||
import { immer } from 'zustand/middleware/immer';
|
||||
|
||||
interface StorageUnitStatus extends StorageEventSchema {
|
||||
productId: string;
|
||||
isActive: boolean;
|
||||
idleTime: number;
|
||||
activeTime: number;
|
||||
currentLoad: number;
|
||||
}
|
||||
|
||||
interface StorageUnitStore {
|
||||
storageUnits: StorageUnitStatus[];
|
||||
|
||||
|
||||
@@ -21,7 +21,8 @@ interface VehiclesStore {
|
||||
) => void;
|
||||
|
||||
setVehicleActive: (modelUuid: string, isActive: boolean) => void;
|
||||
updateVehicleLoad: (modelUuid: string, load: number) => void;
|
||||
incrementVehicleLoad: (modelUuid: string, incrementBy: number) => void;
|
||||
decrementVehicleLoad: (modelUuid: string, decrementBy: number) => void;
|
||||
setVehicleState: (modelUuid: string, newState: VehicleStatus['state']) => void;
|
||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
||||
@@ -74,11 +75,20 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
updateVehicleLoad: (modelUuid, load) => {
|
||||
incrementVehicleLoad: (modelUuid, incrementBy) => {
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
if (vehicle) {
|
||||
vehicle.currentLoad = load;
|
||||
vehicle.currentLoad += incrementBy;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
decrementVehicleLoad: (modelUuid, decrementBy) => {
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
if (vehicle) {
|
||||
vehicle.currentLoad -= decrementBy;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -13,14 +13,17 @@ const useModuleStore = create<ModuleStore>((set) => ({
|
||||
export default useModuleStore;
|
||||
|
||||
// New store for subModule
|
||||
|
||||
type SubModule = 'properties' | 'simulations' | 'mechanics' | 'analysis' | 'zoneProperties';
|
||||
|
||||
interface SubModuleStore {
|
||||
subModule: string;
|
||||
setSubModule: (subModule: string) => void;
|
||||
subModule: SubModule;
|
||||
setSubModule: (subModule: SubModule) => void;
|
||||
}
|
||||
|
||||
const useSubModuleStore = create<SubModuleStore>((set) => ({
|
||||
subModule: "properties", // Initial subModule state
|
||||
setSubModule: (subModule) => set({ subModule }), // Update subModule state
|
||||
setSubModule: (value) => set({ subModule: value }), // Update subModule state
|
||||
}));
|
||||
|
||||
export { useSubModuleStore };
|
||||
|
||||
Reference in New Issue
Block a user