handle error on saving changes

This commit is contained in:
arpitnath 2023-10-23 22:31:09 +05:30
parent 2a16b341e7
commit 856b7a26a5
3 changed files with 64 additions and 40 deletions

View file

@ -913,6 +913,21 @@ const EditorComponent = (props) => {
const paramDiff = computeComponentPropertyDiff(appDefinitionDiff, appDefinition, appDiffOptions); const paramDiff = computeComponentPropertyDiff(appDefinitionDiff, appDefinition, appDiffOptions);
const updateDiff = computeAppDiff(paramDiff, currentPageId, appDiffOptions, currentLayout); const updateDiff = computeAppDiff(paramDiff, currentPageId, appDiffOptions, currentLayout);
if (updateDiff['error']) {
const platform = navigator?.userAgentData?.platform || navigator?.platform || 'unknown';
const isPlatformMac = platform.toLowerCase().indexOf('mac') > -1;
const toastMessage = `Unable to save changes! ${isPlatformMac ? '(⌘ + Z to undo)' : '(ctrl + Z to undo)'}`;
toast(toastMessage, {
icon: '🚫',
});
return updateEditorState({
saveError: true,
isUpdatingEditorStateInProcess: false,
});
}
updateAppVersion(appId, editingVersion?.id, currentPageId, updateDiff, isUserSwitchedVersion) updateAppVersion(appId, editingVersion?.id, currentPageId, updateDiff, isUserSwitchedVersion)
.then(() => { .then(() => {
const _editingVersion = { const _editingVersion = {

View file

@ -1184,56 +1184,61 @@ a more efficient approach, precomputing the parent component types and using
conditional checks for better performance and error handling.*/ conditional checks for better performance and error handling.*/
export function computeComponentState(components = {}) { export function computeComponentState(components = {}) {
let componentState = {}; try {
const currentComponents = getCurrentState().components; let componentState = {};
const currentComponents = getCurrentState().components;
// Precompute parent component types // Precompute parent component types
const parentComponentTypes = {}; const parentComponentTypes = {};
Object.keys(components).forEach((key) => { Object.keys(components).forEach((key) => {
const { component } = components[key]; const { component } = components[key];
parentComponentTypes[key] = component.component; parentComponentTypes[key] = component.component;
}); });
Object.keys(components).forEach((key) => { Object.keys(components).forEach((key) => {
if (!components[key]) return; if (!components[key]) return;
const { component } = components[key]; const { component } = components[key];
const componentMeta = componentTypes.find((comp) => component.component === comp.component); const componentMeta = componentTypes.find((comp) => component.component === comp.component);
const existingComponentName = Object.keys(currentComponents).find((comp) => currentComponents[comp].id === key); const existingComponentName = Object.keys(currentComponents).find((comp) => currentComponents[comp].id === key);
const existingValues = currentComponents[existingComponentName]; const existingValues = currentComponents[existingComponentName];
if (component.parent) { if (component.parent) {
const parentComponentType = parentComponentTypes[component.parent]; const parentComponentType = parentComponentTypes[component.parent];
if (parentComponentType !== 'Listview' && parentComponentType !== 'Form') { if (parentComponentType !== 'Listview' && parentComponentType !== 'Form') {
componentState[component.name] = {
...componentMeta.exposedVariables,
id: key,
...existingValues,
};
}
} else {
componentState[component.name] = { componentState[component.name] = {
...componentMeta.exposedVariables, ...componentMeta.exposedVariables,
id: key, id: key,
...existingValues, ...existingValues,
}; };
} }
} else {
componentState[component.name] = {
...componentMeta.exposedVariables,
id: key,
...existingValues,
};
}
});
useCurrentStateStore.getState().actions.setCurrentState({
components: {
...componentState,
},
});
return new Promise((resolve) => {
useEditorStore.getState().actions.updateEditorState({
defaultComponentStateComputed: true,
}); });
resolve();
}); useCurrentStateStore.getState().actions.setCurrentState({
components: {
...componentState,
},
});
return new Promise((resolve) => {
useEditorStore.getState().actions.updateEditorState({
defaultComponentStateComputed: true,
});
resolve();
});
} catch (error) {
console.log(error);
return Promise.reject(error);
}
} }
export const getSvgIcon = (key, height = 50, width = 50, iconFile = undefined, styles = {}) => { export const getSvgIcon = (key, height = 50, width = 50, iconFile = undefined, styles = {}) => {

View file

@ -47,9 +47,9 @@ const updateType = Object.freeze({
}); });
export const computeAppDiff = (appDiff, currentPageId, opts, currentLayout) => { export const computeAppDiff = (appDiff, currentPageId, opts, currentLayout) => {
const { updateDiff, type, operation } = updateFor(appDiff, currentPageId, opts, currentLayout); const { updateDiff, type, operation, error } = updateFor(appDiff, currentPageId, opts, currentLayout);
return { updateDiff, type, operation }; return { updateDiff, type, operation, error };
}; };
// for table column diffs, we need to compute the diff for each column separately and send the the entire column data // for table column diffs, we need to compute the diff for each column separately and send the the entire column data
@ -170,7 +170,11 @@ const updateFor = (appDiff, currentPageId, opts, currentLayout) => {
const optionsTypes = _.intersection(options, updateTypes); const optionsTypes = _.intersection(options, updateTypes);
if (optionsTypes.length > 0) { if (optionsTypes.length > 0) {
return processingFunction(appDiff, currentPageId, optionsTypes, currentLayout); try {
return processingFunction(appDiff, currentPageId, optionsTypes, currentLayout);
} catch (error) {
return { error, updateDiff: {}, type: null, operation: null };
}
} }
} }