mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-23 17:08:34 +00:00
refactored computing types of diff in clientside
This commit is contained in:
parent
c5167203f5
commit
4a8296faea
2 changed files with 32 additions and 3 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Reference in a new issue