refactored computing types of diff in clientside

This commit is contained in:
arpitnath 2023-08-14 23:42:46 +05:30
parent c5167203f5
commit 4a8296faea
2 changed files with 32 additions and 3 deletions

View file

@ -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,

View file

@ -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);