2019-11-25 05:07:27 +00:00
|
|
|
import { FetchPageRequest } from "api/PageApi";
|
|
|
|
|
import { WidgetProps, WidgetOperation } from "widgets/BaseWidget";
|
|
|
|
|
import { WidgetType } from "constants/WidgetConstants";
|
2019-03-30 12:30:42 +00:00
|
|
|
import {
|
2019-09-13 11:59:45 +00:00
|
|
|
ReduxActionTypes,
|
2019-03-30 12:30:42 +00:00
|
|
|
ReduxAction,
|
2019-09-24 12:36:03 +00:00
|
|
|
UpdateCanvasPayload,
|
2019-09-17 15:09:55 +00:00
|
|
|
SavePagePayload,
|
|
|
|
|
SavePageSuccessPayload,
|
2019-11-22 14:02:55 +00:00
|
|
|
FetchPageListPayload,
|
2019-11-25 05:07:27 +00:00
|
|
|
} from "constants/ReduxActionConstants";
|
|
|
|
|
import { ContainerWidgetProps } from "widgets/ContainerWidget";
|
2019-03-30 12:30:42 +00:00
|
|
|
|
2019-11-22 14:02:55 +00:00
|
|
|
export const fetchPageList = (
|
|
|
|
|
applicationId: string,
|
|
|
|
|
): ReduxAction<FetchPageListPayload> => {
|
|
|
|
|
return {
|
|
|
|
|
type: ReduxActionTypes.FETCH_PAGE_LIST_INIT,
|
|
|
|
|
payload: {
|
|
|
|
|
applicationId,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-11-05 05:09:50 +00:00
|
|
|
|
2020-02-13 09:32:24 +00:00
|
|
|
export const fetchPage = (
|
|
|
|
|
pageId: string,
|
|
|
|
|
canvasWidth?: number,
|
|
|
|
|
): ReduxAction<FetchPageRequest & { canvasWidth?: number }> => {
|
2019-03-30 12:30:42 +00:00
|
|
|
return {
|
2019-11-22 14:02:55 +00:00
|
|
|
type: ReduxActionTypes.FETCH_PAGE_INIT,
|
2019-03-30 12:30:42 +00:00
|
|
|
payload: {
|
2019-12-11 15:24:27 +00:00
|
|
|
pageId,
|
2020-02-13 09:32:24 +00:00
|
|
|
canvasWidth,
|
2019-09-09 09:08:54 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-11-22 14:02:55 +00:00
|
|
|
export const fetchPageSuccess = () => {
|
|
|
|
|
return {
|
|
|
|
|
type: ReduxActionTypes.FETCH_PAGE_SUCCESS,
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export const addWidget = (
|
|
|
|
|
pageId: string,
|
|
|
|
|
widget: WidgetProps,
|
|
|
|
|
): ReduxAction<{ pageId: string; widget: WidgetProps }> => {
|
2019-08-26 12:41:21 +00:00
|
|
|
return {
|
2019-09-12 11:19:38 +00:00
|
|
|
type: ReduxActionTypes.ADD_PAGE_WIDGET,
|
2019-08-26 12:41:21 +00:00
|
|
|
payload: {
|
|
|
|
|
pageId,
|
|
|
|
|
widget,
|
2019-09-09 09:08:54 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-08-26 12:41:21 +00:00
|
|
|
|
2019-09-09 09:08:54 +00:00
|
|
|
export const removeWidget = (
|
|
|
|
|
pageId: string,
|
|
|
|
|
widgetId: string,
|
|
|
|
|
): ReduxAction<{ pageId: string; widgetId: string }> => {
|
2019-08-26 12:41:21 +00:00
|
|
|
return {
|
2019-09-12 11:19:38 +00:00
|
|
|
type: ReduxActionTypes.REMOVE_PAGE_WIDGET,
|
2019-08-26 12:41:21 +00:00
|
|
|
payload: {
|
|
|
|
|
pageId,
|
|
|
|
|
widgetId,
|
2019-09-09 09:08:54 +00:00
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
2019-09-17 15:09:55 +00:00
|
|
|
|
2019-09-23 10:27:45 +00:00
|
|
|
export const updateCanvas = (
|
2019-09-24 12:36:03 +00:00
|
|
|
payload: UpdateCanvasPayload,
|
|
|
|
|
): ReduxAction<UpdateCanvasPayload> => {
|
2019-09-17 15:09:55 +00:00
|
|
|
return {
|
2019-09-23 10:27:45 +00:00
|
|
|
type: ReduxActionTypes.UPDATE_CANVAS,
|
2019-09-17 15:09:55 +00:00
|
|
|
payload,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-18 10:48:56 +00:00
|
|
|
export const savePage = (
|
|
|
|
|
pageId: string,
|
|
|
|
|
layoutId: string,
|
|
|
|
|
dsl: ContainerWidgetProps<WidgetProps>,
|
|
|
|
|
): ReduxAction<SavePagePayload> => {
|
2019-09-17 15:09:55 +00:00
|
|
|
return {
|
|
|
|
|
type: ReduxActionTypes.SAVE_PAGE_INIT,
|
2019-09-18 10:48:56 +00:00
|
|
|
payload: { pageId, layoutId, dsl },
|
2019-09-17 15:09:55 +00:00
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const savePageSuccess = (payload: SavePageSuccessPayload) => {
|
|
|
|
|
return {
|
|
|
|
|
type: ReduxActionTypes.SAVE_PAGE_SUCCESS,
|
|
|
|
|
payload,
|
|
|
|
|
};
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-19 22:25:37 +00:00
|
|
|
export type WidgetAddChild = {
|
|
|
|
|
widgetId: string;
|
|
|
|
|
type: WidgetType;
|
2019-09-25 17:24:23 +00:00
|
|
|
leftColumn: number;
|
|
|
|
|
topRow: number;
|
|
|
|
|
columns: number;
|
|
|
|
|
rows: number;
|
|
|
|
|
parentRowSpace: number;
|
|
|
|
|
parentColumnSpace: number;
|
2020-01-02 12:42:02 +00:00
|
|
|
newWidgetId: string;
|
2019-09-19 22:25:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type WidgetMove = {
|
|
|
|
|
widgetId: string;
|
2019-09-25 17:24:23 +00:00
|
|
|
leftColumn: number;
|
|
|
|
|
topRow: number;
|
2019-10-03 17:35:13 +00:00
|
|
|
parentId: string;
|
2019-09-19 22:25:37 +00:00
|
|
|
/*
|
2019-11-05 05:09:50 +00:00
|
|
|
If newParentId is different from what we have in redux store,
|
2019-09-23 10:43:22 +00:00
|
|
|
then we have to delete this,
|
2019-11-05 05:09:50 +00:00
|
|
|
as it has been dropped in another container somewhere.
|
2019-09-19 22:25:37 +00:00
|
|
|
*/
|
2019-10-03 17:35:13 +00:00
|
|
|
newParentId: string;
|
2019-09-19 22:25:37 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type WidgetRemoveChild = {
|
|
|
|
|
widgetId: string;
|
|
|
|
|
childWidgetId: string;
|
|
|
|
|
};
|
|
|
|
|
|
2019-09-22 20:25:05 +00:00
|
|
|
export type WidgetDelete = {
|
|
|
|
|
widgetId: string;
|
2019-10-03 17:35:13 +00:00
|
|
|
parentId: string;
|
2019-09-22 20:25:05 +00:00
|
|
|
};
|
|
|
|
|
|
2019-09-19 22:25:37 +00:00
|
|
|
export type WidgetResize = {
|
|
|
|
|
widgetId: string;
|
2019-10-02 19:42:25 +00:00
|
|
|
leftColumn: number;
|
|
|
|
|
rightColumn: number;
|
|
|
|
|
topRow: number;
|
|
|
|
|
bottomRow: number;
|
2019-09-19 22:25:37 +00:00
|
|
|
};
|
|
|
|
|
|
2019-09-17 15:09:55 +00:00
|
|
|
export const updateWidget = (
|
2019-09-19 22:25:37 +00:00
|
|
|
operation: WidgetOperation,
|
|
|
|
|
widgetId: string,
|
2019-09-17 15:09:55 +00:00
|
|
|
payload: any,
|
2019-09-19 22:25:37 +00:00
|
|
|
): ReduxAction<
|
2019-09-24 12:36:03 +00:00
|
|
|
WidgetAddChild | WidgetMove | WidgetRemoveChild | WidgetResize | WidgetDelete
|
2019-09-19 22:25:37 +00:00
|
|
|
> => {
|
|
|
|
|
return {
|
|
|
|
|
type: ReduxActionTypes["WIDGET_" + operation],
|
|
|
|
|
payload: { widgetId, ...payload },
|
|
|
|
|
};
|
2019-09-17 15:09:55 +00:00
|
|
|
};
|