Merge remote-tracking branch 'origin/v2' into v2-ui
This commit is contained in:
@@ -10,6 +10,7 @@ interface ArmBotStore {
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<ArmBotStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
clearArmBots: () => void;
|
||||
|
||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||
removeCurrentAction: (modelUuid: string) => void;
|
||||
@@ -39,14 +40,17 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||
|
||||
addArmBot: (productId, event) => {
|
||||
set((state) => {
|
||||
state.armBots.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
const exists = state.armBots.some(a => a.modelUuid === event.modelUuid);
|
||||
if (!exists) {
|
||||
state.armBots.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -65,6 +69,12 @@ export const useArmBotStore = create<ArmBotStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
clearArmBots: () => {
|
||||
set((state) => {
|
||||
state.armBots = [];
|
||||
});
|
||||
},
|
||||
|
||||
addCurrentAction: (modelUuid, actionUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.armBots.find(a => a.modelUuid === modelUuid);
|
||||
|
||||
@@ -10,6 +10,7 @@ interface ConveyorStore {
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<ConveyorStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
clearConveyors: () => void;
|
||||
|
||||
setConveyorActive: (modelUuid: string, isActive: boolean) => void;
|
||||
setConveyorState: (modelUuid: string, newState: ConveyorStatus['state']) => void;
|
||||
@@ -30,14 +31,17 @@ export const useConveyorStore = create<ConveyorStore>()(
|
||||
|
||||
addConveyor: (productId, event) => {
|
||||
set((state) => {
|
||||
state.conveyors.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
const exists = state.conveyors.some(c => c.modelUuid === event.modelUuid);
|
||||
if (!exists) {
|
||||
state.conveyors.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -56,6 +60,12 @@ export const useConveyorStore = create<ConveyorStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
clearConveyors: () => {
|
||||
set((state) => {
|
||||
state.conveyors = [];
|
||||
});
|
||||
},
|
||||
|
||||
setConveyorActive: (modelUuid, isActive) => {
|
||||
set((state) => {
|
||||
const conveyor = state.conveyors.find(c => c.modelUuid === modelUuid);
|
||||
|
||||
@@ -7,7 +7,7 @@ type EventsStore = {
|
||||
// Event-level actions
|
||||
addEvent: (event: EventsSchema) => void;
|
||||
removeEvent: (modelUuid: string) => void;
|
||||
updateEvent: (modelUuid: string, updates: Partial<EventsSchema>) => void;
|
||||
updateEvent: (modelUuid: string, updates: Partial<EventsSchema>) => EventsSchema | undefined;
|
||||
|
||||
// Point-level actions
|
||||
addPoint: (modelUuid: string, point: ConveyorPointSchema | VehiclePointSchema | RoboticArmPointSchema | MachinePointSchema | StoragePointSchema) => void;
|
||||
@@ -49,7 +49,9 @@ export const useEventsStore = create<EventsStore>()(
|
||||
// Event-level actions
|
||||
addEvent: (event) => {
|
||||
set((state) => {
|
||||
state.events.push(event);
|
||||
if (!state.events.some(e => 'modelUuid' in e && e.modelUuid === event.modelUuid)) {
|
||||
state.events.push(event);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -60,12 +62,15 @@ export const useEventsStore = create<EventsStore>()(
|
||||
},
|
||||
|
||||
updateEvent: (modelUuid, updates) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event) {
|
||||
Object.assign(event, updates);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
});
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
// Point-level actions
|
||||
@@ -73,9 +78,14 @@ export const useEventsStore = create<EventsStore>()(
|
||||
set((state) => {
|
||||
const event = state.events.find(e => 'modelUuid' in e && e.modelUuid === modelUuid);
|
||||
if (event && 'points' in event) {
|
||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||
const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
|
||||
if (!existingPoint) {
|
||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||
}
|
||||
} else if (event && 'point' in event) {
|
||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||
if (!(event as any).point || (event as any).point.uuid !== point.uuid) {
|
||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -110,14 +120,15 @@ export const useEventsStore = create<EventsStore>()(
|
||||
const event = state.events.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) {
|
||||
if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||
point.action = action as any;
|
||||
}
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
if ('action' in (event as any).point) {
|
||||
(event as any).point.action = action;
|
||||
} else if ('actions' in (event as any).point) {
|
||||
(event as any).point.actions.push(action);
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||
point.action = action;
|
||||
} else if ('actions' in point && !point.actions.some((a: any) => a.actionUuid === action.actionUuid)) {
|
||||
point.actions.push(action);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -180,18 +191,22 @@ export const useEventsStore = create<EventsStore>()(
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||
point.action.triggers.push(trigger);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
point.action.triggers.push(trigger);
|
||||
if (!point.action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||
point.action.triggers.push(trigger);
|
||||
}
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
const action = (point as RoboticArmPointSchema).actions.find((a) => a.actionUuid === actionUuid);
|
||||
if (action && !action.triggers.some(t => t.triggerUuid === trigger.triggerUuid)) {
|
||||
action.triggers.push(trigger);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -4,23 +4,23 @@ import { immer } from 'zustand/middleware/immer';
|
||||
interface MachineStore {
|
||||
machines: MachineStatus[];
|
||||
|
||||
// Actions
|
||||
addMachine: (productId: string, machine: MachineEventSchema) => void;
|
||||
removeMachine: (modelUuid: string) => void;
|
||||
updateMachine: (
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<MachineStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
clearMachines: () => void;
|
||||
|
||||
addCurrentAction: (modelUuid: string, actionUuid: string) => void;
|
||||
removeCurrentAction: (modelUuid: string) => void;
|
||||
|
||||
// Status updates
|
||||
setMachineActive: (modelUuid: string, isActive: boolean) => void;
|
||||
setMachineState: (modelUuid: string, newState: MachineStatus['state']) => void;
|
||||
|
||||
// Time tracking
|
||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
||||
|
||||
// Helpers
|
||||
getMachineById: (modelUuid: string) => MachineStatus | undefined;
|
||||
getMachinesByProduct: (productId: string) => MachineStatus[];
|
||||
getMachinesBystate: (state: string) => MachineStatus[];
|
||||
@@ -32,17 +32,19 @@ export const useMachineStore = create<MachineStore>()(
|
||||
immer((set, get) => ({
|
||||
machines: [],
|
||||
|
||||
// Actions
|
||||
addMachine: (productId, machine) => {
|
||||
set((state) => {
|
||||
state.machines.push({
|
||||
...machine,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
const exists = state.machines.some(m => m.modelUuid === machine.modelUuid);
|
||||
if (!exists) {
|
||||
state.machines.push({
|
||||
...machine,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -61,7 +63,36 @@ export const useMachineStore = create<MachineStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Status updates
|
||||
clearMachines: () => {
|
||||
set((state) => {
|
||||
state.machines = [];
|
||||
});
|
||||
},
|
||||
|
||||
addCurrentAction: (modelUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.machines.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
const action = armBot.point.action;
|
||||
if (action) {
|
||||
armBot.currentAction = {
|
||||
actionUuid: action.actionUuid,
|
||||
actionName: action.actionName,
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
removeCurrentAction: (modelUuid) => {
|
||||
set((state) => {
|
||||
const armBot = state.machines.find(a => a.modelUuid === modelUuid);
|
||||
if (armBot) {
|
||||
armBot.currentAction = undefined;
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
setMachineActive: (modelUuid, isActive) => {
|
||||
set((state) => {
|
||||
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
||||
@@ -80,7 +111,6 @@ export const useMachineStore = create<MachineStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Time tracking
|
||||
incrementActiveTime: (modelUuid, incrementBy) => {
|
||||
set((state) => {
|
||||
const machine = state.machines.find(m => m.modelUuid === modelUuid);
|
||||
@@ -99,7 +129,6 @@ export const useMachineStore = create<MachineStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Helpers
|
||||
getMachineById: (modelUuid) => {
|
||||
return get().machines.find(m => m.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
@@ -33,27 +33,30 @@ type ProductsStore = {
|
||||
pointUuid: string,
|
||||
action: ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']
|
||||
) => EventsSchema | undefined;
|
||||
removeAction: (actionUuid: string) => EventsSchema | undefined;
|
||||
removeAction: (productId: string, actionUuid: string) => EventsSchema | undefined;
|
||||
updateAction: (
|
||||
productId: string,
|
||||
actionUuid: string,
|
||||
updates: Partial<ConveyorPointSchema['action'] | VehiclePointSchema['action'] | RoboticArmPointSchema['actions'][0] | MachinePointSchema['action'] | StoragePointSchema['action']>
|
||||
) => EventsSchema | undefined;
|
||||
|
||||
// Trigger-level actions
|
||||
addTrigger: (
|
||||
productId: string,
|
||||
actionUuid: string,
|
||||
trigger: TriggerSchema
|
||||
) => void;
|
||||
removeTrigger: (triggerUuid: string) => void;
|
||||
) => EventsSchema | undefined;
|
||||
removeTrigger: (productId: string, triggerUuid: string) => EventsSchema | undefined;
|
||||
updateTrigger: (
|
||||
productId: string,
|
||||
triggerUuid: string,
|
||||
updates: Partial<TriggerSchema>
|
||||
) => void;
|
||||
|
||||
// Renaming functions
|
||||
renameProduct: (productId: string, newName: string) => void;
|
||||
renameAction: (actionUuid: string, newName: string) => EventsSchema | undefined;
|
||||
renameTrigger: (triggerUuid: string, newName: string) => void;
|
||||
renameAction: (productId: string, actionUuid: string, newName: string) => EventsSchema | undefined;
|
||||
renameTrigger: (productId: string, triggerUuid: string, newName: string) => void;
|
||||
|
||||
// Helper functions
|
||||
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
|
||||
@@ -71,12 +74,15 @@ export const useProductStore = create<ProductsStore>()(
|
||||
// Product-level actions
|
||||
addProduct: (productName, productId) => {
|
||||
set((state) => {
|
||||
const newProduct = {
|
||||
productName,
|
||||
productId: productId,
|
||||
eventDatas: []
|
||||
};
|
||||
state.products.push(newProduct);
|
||||
const existingProduct = state.products.find(p => p.productId === productId);
|
||||
if (!existingProduct) {
|
||||
const newProduct = {
|
||||
productName,
|
||||
productId: productId,
|
||||
eventDatas: []
|
||||
};
|
||||
state.products.push(newProduct);
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -106,7 +112,10 @@ export const useProductStore = create<ProductsStore>()(
|
||||
set((state) => {
|
||||
const product = state.products.find(p => p.productId === productId);
|
||||
if (product) {
|
||||
product.eventDatas.push(event);
|
||||
const existingEvent = product.eventDatas.find(e => 'modelUuid' in e && e.modelUuid === event.modelUuid);
|
||||
if (!existingEvent) {
|
||||
product.eventDatas.push(event);
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -120,7 +129,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
deleteEvent: (modelUuid: string) => {
|
||||
deleteEvent: (modelUuid) => {
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
product.eventDatas = product.eventDatas.filter(e => 'modelUuid' in e && e.modelUuid !== modelUuid);
|
||||
@@ -150,9 +159,15 @@ export const useProductStore = create<ProductsStore>()(
|
||||
if (product) {
|
||||
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);
|
||||
const existingPoint = (event as ConveyorEventSchema).points.find(p => p.uuid === point.uuid);
|
||||
if (!existingPoint) {
|
||||
(event as ConveyorEventSchema).points.push(point as ConveyorPointSchema);
|
||||
}
|
||||
} else if (event && 'point' in event) {
|
||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||
const existingPoint = (event as any).point?.uuid === point.uuid;
|
||||
if (!existingPoint) {
|
||||
(event as VehicleEventSchema | RoboticArmEventSchema | MachineEventSchema | StorageEventSchema).point = point as any;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -198,17 +213,22 @@ export const useProductStore = create<ProductsStore>()(
|
||||
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) {
|
||||
if (point && (!point.action || point.action.actionUuid !== action.actionUuid)) {
|
||||
point.action = action as any;
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
} else if (event && 'point' in event && (event as any).point.uuid === pointUuid) {
|
||||
if ('action' in (event as any).point) {
|
||||
(event as any).point.action = action;
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
if (!(event as any).point.action || (event as any).point.action.actionUuid !== action.actionUuid) {
|
||||
(event as any).point.action = action;
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
} else if ('actions' in (event as any).point) {
|
||||
(event as any).point.actions.push(action);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
const existingAction = (event as any).point.actions.find((a: any) => a.actionUuid === action.actionUuid);
|
||||
if (!existingAction) {
|
||||
(event as any).point.actions.push(action);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,10 +236,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
removeAction: (actionUuid: string) => {
|
||||
removeAction: (productId, actionUuid) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
// Handle ConveyorEventSchema
|
||||
@@ -248,10 +269,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
updateAction: (actionUuid, updates) => {
|
||||
updateAction: (productId, actionUuid, updates) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
@@ -283,26 +305,40 @@ export const useProductStore = create<ProductsStore>()(
|
||||
},
|
||||
|
||||
// Trigger-level actions
|
||||
addTrigger: (actionUuid, trigger) => {
|
||||
addTrigger: (productId, actionUuid, trigger) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
const existingTrigger = point.action.triggers.find(t => t.triggerUuid === trigger.triggerUuid);
|
||||
if (!existingTrigger) {
|
||||
point.action.triggers.push(trigger);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && point.action.actionUuid === actionUuid) {
|
||||
point.action.triggers.push(trigger);
|
||||
const existingTrigger = point.action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
|
||||
if (!existingTrigger) {
|
||||
point.action.triggers.push(trigger);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
return;
|
||||
} else if ('actions' in point) {
|
||||
const action = point.actions.find((a: any) => a.actionUuid === actionUuid);
|
||||
if (action) {
|
||||
action.triggers.push(trigger);
|
||||
const existingTrigger = action.triggers.find((t: any) => t.triggerUuid === trigger.triggerUuid);
|
||||
if (!existingTrigger) {
|
||||
action.triggers.push(trigger);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -310,26 +346,41 @@ export const useProductStore = create<ProductsStore>()(
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
removeTrigger: (triggerUuid) => {
|
||||
removeTrigger: (productId, triggerUuid) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
if (point.action && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||
const Trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
|
||||
if (Trigger) {
|
||||
point.action.triggers = point.action.triggers.filter(t => t.triggerUuid !== triggerUuid);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if ('point' in event) {
|
||||
const point = (event as any).point;
|
||||
if ('action' in point && 'triggers' in point.action) {
|
||||
point.action.triggers = point.action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
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);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
} else if ('actions' in point) {
|
||||
for (const action of point.actions) {
|
||||
if ('triggers' in action) {
|
||||
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
const Trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
|
||||
if (Trigger) {
|
||||
action.triggers = action.triggers.filter((t: any) => t.triggerUuid !== triggerUuid);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -337,11 +388,13 @@ export const useProductStore = create<ProductsStore>()(
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
updateTrigger: (triggerUuid, updates) => {
|
||||
updateTrigger: (productId, triggerUuid, updates) => {
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
@@ -388,10 +441,11 @@ export const useProductStore = create<ProductsStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
renameAction: (actionUuid, newName) => {
|
||||
renameAction: (productId, actionUuid, newName) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
@@ -422,9 +476,10 @@ export const useProductStore = create<ProductsStore>()(
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
renameTrigger: (triggerUuid, newName) => {
|
||||
renameTrigger: (productId, triggerUuid, newName) => {
|
||||
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) {
|
||||
if ('points' in event) {
|
||||
for (const point of (event as ConveyorEventSchema).points) {
|
||||
|
||||
@@ -114,4 +114,36 @@ export const useSelectedAction = create<SelectedActionState>()(
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface IsDraggingState {
|
||||
isDragging: "start" | "end" | null;
|
||||
setIsDragging: (state: "start" | "end" | null) => void;
|
||||
}
|
||||
|
||||
export const useIsDragging = create<IsDraggingState>()(
|
||||
immer((set) => ({
|
||||
isDragging: null,
|
||||
setIsDragging: (state) => {
|
||||
set((s) => {
|
||||
s.isDragging = state;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
|
||||
interface IsRotatingState {
|
||||
isRotating: "start" | "end" | null;
|
||||
setIsRotating: (state: "start" | "end" | null) => void;
|
||||
}
|
||||
|
||||
export const useIsRotating = create<IsRotatingState>()(
|
||||
immer((set) => ({
|
||||
isRotating: null,
|
||||
setIsRotating: (state) => {
|
||||
set((s) => {
|
||||
s.isRotating = state;
|
||||
});
|
||||
},
|
||||
}))
|
||||
);
|
||||
@@ -4,26 +4,22 @@ import { immer } from 'zustand/middleware/immer';
|
||||
interface StorageUnitStore {
|
||||
storageUnits: StorageUnitStatus[];
|
||||
|
||||
// Actions
|
||||
addStorageUnit: (productId: string, storageUnit: StorageEventSchema) => void;
|
||||
removeStorageUnit: (modelUuid: string) => void;
|
||||
updateStorageUnit: (
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<StorageUnitStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
clearStorageUnits: () => void;
|
||||
|
||||
// Status updates
|
||||
setStorageUnitActive: (modelUuid: string, isActive: boolean) => void;
|
||||
setStorageUnitState: (modelUuid: string, newState: StorageUnitStatus['state']) => void;
|
||||
|
||||
// Load updates
|
||||
updateStorageUnitLoad: (modelUuid: string, incrementBy: number) => void;
|
||||
|
||||
// Time tracking
|
||||
incrementActiveTime: (modelUuid: string, incrementBy: number) => void;
|
||||
incrementIdleTime: (modelUuid: string, incrementBy: number) => void;
|
||||
|
||||
// Helpers
|
||||
getStorageUnitById: (modelUuid: string) => StorageUnitStatus | undefined;
|
||||
getStorageUnitsByProduct: (productId: string) => StorageUnitStatus[];
|
||||
getStorageUnitsBystate: (state: string) => StorageUnitStatus[];
|
||||
@@ -37,18 +33,20 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||
immer((set, get) => ({
|
||||
storageUnits: [],
|
||||
|
||||
// Actions
|
||||
addStorageUnit: (productId, storageUnit) => {
|
||||
set((state) => {
|
||||
state.storageUnits.push({
|
||||
...storageUnit,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
currentLoad: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
const exists = state.storageUnits.some(s => s.modelUuid === storageUnit.modelUuid);
|
||||
if (!exists) {
|
||||
state.storageUnits.push({
|
||||
...storageUnit,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
currentLoad: 0,
|
||||
state: 'idle',
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -67,7 +65,12 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Status updates
|
||||
clearStorageUnits: () => {
|
||||
set(() => ({
|
||||
storageUnits: [],
|
||||
}));
|
||||
},
|
||||
|
||||
setStorageUnitActive: (modelUuid, isActive) => {
|
||||
set((state) => {
|
||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||
@@ -86,7 +89,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Load updates
|
||||
updateStorageUnitLoad: (modelUuid, incrementBy) => {
|
||||
set((state) => {
|
||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||
@@ -96,7 +98,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Time tracking
|
||||
incrementActiveTime: (modelUuid, incrementBy) => {
|
||||
set((state) => {
|
||||
const unit = state.storageUnits.find(s => s.modelUuid === modelUuid);
|
||||
@@ -115,7 +116,6 @@ export const useStorageUnitStore = create<StorageUnitStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
// Helpers
|
||||
getStorageUnitById: (modelUuid) => {
|
||||
return get().storageUnits.find(s => s.modelUuid === modelUuid);
|
||||
},
|
||||
|
||||
@@ -20,6 +20,7 @@ interface VehiclesStore {
|
||||
modelUuid: string,
|
||||
updates: Partial<Omit<VehicleStatus, 'modelUuid' | 'productId'>>
|
||||
) => void;
|
||||
clearvehicles: () => void;
|
||||
|
||||
setVehicleActive: (modelUuid: string, isActive: boolean) => void;
|
||||
updateSteeringAngle: (modelUuid: string, steeringAngle: number) => void;
|
||||
@@ -41,15 +42,18 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||
|
||||
addVehicle: (productId, event) => {
|
||||
set((state) => {
|
||||
state.vehicles.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
currentLoad: 0,
|
||||
distanceTraveled: 0,
|
||||
});
|
||||
const exists = state.vehicles.some(v => v.modelUuid === event.modelUuid);
|
||||
if (!exists) {
|
||||
state.vehicles.push({
|
||||
...event,
|
||||
productId,
|
||||
isActive: false,
|
||||
idleTime: 0,
|
||||
activeTime: 0,
|
||||
currentLoad: 0,
|
||||
distanceTraveled: 0,
|
||||
});
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
@@ -68,6 +72,12 @@ export const useVehicleStore = create<VehiclesStore>()(
|
||||
});
|
||||
},
|
||||
|
||||
clearvehicles: () => {
|
||||
set((state) => {
|
||||
state.vehicles = [];
|
||||
});
|
||||
},
|
||||
|
||||
setVehicleActive: (modelUuid, isActive) => {
|
||||
set((state) => {
|
||||
const vehicle = state.vehicles.find(v => v.modelUuid === modelUuid);
|
||||
|
||||
Reference in New Issue
Block a user