2019-09-09 10:30:22 +00:00
|
|
|
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";
|
2019-09-09 10:30:22 +00:00
|
|
|
import { ContainerWidgetProps } from "../../widgets/ContainerWidget";
|
2019-10-24 07:03:59 +00:00
|
|
|
import {
|
|
|
|
|
ReduxAction,
|
|
|
|
|
UpdateCanvasPayload,
|
2019-10-31 08:36:04 +00:00
|
|
|
PageListPayload,
|
2019-10-24 07:03:59 +00:00
|
|
|
} from "../../constants/ReduxActionConstants";
|
2019-09-27 16:05:33 +00:00
|
|
|
|
2019-09-26 11:11:28 +00:00
|
|
|
const editorConfigs = getEditorConfigs();
|
2019-09-17 15:09:55 +00:00
|
|
|
const initialState: EditorReduxState = {
|
|
|
|
|
pageWidgetId: "0",
|
2019-09-26 11:11:28 +00:00
|
|
|
...editorConfigs,
|
2019-10-31 08:36:04 +00:00
|
|
|
pages: [],
|
|
|
|
|
loadingStates: {
|
|
|
|
|
publishing: false,
|
|
|
|
|
publishingError: false,
|
|
|
|
|
saving: false,
|
|
|
|
|
savingError: false,
|
|
|
|
|
},
|
2019-09-17 15:09:55 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
const editorReducer = createReducer(initialState, {
|
2019-10-31 08:36:04 +00:00
|
|
|
[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 };
|
|
|
|
|
},
|
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
|
|
|
},
|
2019-10-24 07:03:59 +00:00
|
|
|
[ReduxActionTypes.UPDATE_CANVAS]: (
|
|
|
|
|
state: EditorReduxState,
|
|
|
|
|
action: ReduxAction<UpdateCanvasPayload>,
|
|
|
|
|
) => {
|
|
|
|
|
const {
|
|
|
|
|
currentPageId,
|
|
|
|
|
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,
|
|
|
|
|
currentPageId,
|
|
|
|
|
currentPageName,
|
|
|
|
|
currentLayoutId,
|
|
|
|
|
pageWidgetId,
|
|
|
|
|
currentApplicationId,
|
|
|
|
|
};
|
|
|
|
|
},
|
2019-09-09 10:30:22 +00:00
|
|
|
});
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
export interface EditorReduxState {
|
2019-09-19 22:25:37 +00:00
|
|
|
dsl?: ContainerWidgetProps<WidgetProps>;
|
2019-09-17 15:09:55 +00:00
|
|
|
pageWidgetId: string;
|
2019-09-18 10:48:56 +00:00
|
|
|
currentPageId: string;
|
|
|
|
|
currentLayoutId: string;
|
2019-09-27 08:08:31 +00:00
|
|
|
currentPageName: string;
|
2019-10-21 11:40:24 +00:00
|
|
|
propertyPaneConfigsId: string;
|
2019-10-24 07:03:59 +00:00
|
|
|
currentApplicationId?: string;
|
2019-10-31 08:36:04 +00:00
|
|
|
pages: PageListPayload;
|
|
|
|
|
loadingStates: {
|
|
|
|
|
saving: boolean;
|
|
|
|
|
savingError: boolean;
|
|
|
|
|
publishing: boolean;
|
|
|
|
|
publishingError: boolean;
|
|
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default editorReducer;
|