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

105 lines
3.0 KiB
TypeScript
Raw Normal View History

import { createReducer } from "../../utils/AppsmithUtils";
2019-09-26 11:11:28 +00:00
import { getEditorConfigs } from "../../constants/ApiConstants";
2019-10-18 08:16:26 +00:00
import { ReduxActionTypes } from "../../constants/ReduxActionConstants";
import { WidgetProps } from "../../widgets/BaseWidget";
import { ContainerWidgetProps } from "../../widgets/ContainerWidget";
import {
ReduxAction,
UpdateCanvasPayload,
PageListPayload,
} from "../../constants/ReduxActionConstants";
2019-09-27 16:05:33 +00:00
2019-09-26 11:11:28 +00:00
const editorConfigs = getEditorConfigs();
const initialState: EditorReduxState = {
pageWidgetId: "0",
2019-09-26 11:11:28 +00:00
...editorConfigs,
pages: [],
loadingStates: {
publishing: false,
publishingError: false,
saving: false,
savingError: false,
},
};
2019-08-26 12:41:21 +00:00
const editorReducer = createReducer(initialState, {
[ReduxActionTypes.PUBLISH_APPLICATION_INIT]: (state: EditorReduxState) => {
state.loadingStates.publishing = true;
state.loadingStates.publishingError = false;
return { ...state };
},
[ReduxActionTypes.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;
return { ...state };
},
[ReduxActionTypes.FETCH_PAGE_LIST_SUCCESS]: (
state: EditorReduxState,
action: ReduxAction<PageListPayload>,
) => {
return { ...state, pages: action.payload };
},
[ReduxActionTypes.CREATE_PAGE_SUCCESS]: (
state: EditorReduxState,
action: ReduxAction<{ pageName: string; pageId: string; layoutId: string }>,
) => {
state.pages.push(action.payload);
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 };
},
[ReduxActionTypes.UPDATE_CANVAS]: (
state: EditorReduxState,
action: ReduxAction<UpdateCanvasPayload>,
) => {
const {
currentPageId,
currentPageName,
currentLayoutId,
pageWidgetId,
currentApplicationId,
} = action.payload;
state.loadingStates.publishing = false;
state.loadingStates.publishingError = false;
return {
...state,
currentPageId,
currentPageName,
currentLayoutId,
pageWidgetId,
currentApplicationId,
};
},
});
2019-08-26 12:41:21 +00:00
export interface EditorReduxState {
dsl?: ContainerWidgetProps<WidgetProps>;
pageWidgetId: string;
currentPageId: string;
currentLayoutId: string;
currentPageName: string;
propertyPaneConfigsId: string;
currentApplicationId?: string;
pages: PageListPayload;
loadingStates: {
saving: boolean;
savingError: boolean;
publishing: boolean;
publishingError: boolean;
};
2019-08-26 12:41:21 +00:00
}
export default editorReducer;