2023-10-19 20:27:40 +00:00
|
|
|
import { RenderModes } from "constants/WidgetConstants";
|
|
|
|
|
import {
|
|
|
|
|
LayoutComponentTypes,
|
|
|
|
|
type LayoutComponentProps,
|
|
|
|
|
type WidgetLayoutProps,
|
|
|
|
|
} from "layoutSystems/anvil/utils/anvilTypes";
|
|
|
|
|
import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
|
|
|
|
|
import type { WidgetProps } from "widgets/BaseWidget";
|
|
|
|
|
import { generateReactKey } from "utils/generators";
|
|
|
|
|
import { mockButtonProps } from "mocks/widgetProps/button";
|
|
|
|
|
import { mockInputProps } from "mocks/widgetProps/input";
|
|
|
|
|
import { FlexLayerAlignment } from "layoutSystems/common/utils/constants";
|
|
|
|
|
|
|
|
|
|
export function generateLayoutComponentMock(
|
|
|
|
|
data: Partial<LayoutComponentProps> = {},
|
|
|
|
|
rendersWidgets = true,
|
2023-12-26 14:16:58 +00:00
|
|
|
): { layout: LayoutComponentProps; childrenMap: Record<string, WidgetProps> } {
|
2023-10-19 20:27:40 +00:00
|
|
|
if (data?.layoutType === LayoutComponentTypes.ALIGNED_WIDGET_ROW)
|
|
|
|
|
return generateAlignedRowMock(data, rendersWidgets);
|
2023-12-26 14:16:58 +00:00
|
|
|
const layout: WidgetLayoutProps[] | LayoutComponentProps[] = [];
|
|
|
|
|
let childrenMap: { [key: string]: WidgetProps } = {};
|
2023-10-19 20:27:40 +00:00
|
|
|
let type = LayoutComponentTypes.WIDGET_ROW;
|
|
|
|
|
if (rendersWidgets) {
|
|
|
|
|
/**
|
|
|
|
|
* This generates a Row with button and input widgets in it.
|
|
|
|
|
* Row
|
|
|
|
|
* Button
|
|
|
|
|
* Input
|
|
|
|
|
*/
|
|
|
|
|
const buttonWidget: BaseWidgetProps = mockButtonProps();
|
|
|
|
|
const inputWidget: BaseWidgetProps = mockInputProps();
|
|
|
|
|
(layout as WidgetLayoutProps[]).push({
|
|
|
|
|
alignment: FlexLayerAlignment.Start,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgetId: buttonWidget.widgetId,
|
|
|
|
|
widgetType: buttonWidget.type,
|
2023-10-19 20:27:40 +00:00
|
|
|
});
|
|
|
|
|
(layout as WidgetLayoutProps[]).push({
|
|
|
|
|
alignment: FlexLayerAlignment.Start,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
widgetType: inputWidget.type,
|
2023-10-19 20:27:40 +00:00
|
|
|
});
|
|
|
|
|
childrenMap[buttonWidget.widgetId] = buttonWidget;
|
|
|
|
|
childrenMap[inputWidget.widgetId] = inputWidget;
|
|
|
|
|
} else {
|
|
|
|
|
type = LayoutComponentTypes.LAYOUT_ROW;
|
2023-12-26 14:16:58 +00:00
|
|
|
const mock1 = generateLayoutComponentMock();
|
|
|
|
|
const mock2 = generateLayoutComponentMock();
|
|
|
|
|
(layout as LayoutComponentProps[]).push(mock1.layout);
|
|
|
|
|
(layout as LayoutComponentProps[]).push(mock2.layout);
|
|
|
|
|
childrenMap = {
|
|
|
|
|
...childrenMap,
|
|
|
|
|
...mock1.childrenMap,
|
|
|
|
|
...mock2.childrenMap,
|
|
|
|
|
};
|
2023-10-19 20:27:40 +00:00
|
|
|
}
|
|
|
|
|
return {
|
2023-12-26 14:16:58 +00:00
|
|
|
layout: {
|
|
|
|
|
layout,
|
|
|
|
|
layoutId: generateReactKey(),
|
|
|
|
|
layoutIndex: 0,
|
|
|
|
|
layoutStyle: {},
|
|
|
|
|
layoutType: type,
|
2023-10-19 20:27:40 +00:00
|
|
|
|
2023-12-26 14:16:58 +00:00
|
|
|
allowedWidgetTypes: [],
|
|
|
|
|
canvasId: "",
|
|
|
|
|
children: [],
|
|
|
|
|
childTemplate: null,
|
|
|
|
|
isDropTarget: false,
|
|
|
|
|
insertChild: rendersWidgets,
|
|
|
|
|
isPermanent: false,
|
2023-10-19 20:27:40 +00:00
|
|
|
|
2023-12-26 14:16:58 +00:00
|
|
|
layoutOrder: [],
|
|
|
|
|
parentDropTarget: "",
|
|
|
|
|
renderMode: RenderModes.CANVAS,
|
|
|
|
|
...data,
|
|
|
|
|
},
|
2023-10-19 20:27:40 +00:00
|
|
|
childrenMap,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This generates an AlignedRow with button and input widgets in start alignment.
|
|
|
|
|
* AlignedRow
|
|
|
|
|
* Start
|
|
|
|
|
* Button
|
|
|
|
|
* Input
|
|
|
|
|
* Center
|
|
|
|
|
* End
|
|
|
|
|
*/
|
|
|
|
|
export function generateAlignedRowMock(
|
|
|
|
|
data: Partial<LayoutComponentProps> = {},
|
|
|
|
|
rendersWidgets = true,
|
2023-12-26 14:16:58 +00:00
|
|
|
): { layout: LayoutComponentProps; childrenMap: Record<string, WidgetProps> } {
|
2023-10-19 20:27:40 +00:00
|
|
|
const layout: WidgetLayoutProps[] = [],
|
|
|
|
|
childrenMap: { [key: string]: WidgetProps } = {};
|
|
|
|
|
if (rendersWidgets) {
|
|
|
|
|
const buttonWidget: BaseWidgetProps = mockButtonProps();
|
|
|
|
|
const inputWidget: BaseWidgetProps = mockInputProps();
|
|
|
|
|
(layout as WidgetLayoutProps[]).push({
|
|
|
|
|
alignment: FlexLayerAlignment.Start,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgetId: buttonWidget.widgetId,
|
|
|
|
|
widgetType: buttonWidget.type,
|
2023-10-19 20:27:40 +00:00
|
|
|
});
|
|
|
|
|
(layout as WidgetLayoutProps[]).push({
|
|
|
|
|
alignment: FlexLayerAlignment.Start,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgetId: inputWidget.widgetId,
|
|
|
|
|
widgetType: inputWidget.type,
|
2023-10-19 20:27:40 +00:00
|
|
|
});
|
|
|
|
|
childrenMap[buttonWidget.widgetId] = buttonWidget;
|
|
|
|
|
childrenMap[inputWidget.widgetId] = inputWidget;
|
|
|
|
|
}
|
|
|
|
|
return {
|
2023-12-26 14:16:58 +00:00
|
|
|
layout: {
|
|
|
|
|
layout,
|
|
|
|
|
layoutId: "",
|
|
|
|
|
layoutIndex: 0,
|
|
|
|
|
layoutStyle: {},
|
|
|
|
|
layoutType: LayoutComponentTypes.ALIGNED_WIDGET_ROW,
|
2023-10-19 20:27:40 +00:00
|
|
|
|
2023-12-26 14:16:58 +00:00
|
|
|
allowedWidgetTypes: [],
|
|
|
|
|
canvasId: "",
|
|
|
|
|
children: [],
|
|
|
|
|
childTemplate: null,
|
|
|
|
|
isDropTarget: false,
|
|
|
|
|
insertChild: rendersWidgets,
|
|
|
|
|
isPermanent: false,
|
2023-10-19 20:27:40 +00:00
|
|
|
|
2023-12-26 14:16:58 +00:00
|
|
|
layoutOrder: [],
|
|
|
|
|
parentDropTarget: "",
|
|
|
|
|
renderMode: RenderModes.CANVAS,
|
|
|
|
|
...data,
|
|
|
|
|
},
|
2023-10-19 20:27:40 +00:00
|
|
|
childrenMap,
|
|
|
|
|
};
|
|
|
|
|
}
|