Enhance TriggerConnector and useProductStore: add removeTrigger return value and improve event handling in TriggerConnector
This commit is contained in:
@@ -44,7 +44,7 @@ type ProductsStore = {
|
||||
actionUuid: string,
|
||||
trigger: TriggerSchema
|
||||
) => EventsSchema | undefined;
|
||||
removeTrigger: (triggerUuid: string) => void;
|
||||
removeTrigger: (triggerUuid: string) => EventsSchema | undefined;
|
||||
updateTrigger: (
|
||||
triggerUuid: string,
|
||||
updates: Partial<TriggerSchema>
|
||||
@@ -318,6 +318,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
},
|
||||
|
||||
removeTrigger: (triggerUuid) => {
|
||||
let updatedEvent: EventsSchema | undefined;
|
||||
set((state) => {
|
||||
for (const product of state.products) {
|
||||
for (const event of product.eventDatas) {
|
||||
@@ -325,16 +326,19 @@ export const useProductStore = create<ProductsStore>()(
|
||||
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);
|
||||
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);
|
||||
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);
|
||||
updatedEvent = JSON.parse(JSON.stringify(event));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -342,6 +346,7 @@ export const useProductStore = create<ProductsStore>()(
|
||||
}
|
||||
}
|
||||
});
|
||||
return updatedEvent;
|
||||
},
|
||||
|
||||
updateTrigger: (triggerUuid, updates) => {
|
||||
|
||||
Reference in New Issue
Block a user