diff --git a/frontend/src/Editor/EditorFunc.jsx b/frontend/src/Editor/EditorFunc.jsx index 5542793b67..255e3bb690 100644 --- a/frontend/src/Editor/EditorFunc.jsx +++ b/frontend/src/Editor/EditorFunc.jsx @@ -887,9 +887,9 @@ const EditorComponent = (props) => { isSaving: false, }); } else if (!isEmpty(props?.editingVersion)) { - const componentDiff = computeAppDiff(appDefinitionDiff, currentPageId, appDiffOptions); + const updateDiff = computeAppDiff(appDefinitionDiff, currentPageId, appDiffOptions); - updateAppVersion(appId, props.editingVersion?.id, currentPageId, componentDiff, isUserSwitchedVersion) + updateAppVersion(appId, props.editingVersion?.id, currentPageId, updateDiff, isUserSwitchedVersion) .then(() => { const _editingVersion = { ...props.editingVersion, diff --git a/frontend/src/_stores/utils.js b/frontend/src/_stores/utils.js index 921d1b3515..a391055ce4 100644 --- a/frontend/src/_stores/utils.js +++ b/frontend/src/_stores/utils.js @@ -44,6 +44,25 @@ const updateType = Object.freeze({ }); export const computeAppDiff = (appDiff, currentPageId, opts) => { + const { updateDiff, type, operation } = updateFor(appDiff, currentPageId, opts); + + return { updateDiff, type, operation }; +}; + +const updateFor = (appDiff, currentPageId, opts) => { + const componentUpdates = ['componentAdded', 'componentDefinitionChanged', 'componentDeleted', 'containerChanges']; + const pageUpdates = ['pageDefinitionChanged', 'pageSortingChanged', 'deletePageRequest', 'addNewPage']; + + const options = _.keys(opts); + + if (_.intersection(options, componentUpdates).length > 0) { + return computeComponentDiff(appDiff, currentPageId, opts); + } else if (_.intersection(options, pageUpdates).length > 0) { + return computePageUpdate(appDiff, currentPageId, opts); + } +}; + +const computePageUpdate = (appDiff, currentPageId, opts) => { let type; let updateDiff; let operation = 'update'; @@ -73,7 +92,17 @@ export const computeAppDiff = (appDiff, currentPageId, opts) => { if (opts?.addNewPage) { operation = 'create'; } - } else if (opts?.componentDeleted) { + } + + return { updateDiff, type, operation }; +}; + +const computeComponentDiff = (appDiff, currentPageId, opts) => { + let type; + let updateDiff; + let operation = 'update'; + + if (opts?.componentDeleted) { const currentPageComponents = appDiff?.pages[currentPageId]?.components; updateDiff = _.keys(currentPageComponents);