Fixed events missing on duplicating queries (#2499)

This commit is contained in:
Shaurya Sharma 2024-10-25 12:40:57 +05:30 committed by Shaurya Sharma
parent f45463d889
commit 1c83d01026
3 changed files with 18 additions and 2 deletions

View file

@ -262,7 +262,7 @@ export const copyComponents = ({ isCut = false, isCloning = false }) => {
for (let selectedComponent of filteredSelectedComponents) {
if (addedComponentId.has(selectedComponent.id)) continue;
const events = useStore.getState().eventsSlice.geEventsByComponentsId(selectedComponent.id);
const events = useStore.getState().eventsSlice.getEventsByComponentsId(selectedComponent.id);
const component = {
component: allComponents[selectedComponent.id]?.component,
layouts: allComponents[selectedComponent.id]?.layouts,

View file

@ -223,6 +223,8 @@ export const createDataQuerySlice = (set, get) => ({
set((state) => {
state.dataQuery.creatingQueryInProcessId = uuidv4();
});
const { eventsSlice } = get();
const { getEventsByComponentsId, createAppVersionEventHandlers } = eventsSlice;
const dataQueries = get().dataQuery.queries.modules[moduleId];
const queryToClone = { ...dataQueries.find((query) => query.id === id) };
let newName = queryToClone.name + '_copy';
@ -266,6 +268,20 @@ export const createDataQuerySlice = (set, get) => ({
rawData: [],
id: data.id,
});
const events = getEventsByComponentsId(queryToClone.id);
events.forEach((event) => {
const newEvent = {
event: {
...event.event,
},
eventType: event.target,
attachedTo: data.id,
index: event.index,
};
createAppVersionEventHandlers(newEvent, moduleId);
});
})
.catch((error) => {
console.error('error', error);

View file

@ -948,7 +948,7 @@ export const createEventsSlice = (set, get) => ({
};
},
// Selectors
geEventsByComponentsId: (componentId, moduleId = 'canvas') => {
getEventsByComponentsId: (componentId, moduleId = 'canvas') => {
const { eventsSlice } = get();
return eventsSlice.module[moduleId]?.events?.filter((event) => event.sourceId === componentId);
},