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-08-26 12:41:21 +00:00
|
|
|
import {
|
2019-09-12 11:19:38 +00:00
|
|
|
ReduxActionTypes,
|
2019-08-26 12:41:21 +00:00
|
|
|
ReduxAction,
|
2019-09-09 10:30:22 +00:00
|
|
|
LoadWidgetCardsPanePayload,
|
2019-09-13 11:59:45 +00:00
|
|
|
} from "../../constants/ReduxActionConstants";
|
|
|
|
|
import { WidgetCardProps, WidgetProps } from "../../widgets/BaseWidget";
|
2019-09-09 10:30:22 +00:00
|
|
|
import { ContainerWidgetProps } from "../../widgets/ContainerWidget";
|
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-09-23 10:27:45 +00:00
|
|
|
isSaving: false,
|
2019-09-17 15:09:55 +00:00
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
|
|
|
|
const editorReducer = createReducer(initialState, {
|
2019-09-12 11:19:38 +00:00
|
|
|
[ReduxActionTypes.SUCCESS_FETCHING_WIDGET_CARDS]: (
|
2019-08-26 12:41:21 +00:00
|
|
|
state: EditorReduxState,
|
2019-09-09 10:30:22 +00:00
|
|
|
action: ReduxAction<LoadWidgetCardsPanePayload>,
|
2019-08-26 12:41:21 +00:00
|
|
|
) => {
|
2019-09-22 20:25:05 +00:00
|
|
|
return { ...state, ...action.payload };
|
2019-08-26 12:41:21 +00:00
|
|
|
},
|
2019-09-23 10:27:45 +00:00
|
|
|
[ReduxActionTypes.SAVE_PAGE_INIT]: (state: EditorReduxState) => {
|
|
|
|
|
return { ...state, isSaving: true };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.SAVE_PAGE_SUCCESS]: (state: EditorReduxState) => {
|
|
|
|
|
return { ...state, isSaving: false };
|
|
|
|
|
},
|
|
|
|
|
[ReduxActionTypes.SAVE_PAGE_ERROR]: (state: EditorReduxState) => {
|
|
|
|
|
return { ...state, isSaving: false };
|
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-08-26 12:41:21 +00:00
|
|
|
cards?: {
|
2019-09-06 09:30:22 +00:00
|
|
|
[id: string]: WidgetCardProps[];
|
2019-09-02 10:58:11 +00:00
|
|
|
};
|
2019-09-17 15:09:55 +00:00
|
|
|
pageWidgetId: string;
|
2019-09-18 10:48:56 +00:00
|
|
|
currentPageId: string;
|
|
|
|
|
currentLayoutId: string;
|
2019-09-23 10:27:45 +00:00
|
|
|
isSaving: boolean;
|
2019-08-26 12:41:21 +00:00
|
|
|
}
|
|
|
|
|
|
2019-09-09 10:30:22 +00:00
|
|
|
export default editorReducer;
|