mirror of
https://github.com/ToolJet/ToolJet
synced 2026-05-24 09:28:31 +00:00
update the saving state
This commit is contained in:
parent
03b31ee59e
commit
30d0bd4912
4 changed files with 45 additions and 39 deletions
|
|
@ -101,7 +101,7 @@ const EditorComponent = (props) => {
|
|||
currentLayout,
|
||||
canUndo,
|
||||
canRedo,
|
||||
isSaving,
|
||||
isUpdatingEditorStateInProcess,
|
||||
saveError,
|
||||
scrollOptions,
|
||||
currentSidebarTab,
|
||||
|
|
@ -227,7 +227,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
computeComponentState(components);
|
||||
|
||||
if (isSaving) {
|
||||
if (isUpdatingEditorStateInProcess) {
|
||||
autoSave();
|
||||
}
|
||||
}
|
||||
|
|
@ -612,7 +612,7 @@ const EditorComponent = (props) => {
|
|||
}
|
||||
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
appDefinitionChanged(newAppDefinition, {
|
||||
|
|
@ -715,7 +715,7 @@ const EditorComponent = (props) => {
|
|||
useAppVersionStore.getState().actions.updateEditingVersion(version);
|
||||
|
||||
updateEditorState({
|
||||
isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
});
|
||||
|
||||
shouldWeEditVersion && saveEditingVersion(true);
|
||||
|
|
@ -745,7 +745,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
return new Promise((resolve) => {
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
resolve();
|
||||
|
|
@ -793,7 +793,7 @@ const EditorComponent = (props) => {
|
|||
appDiffOptions: opts,
|
||||
});
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
appDefinition: updatedAppDefinition,
|
||||
});
|
||||
|
||||
|
|
@ -808,7 +808,7 @@ const EditorComponent = (props) => {
|
|||
const saveEditingVersion = (isUserSwitchedVersion = false) => {
|
||||
if (props.isVersionReleased && !isUserSwitchedVersion) {
|
||||
updateEditorState({
|
||||
isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
});
|
||||
} else if (!isEmpty(props?.editingVersion)) {
|
||||
const updateDiff = computeAppDiff(appDefinitionDiff, currentPageId, appDiffOptions);
|
||||
|
|
@ -835,13 +835,13 @@ const EditorComponent = (props) => {
|
|||
|
||||
updateEditorState({
|
||||
saveError: false,
|
||||
isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
});
|
||||
})
|
||||
.catch(() => {
|
||||
updateEditorState({
|
||||
saveError: true,
|
||||
isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
});
|
||||
toast.error('App could not save.');
|
||||
});
|
||||
|
|
@ -849,7 +849,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
updateEditorState({
|
||||
saveError: false,
|
||||
isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
});
|
||||
};
|
||||
|
||||
|
|
@ -897,10 +897,8 @@ const EditorComponent = (props) => {
|
|||
updateEditorState({
|
||||
appDefinition: updatedAppDefinition,
|
||||
currentSidebarTab: 2,
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
// autoSave();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -919,10 +917,8 @@ const EditorComponent = (props) => {
|
|||
|
||||
updateEditorState({
|
||||
appDefinition: updatedAppDefinition,
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
// autoSave();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -949,7 +945,7 @@ const EditorComponent = (props) => {
|
|||
componentDefinition.component;
|
||||
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const diffPatches = diff(appDefinition, updatedAppDefinition);
|
||||
|
|
@ -1228,7 +1224,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
setCurrentPageId(newCurrentPageId);
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
setIsDeletingPage(false);
|
||||
|
||||
|
|
@ -1244,7 +1240,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
const hidePage = (pageId) => {
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
|
@ -1260,7 +1256,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
const unHidePage = (pageId) => {
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
|
@ -1278,7 +1274,7 @@ const EditorComponent = (props) => {
|
|||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const currentPage = copyOfAppDefinition.pages[pageId];
|
||||
|
|
@ -1347,7 +1343,7 @@ const EditorComponent = (props) => {
|
|||
|
||||
const updateHomePage = (pageId) => {
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
|
@ -1365,7 +1361,7 @@ const EditorComponent = (props) => {
|
|||
const copyOfAppDefinition = JSON.parse(JSON.stringify(appDefinition));
|
||||
|
||||
updateEditorState({
|
||||
isSaving: true,
|
||||
isUpdatingEditorStateInProcess: true,
|
||||
});
|
||||
|
||||
const pageExists = Object.values(copyOfAppDefinition.pages).some((page) => page.handle === newHandle);
|
||||
|
|
@ -1480,7 +1476,6 @@ const EditorComponent = (props) => {
|
|||
canRedo={canRedo}
|
||||
handleUndo={handleUndo}
|
||||
handleRedo={handleRedo}
|
||||
isSaving={isSaving}
|
||||
saveError={saveError}
|
||||
onNameChanged={onNameChanged}
|
||||
setAppDefinitionFromVersion={setAppDefinitionFromVersion}
|
||||
|
|
@ -1516,7 +1511,7 @@ const EditorComponent = (props) => {
|
|||
removeComponent={removeComponent}
|
||||
runQuery={(queryId, queryName) => handleRunQuery(queryId, queryName)}
|
||||
ref={dataSourceModalRef}
|
||||
isSaving={isSaving}
|
||||
isSaving={isUpdatingEditorStateInProcess}
|
||||
currentPageId={currentPageId}
|
||||
addNewPage={addNewPage}
|
||||
switchPage={switchPage}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import config from 'config';
|
|||
import { useUpdatePresence } from '@y-presence/react';
|
||||
import { useAppVersionStore } from '@/_stores/appVersionStore';
|
||||
import { shallow } from 'zustand/shallow';
|
||||
import { useAppDataActions, useCurrentUser } from '@/_stores/appDataStore';
|
||||
import { useAppDataActions, useAppInfo, useCurrentUser } from '@/_stores/appDataStore';
|
||||
|
||||
export default function EditorHeader({
|
||||
darkMode,
|
||||
|
|
@ -27,7 +27,6 @@ export default function EditorHeader({
|
|||
canRedo,
|
||||
handleUndo,
|
||||
handleRedo,
|
||||
isSaving,
|
||||
saveError,
|
||||
onNameChanged,
|
||||
setAppDefinitionFromVersion,
|
||||
|
|
@ -42,6 +41,7 @@ export default function EditorHeader({
|
|||
const currentUser = useCurrentUser();
|
||||
|
||||
const { updateState } = useAppDataActions();
|
||||
const { isSaving } = useAppInfo();
|
||||
|
||||
const handleSlugChange = (newSlug) => {
|
||||
updateState({ slug: newSlug });
|
||||
|
|
|
|||
|
|
@ -33,23 +33,30 @@ export const useAppDataStore = create(
|
|||
updateApps: (apps) => set(() => ({ apps: apps })),
|
||||
updateState: (state) => set((prev) => ({ ...prev, ...state })),
|
||||
updateAppDefinitionDiff: (appDefinitionDiff) => set(() => ({ appDefinitionDiff: appDefinitionDiff })),
|
||||
updateAppVersion: async (appId, versionId, pageId, appDefinitionDiff, isUserSwitchedVersion = false) => {
|
||||
return await appVersionService.autoSaveApp(
|
||||
appId,
|
||||
versionId,
|
||||
appDefinitionDiff.updateDiff,
|
||||
appDefinitionDiff.type,
|
||||
pageId,
|
||||
appDefinitionDiff.operation,
|
||||
isUserSwitchedVersion
|
||||
);
|
||||
updateAppVersion: (appId, versionId, pageId, appDefinitionDiff, isUserSwitchedVersion = false) => {
|
||||
useAppDataStore.getState().actions.setIsSaving(true);
|
||||
appVersionService
|
||||
.autoSaveApp(
|
||||
appId,
|
||||
versionId,
|
||||
appDefinitionDiff.updateDiff,
|
||||
appDefinitionDiff.type,
|
||||
pageId,
|
||||
appDefinitionDiff.operation,
|
||||
isUserSwitchedVersion
|
||||
)
|
||||
.then(() => {
|
||||
useAppDataStore.getState().actions.setIsSaving(false);
|
||||
});
|
||||
},
|
||||
updateAppVersionEventHandlers: async (events) => {
|
||||
useAppDataStore.getState().actions.setIsSaving(true);
|
||||
const appId = get().appId;
|
||||
const versionId = get().currentVersionId;
|
||||
|
||||
const response = await appVersionService.saveAppVersionEventHandlers(appId, versionId, events);
|
||||
|
||||
useAppDataStore.getState().actions.setIsSaving(false);
|
||||
const updatedEvents = get().events;
|
||||
|
||||
updatedEvents.forEach((e, index) => {
|
||||
|
|
@ -62,24 +69,27 @@ export const useAppDataStore = create(
|
|||
},
|
||||
|
||||
createAppVersionEventHandlers: async (event) => {
|
||||
useAppDataStore.getState().actions.setIsSaving(true);
|
||||
const appId = get().appId;
|
||||
const versionId = get().currentVersionId;
|
||||
|
||||
const updatedEvents = get().events;
|
||||
const response = await appVersionService.createAppVersionEventHandler(appId, versionId, event);
|
||||
useAppDataStore.getState().actions.setIsSaving(false);
|
||||
updatedEvents.push(response);
|
||||
|
||||
set(() => ({ events: updatedEvents }));
|
||||
},
|
||||
|
||||
deleteAppVersionEventHandler: async (eventId) => {
|
||||
useAppDataStore.getState().actions.setIsSaving(true);
|
||||
const appId = get().appId;
|
||||
const versionId = get().currentVersionId;
|
||||
|
||||
const updatedEvents = get().events;
|
||||
|
||||
const response = await appVersionService.deleteAppVersionEventHandler(appId, versionId, eventId);
|
||||
|
||||
useAppDataStore.getState().actions.setIsSaving(false);
|
||||
if (response?.affected === 1) {
|
||||
updatedEvents.splice(
|
||||
updatedEvents.findIndex((e) => e.id === eventId),
|
||||
|
|
|
|||
|
|
@ -17,7 +17,8 @@ const initialState = {
|
|||
currentVersion: {},
|
||||
noOfVersionsSupported: 100,
|
||||
appDefinition: {},
|
||||
isSaving: false,
|
||||
// isSaving: false,
|
||||
isUpdatingEditorStateInProcess: false,
|
||||
saveError: false,
|
||||
isLoading: true,
|
||||
defaultComponentStateComputed: false,
|
||||
|
|
|
|||
Loading…
Reference in a new issue