PromucFlow_constructor/app/client/src/reducers/entityReducers/widgetConfigReducer.tsx

93 lines
4.0 KiB
TypeScript
Raw Normal View History

2019-11-25 05:07:27 +00:00
import { createReducer } from "utils/AppsmithUtils";
import { ReduxActionTypes, ReduxAction } from "constants/ReduxActionConstants";
import { WidgetProps } from "widgets/BaseWidget";
import WidgetConfigResponse from "mockResponses/WidgetConfigResponse";
import { ButtonWidgetProps } from "widgets/ButtonWidget";
import { TextWidgetProps } from "widgets/TextWidget";
import { ContainerWidgetProps } from "widgets/ContainerWidget";
import { ImageWidgetProps } from "widgets/ImageWidget";
import { InputWidgetProps } from "widgets/InputWidget";
2020-03-20 11:17:30 +00:00
import { RichTextEditorWidgetProps } from "widgets/RichTextEditorWidget";
2020-03-13 12:06:41 +00:00
import { DatePickerWidgetProps } from "../../widgets/DatePickerWidget";
import { TableWidgetProps } from "../../widgets/TableWidget/TableWidgetConstants";
2020-03-13 12:06:41 +00:00
import { DropdownWidgetProps } from "../../widgets/DropdownWidget";
import { CheckboxWidgetProps } from "../../widgets/CheckboxWidget";
import { RadioGroupWidgetProps } from "../../widgets/RadioGroupWidget";
import { AlertWidgetProps } from "../../widgets/AlertWidget";
import { FilePickerWidgetProps } from "../../widgets/FilepickerWidget";
2020-04-15 11:42:11 +00:00
import {
TabsWidgetProps,
TabContainerWidgetProps,
} from "../../widgets/TabsWidget";
2020-03-13 12:06:41 +00:00
import { ChartWidgetProps } from "../../widgets/ChartWidget";
2020-03-06 09:45:21 +00:00
import { FormWidgetProps } from "widgets/FormWidget";
import { FormButtonWidgetProps } from "widgets/FormButtonWidget";
2020-04-15 11:42:11 +00:00
import { MapWidgetProps } from "widgets/MapWidget";
import { ModalWidgetProps } from "widgets/ModalWidget";
import { IconWidgetProps } from "widgets/IconWidget";
import { VideoWidgetProps } from "widgets/VideoWidget";
import { SkeletonWidgetProps } from "../../widgets/SkeletonWidget";
2019-09-12 08:11:25 +00:00
const initialState: WidgetConfigReducerState = WidgetConfigResponse;
2019-09-12 08:11:25 +00:00
2020-03-06 09:45:21 +00:00
export type WidgetBlueprint = {
view?: Array<{
2020-03-06 09:45:21 +00:00
type: string;
size?: { rows: number; cols: number };
2020-03-06 09:45:21 +00:00
position: { top?: number; left?: number };
props: Record<string, any>;
}>;
operations?: any;
2020-03-06 09:45:21 +00:00
};
2019-09-12 08:11:25 +00:00
export interface WidgetConfigProps {
rows: number;
columns: number;
2020-03-06 09:45:21 +00:00
blueprint?: WidgetBlueprint;
2020-04-03 09:32:13 +00:00
widgetName: string;
2019-09-12 08:11:25 +00:00
}
export interface WidgetConfigReducerState {
config: {
BUTTON_WIDGET: Partial<ButtonWidgetProps> & WidgetConfigProps;
TEXT_WIDGET: Partial<TextWidgetProps> & WidgetConfigProps;
IMAGE_WIDGET: Partial<ImageWidgetProps> & WidgetConfigProps;
INPUT_WIDGET: Partial<InputWidgetProps> & WidgetConfigProps;
2020-03-20 11:17:30 +00:00
RICH_TEXT_EDITOR_WIDGET: Partial<RichTextEditorWidgetProps> &
WidgetConfigProps;
CONTAINER_WIDGET: Partial<ContainerWidgetProps<WidgetProps>> &
WidgetConfigProps;
DATE_PICKER_WIDGET: Partial<DatePickerWidgetProps> & WidgetConfigProps;
TABLE_WIDGET: Partial<TableWidgetProps> & WidgetConfigProps;
VIDEO_WIDGET: Partial<VideoWidgetProps> & WidgetConfigProps;
DROP_DOWN_WIDGET: Partial<DropdownWidgetProps> & WidgetConfigProps;
CHECKBOX_WIDGET: Partial<CheckboxWidgetProps> & WidgetConfigProps;
RADIO_GROUP_WIDGET: Partial<RadioGroupWidgetProps> & WidgetConfigProps;
ALERT_WIDGET: Partial<AlertWidgetProps> & WidgetConfigProps;
2019-11-05 05:09:50 +00:00
FILE_PICKER_WIDGET: Partial<FilePickerWidgetProps> & WidgetConfigProps;
2020-04-15 11:42:11 +00:00
TABS_WIDGET: Partial<TabsWidgetProps<TabContainerWidgetProps>> &
WidgetConfigProps;
MODAL_WIDGET: Partial<ModalWidgetProps> & WidgetConfigProps;
2020-03-13 12:06:41 +00:00
CHART_WIDGET: Partial<ChartWidgetProps> & WidgetConfigProps;
2020-03-06 09:45:21 +00:00
FORM_WIDGET: Partial<FormWidgetProps> & WidgetConfigProps;
FORM_BUTTON_WIDGET: Partial<FormButtonWidgetProps> & WidgetConfigProps;
2020-04-15 11:42:11 +00:00
MAP_WIDGET: Partial<MapWidgetProps> & WidgetConfigProps;
CANVAS_WIDGET: Partial<ContainerWidgetProps<WidgetProps>> &
WidgetConfigProps;
ICON_WIDGET: Partial<IconWidgetProps> & WidgetConfigProps;
SKELETON_WIDGET: Partial<SkeletonWidgetProps> & WidgetConfigProps;
};
configVersion: number;
2019-09-12 08:11:25 +00:00
}
const widgetConfigReducer = createReducer(initialState, {
[ReduxActionTypes.LOAD_WIDGET_CONFIG]: (
2019-09-12 08:11:25 +00:00
state: WidgetConfigReducerState,
action: ReduxAction<WidgetConfigReducerState>,
2019-09-12 08:11:25 +00:00
) => {
return { ...action.payload };
},
});
2019-09-12 08:11:25 +00:00
export default widgetConfigReducer;