diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 3405ada065..db2709dac1 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -87,6 +87,7 @@ const EditorComponent = (props) => { setIsSaving, createAppVersionEventHandlers, setAppPreviewLink, + autoUpdateEventStore, } = useAppDataActions(); const { updateEditorState, updateQueryConfirmationList, setSelectedComponents, setCurrentPageId } = useEditorActions(); @@ -275,6 +276,15 @@ const EditorComponent = (props) => { } }, [currentLayout, mounted]); + useEffect(() => { + console.log('---arpit:::: event changed'); + props.ymap?.set('eventHandlersUpdated', { + updated: true, + currentVersionId: currentVersionId, + currentSessionId: currentSessionId, + }); + }, [JSON.stringify({ events })]); + const handleMessage = (event) => { const { data } = event; @@ -355,24 +365,37 @@ const EditorComponent = (props) => { // Observe changes in the 'appDef' property of the 'ymap' object props.ymap?.observeDeep(() => { const ymapUpdates = props.ymap?.get('appDef'); + const ymapEventHandlersUpdated = props.ymap?.get('eventHandlersUpdated'); - // Check if there is a new session and if others are on the same version and page - if (!ymapUpdates.currentSessionId || ymapUpdates.currentSessionId === currentSessionId) return; + if (ymapUpdates) { + // Check if there is a new session and if others are on the same version and page + if (!ymapUpdates.currentSessionId || ymapUpdates.currentSessionId === currentSessionId) return; - // Check if others are on the same version and page - if (!ymapUpdates.areOthersOnSameVersionAndPage) return; + // Check if others are on the same version and page + if (!ymapUpdates.areOthersOnSameVersionAndPage) return; - // Check if the new application definition is different from the current one - if (isEqual(appDefinition, ymapUpdates.newDefinition)) return; + // Check if the new application definition is different from the current one + if (isEqual(appDefinition, ymapUpdates.newDefinition)) return; - // Trigger real-time save with specific options - realtimeSave(props.ymap?.get('appDef').newDefinition, { - skipAutoSave: true, - skipYmapUpdate: true, - currentSessionId: ymapUpdates.currentSessionId, - componentAdding: ymapUpdates.componentAdding, - componentDeleting: ymapUpdates.componentDeleting, - }); + // Trigger real-time save with specific options + realtimeSave(props.ymap?.get('appDef').newDefinition, { + skipAutoSave: true, + skipYmapUpdate: true, + currentSessionId: ymapUpdates.currentSessionId, + componentAdding: ymapUpdates.componentAdding, + componentDeleting: ymapUpdates.componentDeleting, + }); + } + + if (ymapEventHandlersUpdated) { + if ( + !ymapEventHandlersUpdated.currentSessionId || + ymapEventHandlersUpdated.currentSessionId === currentSessionId + ) + return; + + autoUpdateEventStore(ymapEventHandlersUpdated.currentVersionId); + } }); }; diff --git a/frontend/src/_services/appVersion.service.js b/frontend/src/_services/appVersion.service.js index 3471c23fd7..85a462a855 100644 --- a/frontend/src/_services/appVersion.service.js +++ b/frontend/src/_services/appVersion.service.js @@ -170,7 +170,7 @@ function clonePage(appId, versionId, pageId) { ); } -function findAllEventsWithSourceId(appId, versionId, sourceId) { +function findAllEventsWithSourceId(appId, versionId, sourceId = undefined) { const requestOptions = { method: 'GET', headers: authHeader(), diff --git a/frontend/src/_stores/appDataStore.js b/frontend/src/_stores/appDataStore.js index 7af5264dc3..1f5d36870f 100644 --- a/frontend/src/_stores/appDataStore.js +++ b/frontend/src/_stores/appDataStore.js @@ -112,7 +112,12 @@ export const useAppDataStore = create( set(() => ({ events: updatedEvents })); } }, + autoUpdateEventStore: async (versionId) => { + const appId = get().appId; + const response = await appVersionService.findAllEventsWithSourceId(appId, versionId); + set(() => ({ events: response })); + }, setIsSaving: (isSaving) => set(() => ({ isSaving })), setAppId: (appId) => set(() => ({ appId })), setAppPreviewLink: (appVersionPreviewLink) => set(() => ({ appVersionPreviewLink })), diff --git a/server/src/controllers/apps.controller.v2.ts b/server/src/controllers/apps.controller.v2.ts index e2e0dd4e36..78fda8c12d 100644 --- a/server/src/controllers/apps.controller.v2.ts +++ b/server/src/controllers/apps.controller.v2.ts @@ -424,6 +424,10 @@ export class AppsControllerV2 { throw new ForbiddenException('You do not have permissions to perform this action'); } + if (!sourceId) { + return this.eventService.findEventsForVersion(versionId); + } + return this.eventService.findAllEventsWithSourceId(sourceId); }