feat: Implement Zustand stores for machine, simulation, storage unit, vehicle, and visualization management

- Added `useMachineStore` for managing machine statuses, including actions for adding, removing, and updating machines.
- Introduced `useSimulationStore` to handle product and event management with actions for adding, removing, and updating products and events.
- Created `useStorageUnitStore` for managing storage unit statuses, including load tracking and state updates.
- Developed `useVehicleStore` for vehicle management, including load and state updates.
- Implemented `useChartStore` for managing measurement data and visualization settings.
- Added `useDroppedObjectsStore` for handling dropped objects in visualization zones, including object manipulation actions.
- Created `useZone3DWidgetStore` for managing 3D widget data in zones, including position and rotation updates.
- Introduced `useZoneStore` for managing selected zone states and widget configurations.
This commit is contained in:
2025-04-22 14:28:29 +05:30
parent 78b9663d0f
commit 6363d5b9af
65 changed files with 1306 additions and 194 deletions

View File

@@ -0,0 +1,129 @@
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: Record<string, ConveyorStatus>;
// Actions
addConveyor: (productId: string, event: ConveyorEventSchema) => void;
removeConveyor: (modelUuid: string) => void;
updateConveyor: (
modelUuid: string,
updates: Partial<Omit<ConveyorStatus, 'modelUuid' | 'productId'>>
) => void;
// Status updates
setConveyorActive: (modelUuid: string, isActive: boolean) => void;
setConveyorState: (modelUuid: string, newState: ConveyorStatus['state']) => void;
// Time tracking
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
// Helper functions
getConveyorById: (modelUuid: string) => ConveyorStatus | undefined;
getConveyorsByProduct: (productId: string) => ConveyorStatus[];
getActiveConveyors: () => ConveyorStatus[];
getIdleConveyors: () => ConveyorStatus[];
}
export const useConveyorStore = create<ConveyorStore>()(
immer((set, get) => ({
conveyors: {},
// Actions
addConveyor: (productId, event) => {
set((state) => {
state.conveyors[event.modelUuid] = {
...event,
productId,
isActive: false,
idleTime: 0,
activeTime: 0,
state: 'idle',
};
});
},
removeConveyor: (modelUuid) => {
set((state) => {
delete state.conveyors[modelUuid];
});
},
updateConveyor: (modelUuid, updates) => {
set((state) => {
const conveyor = state.conveyors[modelUuid];
if (conveyor) {
Object.assign(conveyor, updates);
}
});
},
// Status updates
setConveyorActive: (modelUuid, isActive) => {
set((state) => {
const conveyor = state.conveyors[modelUuid];
if (conveyor) {
conveyor.isActive = isActive;
}
});
},
setConveyorState: (modelUuid, newState) => {
set((state) => {
const conveyor = state.conveyors[modelUuid];
if (conveyor) {
conveyor.state = newState;
}
});
},
// Time tracking
incrementActiveTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors[modelUuid];
if (conveyor) {
conveyor.activeTime += incrementBy;
}
});
},
incrementIdleTime: (modelUuid, incrementBy) => {
set((state) => {
const conveyor = state.conveyors[modelUuid];
if (conveyor) {
conveyor.idleTime += incrementBy;
}
});
},
// Helper functions
getConveyorById: (modelUuid) => {
return get().conveyors[modelUuid];
},
getConveyorsByProduct: (productId) => {
return Object.values(get().conveyors).filter(
c => c.productId === productId
);
},
getActiveConveyors: () => {
return Object.values(get().conveyors).filter(c => c.isActive);
},
getIdleConveyors: () => {
return Object.values(get().conveyors).filter(
c => !c.isActive && c.state === 'idle'
);
},
}))
);