PromucFlow_constructor/app/client/src/reducers/uiReducers/editorReducer.tsx

194 lines
5.8 KiB
TypeScript
Raw Normal View History

2019-11-25 05:07:27 +00:00
import { createReducer } from "utils/AppsmithUtils";
import {
2019-12-16 08:49:10 +00:00
ReduxAction,
UpdateCanvasPayload,
ReduxActionTypes,
ReduxActionErrorTypes,
2019-11-25 05:07:27 +00:00
} from "constants/ReduxActionConstants";
import moment from "moment";
2019-09-27 16:05:33 +00:00
const initialState: EditorReduxState = {
2020-01-24 09:54:40 +00:00
initialized: false,
loadingStates: {
publishing: false,
publishingError: false,
saving: false,
savingError: false,
loading: false,
loadingError: false,
pageSwitchingError: false,
isPageSwitching: false,
2020-01-27 08:24:58 +00:00
creatingPage: false,
creatingPageError: false,
cloningPage: false,
cloningPageError: false,
2020-02-21 12:16:49 +00:00
updatingWidgetName: false,
updateWidgetNameError: false,
},
};
2019-08-26 12:41:21 +00:00
const editorReducer = createReducer(initialState, {
2021-03-08 08:24:12 +00:00
[ReduxActionTypes.RESET_EDITOR_SUCCESS]: (state: EditorReduxState) => {
return { ...state, initialized: false };
},
2020-01-24 09:54:40 +00:00
[ReduxActionTypes.INITIALIZE_EDITOR_SUCCESS]: (state: EditorReduxState) => {
return { ...state, initialized: true };
},
[ReduxActionTypes.UPDATE_PAGE_SUCCESS]: (
state: EditorReduxState,
action: ReduxAction<{ id: string; name: string }>,
) => {
if (action.payload.id === state.currentPageId) {
return { ...state, currentPageName: action.payload.name };
}
return state;
},
[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,
},
}),
[ReduxActionTypes.PUBLISH_APPLICATION_INIT]: (state: EditorReduxState) => {
state.loadingStates.publishing = true;
state.loadingStates.publishingError = false;
return { ...state };
},
[ReduxActionErrorTypes.PUBLISH_APPLICATION_ERROR]: (
state: EditorReduxState,
) => {
state.loadingStates.publishing = false;
state.loadingStates.publishingError = true;
return { ...state };
},
[ReduxActionTypes.PUBLISH_APPLICATION_SUCCESS]: (state: EditorReduxState) => {
state.loadingStates.publishing = false;
state.loadingStates.publishingError = false;
state.loadingStates.published = moment().format();
return { ...state };
},
[ReduxActionTypes.SAVE_PAGE_INIT]: (state: EditorReduxState) => {
state.loadingStates.saving = true;
state.loadingStates.savingError = false;
return { ...state };
},
[ReduxActionTypes.SAVE_PAGE_SUCCESS]: (state: EditorReduxState) => {
state.loadingStates.saving = false;
return { ...state };
},
[ReduxActionErrorTypes.SAVE_PAGE_ERROR]: (state: EditorReduxState) => {
state.loadingStates.saving = false;
state.loadingStates.savingError = true;
return { ...state };
},
[ReduxActionTypes.INIT_CANVAS_LAYOUT]: (
state: EditorReduxState,
action: ReduxAction<UpdateCanvasPayload>,
) => {
const {
currentPageName,
currentLayoutId,
pageWidgetId,
currentApplicationId,
currentPageId,
} = action.payload;
state.loadingStates.publishing = false;
state.loadingStates.publishingError = false;
return {
...state,
currentPageName,
currentLayoutId,
pageWidgetId,
currentApplicationId,
currentPageId,
};
},
[ReduxActionTypes.CLONE_PAGE_INIT]: (state: EditorReduxState) => {
state.loadingStates.cloningPage = true;
state.loadingStates.cloningPageError = false;
return { ...state };
},
[ReduxActionTypes.CLONE_PAGE_ERROR]: (state: EditorReduxState) => {
state.loadingStates.cloningPageError = true;
state.loadingStates.cloningPage = false;
return { ...state };
},
[ReduxActionTypes.CLONE_PAGE_SUCCESS]: (state: EditorReduxState) => {
state.loadingStates.cloningPage = false;
return { ...state };
},
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-08-26 12:41:21 +00:00
export interface EditorReduxState {
2020-01-24 09:54:40 +00:00
initialized: boolean;
pageWidgetId?: string;
currentLayoutId?: string;
currentPageName?: string;
currentPageId?: string;
loadingStates: {
saving: boolean;
savingError: boolean;
publishing: boolean;
published?: string;
publishingError: boolean;
loading: boolean;
loadingError: boolean;
isPageSwitching: boolean;
pageSwitchingError: boolean;
2020-01-27 08:24:58 +00:00
creatingPage: boolean;
creatingPageError: boolean;
cloningPage: boolean;
cloningPageError: boolean;
2020-02-21 12:16:49 +00:00
updatingWidgetName: boolean;
updateWidgetNameError: boolean;
};
2019-08-26 12:41:21 +00:00
}
export default editorReducer;