2019-11-25 05:07:27 +00:00
|
|
|
import { createReducer } from "utils/AppsmithUtils";
|
2019-11-22 14:02:55 +00:00
|
|
|
import {
|
2019-12-16 08:49:10 +00:00
|
|
|
ReduxAction,
|
|
|
|
|
UpdateCanvasPayload,
|
2019-11-22 14:02:55 +00:00
|
|
|
ReduxActionTypes,
|
|
|
|
|
ReduxActionErrorTypes,
|
2019-11-25 05:07:27 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
|
import { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import { ContainerWidgetProps } from "widgets/ContainerWidget";
|
2019-11-22 14:02:55 +00:00
|
|
|
import moment from "moment";
|
2019-09-27 16:05:33 +00:00
|
|
|
|
2019-09-17 15:09:55 +00:00
|
|
|
const initialState: EditorReduxState = {
|
2020-01-24 09:54:40 +00:00
|
|
|
initialized: false,
|
2019-10-31 08:36:04 +00:00
|
|
|
loadingStates: {
|
|
|
|
|
publishing: false,
|
|
|
|
|
publishingError: false,
|
|
|
|
|
saving: false,
|
|
|
|
|
savingError: false,
|
2019-11-22 14:02:55 +00:00
|
|
|
loading: false,
|
|
|
|
|
loadingError: false,
|
|
|
|
|
pageSwitchingError: false,
|
|
|
|
|
isPageSwitching: false,
|
2020-01-27 08:24:58 +00:00
|
|
|
creatingPage: false,
|
|
|
|
|
creatingPageError: false,
|
2020-02-21 12:16:49 +00:00
|
|
|
updatingWidgetName: false,
|
|
|
|
|
updateWidgetNameError: false,
|
2019-10-31 08:36:04 +00:00
|
|
|
},
|
2019-09-17 15:09:55 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
const editorReducer = createReducer(initialState, {
|
2020-01-24 09:54:40 +00:00
|
|
|
[ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS]: (state: EditorReduxState) => {
|
|
|
|
|
return { ...state, initialized: true };
|
|
|
|
|
},
|
2019-11-22 14:02:55 +00:00
|
|
|
[ReduxActionTypes.FETCH_PAGE_INIT]: (state: EditorReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
loadingStates: {
|
|
|
|
|
...state.loadingStates,
|
|
|
|
|
isPageSwitching: true,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionTypes.FETCH_PAGE_SUCCESS]: (state: EditorReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
loadingStates: {
|
|
|
|
|
...state.loadingStates,
|
|
|
|
|
isPageSwitching: false,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.FETCH_PAGE_ERROR]: (state: EditorReduxState) => ({
|
|
|
|
|
...state,
|
|
|
|
|
loadingStates: {
|
|
|
|
|
...state.loadingStates,
|
|
|
|
|
isPageSwitching: false,
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
[ReduxActionErrorTypes.INITIALIZE_EDITOR_ERROR]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
) => {
|
|
|
|
|
state.loadingStates.loading = false;
|
|
|
|
|
state.loadingStates.loadingError = true;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
2019-10-31 08:36:04 +00:00
|
|
|
[ReduxActionTypes.PUBLISH_APPLICATION_INIT]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.publishing = true;
|
|
|
|
|
state.loadingStates.publishingError = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
2020-04-05 06:34:14 +00:00
|
|
|
[ReduxActionErrorTypes.PUBLISH_APPLICATION_ERROR]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
) => {
|
2019-10-31 08:36:04 +00:00
|
|
|
state.loadingStates.publishing = false;
|
|
|
|
|
state.loadingStates.publishingError = true;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.PUBLISH_APPLICATION_SUCCESS]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.publishing = false;
|
|
|
|
|
state.loadingStates.publishingError = false;
|
2019-11-22 14:02:55 +00:00
|
|
|
state.loadingStates.published = moment().format();
|
2019-10-31 08:36:04 +00:00
|
|
|
return { ...state };
|
|
|
|
|
},
|
2019-09-23 10:27:45 +00:00
|
|
|
[ReduxActionTypes.SAVE_PAGE_INIT]: (state: EditorReduxState) => {
|
2019-10-31 08:36:04 +00:00
|
|
|
state.loadingStates.saving = true;
|
|
|
|
|
state.loadingStates.savingError = false;
|
|
|
|
|
return { ...state };
|
2019-09-23 10:27:45 +00:00
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.SAVE_PAGE_SUCCESS]: (state: EditorReduxState) => {
|
2019-10-31 08:36:04 +00:00
|
|
|
state.loadingStates.saving = false;
|
|
|
|
|
return { ...state };
|
2019-09-23 10:27:45 +00:00
|
|
|
},
|
2020-04-05 06:34:14 +00:00
|
|
|
[ReduxActionTypes.SAVE_PAGE_ERROR]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.saving = false;
|
|
|
|
|
state.loadingStates.savingError = true;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
2019-10-24 07:03:59 +00:00
|
|
|
[ReduxActionTypes.UPDATE_CANVAS]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
action: ReduxAction<UpdateCanvasPayload>,
|
|
|
|
|
) => {
|
|
|
|
|
const {
|
|
|
|
|
currentPageName,
|
|
|
|
|
currentLayoutId,
|
|
|
|
|
pageWidgetId,
|
|
|
|
|
currentApplicationId,
|
|
|
|
|
} = action.payload;
|
2019-10-31 08:36:04 +00:00
|
|
|
state.loadingStates.publishing = false;
|
|
|
|
|
state.loadingStates.publishingError = false;
|
2019-10-24 07:03:59 +00:00
|
|
|
return {
|
|
|
|
|
...state,
|
|
|
|
|
currentPageName,
|
|
|
|
|
currentLayoutId,
|
|
|
|
|
pageWidgetId,
|
|
|
|
|
currentApplicationId,
|
|
|
|
|
};
|
|
|
|
|
},
|
2020-01-27 08:24:58 +00:00
|
|
|
[ReduxActionTypes.CREATE_PAGE_INIT]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.creatingPage = true;
|
|
|
|
|
state.loadingStates.creatingPageError = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionErrorTypes.CREATE_PAGE_ERROR]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.creatingPageError = true;
|
|
|
|
|
state.loadingStates.creatingPage = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.CREATE_PAGE_SUCCESS]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.creatingPage = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
2020-02-21 12:16:49 +00:00
|
|
|
[ReduxActionTypes.UPDATE_WIDGET_NAME_INIT]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.updatingWidgetName = true;
|
|
|
|
|
state.loadingStates.updateWidgetNameError = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.UPDATE_WIDGET_NAME_SUCCESS]: (state: EditorReduxState) => {
|
|
|
|
|
state.loadingStates.updatingWidgetName = false;
|
|
|
|
|
state.loadingStates.updateWidgetNameError = false;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionErrorTypes.UPDATE_WIDGET_NAME_ERROR]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
) => {
|
|
|
|
|
state.loadingStates.updatingWidgetName = false;
|
|
|
|
|
state.loadingStates.updateWidgetNameError = true;
|
|
|
|
|
return { ...state };
|
|
|
|
|
},
|
2019-09-09 10:30:22 +00:00
|
|
|
});
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
export interface EditorReduxState {
|
2020-01-24 09:54:40 +00:00
|
|
|
initialized: boolean;
|
2019-09-19 22:25:37 +00:00
|
|
|
dsl?: ContainerWidgetProps<WidgetProps>;
|
2019-11-22 14:02:55 +00:00
|
|
|
pageWidgetId?: string;
|
|
|
|
|
currentLayoutId?: string;
|
|
|
|
|
currentPageName?: string;
|
2019-10-31 08:36:04 +00:00
|
|
|
loadingStates: {
|
|
|
|
|
saving: boolean;
|
|
|
|
|
savingError: boolean;
|
|
|
|
|
publishing: boolean;
|
2019-11-26 10:45:46 +00:00
|
|
|
published?: string;
|
2019-10-31 08:36:04 +00:00
|
|
|
publishingError: boolean;
|
2019-11-22 14:02:55 +00:00
|
|
|
loading: boolean;
|
|
|
|
|
loadingError: boolean;
|
|
|
|
|
isPageSwitching: boolean;
|
|
|
|
|
pageSwitchingError: boolean;
|
2020-01-27 08:24:58 +00:00
|
|
|
creatingPage: boolean;
|
|
|
|
|
creatingPageError: boolean;
|
2020-02-21 12:16:49 +00:00
|
|
|
updatingWidgetName: boolean;
|
|
|
|
|
updateWidgetNameError: boolean;
|
2019-10-31 08:36:04 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default editorReducer;
|