Refactor trigger handling in Trigger component: update trigger selection logic and add memoization for performance; enhance renameTrigger function in useProductStore to return updated event.

This commit is contained in:
2025-05-03 13:23:01 +05:30
parent 649352b4b4
commit 71fdb26e16
3 changed files with 113 additions and 52 deletions

View File

@@ -56,7 +56,7 @@ type ProductsStore = {
// Renaming functions
renameProduct: (productId: string, newName: string) => void;
renameAction: (productId: string, actionUuid: string, newName: string) => EventsSchema | undefined;
renameTrigger: (productId: string, triggerUuid: string, newName: string) => void;
renameTrigger: (productId: string, triggerUuid: string, newName: string) => EventsSchema | undefined;
// Helper functions
getProductById: (productId: string) => { productName: string; productId: string; eventDatas: EventsSchema[] } | undefined;
@@ -482,6 +482,7 @@ export const useProductStore = create<ProductsStore>()(
},
renameTrigger: (productId, triggerUuid, newName) => {
let updatedEvent: EventsSchema | undefined;
set((state) => {
const product = state.products.find(p => p.productId === productId);
if (product) {
@@ -492,6 +493,7 @@ export const useProductStore = create<ProductsStore>()(
const trigger = point.action.triggers.find(t => t.triggerUuid === triggerUuid);
if (trigger) {
trigger.triggerName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
@@ -502,6 +504,7 @@ export const useProductStore = create<ProductsStore>()(
const trigger = point.action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
if (trigger) {
trigger.triggerName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
} else if ('actions' in point) {
@@ -510,6 +513,7 @@ export const useProductStore = create<ProductsStore>()(
const trigger = action.triggers.find((t: any) => t.triggerUuid === triggerUuid);
if (trigger) {
trigger.triggerName = newName;
updatedEvent = JSON.parse(JSON.stringify(event));
return;
}
}
@@ -519,6 +523,7 @@ export const useProductStore = create<ProductsStore>()(
}
}
});
return updatedEvent;
},
// Helper functions