Enhance event handling and backend updates across mechanics components; refactor trigger management in TriggerConnector

This commit is contained in:
2025-04-30 20:16:26 +05:30
parent a704be77d3
commit 29efeab387
12 changed files with 399 additions and 89 deletions

View File

@@ -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;
@@ -60,12 +60,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

View File

@@ -43,7 +43,7 @@ type ProductsStore = {
addTrigger: (
actionUuid: string,
trigger: TriggerSchema
) => void;
) => EventsSchema | undefined;
removeTrigger: (triggerUuid: string) => void;
updateTrigger: (
triggerUuid: string,
@@ -284,6 +284,7 @@ export const useProductStore = create<ProductsStore>()(
// Trigger-level actions
addTrigger: (actionUuid, trigger) => {
let updatedEvent: EventsSchema | undefined;
set((state) => {
for (const product of state.products) {
for (const event of product.eventDatas) {
@@ -291,6 +292,7 @@ export const useProductStore = create<ProductsStore>()(
for (const point of (event as ConveyorEventSchema).points) {
if (point.action && point.action.actionUuid === actionUuid) {
point.action.triggers.push(trigger);
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
@@ -298,11 +300,13 @@ export const useProductStore = create<ProductsStore>()(
const point = (event as any).point;
if ('action' in point && point.action.actionUuid === actionUuid) {
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);
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
@@ -310,6 +314,7 @@ export const useProductStore = create<ProductsStore>()(
}
}
});
return updatedEvent;
},
removeTrigger: (triggerUuid) => {