mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 08:58:26 +00:00
event handlers sycned for multi-user
This commit is contained in:
parent
965882d31c
commit
242b86de6b
4 changed files with 47 additions and 15 deletions
|
|
@ -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);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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 })),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue