PromucFlow_constructor/app/client/src/mocks/layoutComponents/layoutComponentMock.ts

121 lines
3.5 KiB
TypeScript
Raw Normal View History

chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
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,
): LayoutComponentProps {
if (data?.layoutType === LayoutComponentTypes.ALIGNED_WIDGET_ROW)
return generateAlignedRowMock(data, rendersWidgets);
const layout: WidgetLayoutProps[] | LayoutComponentProps[] = [],
childrenMap: { [key: string]: WidgetProps } = {};
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({
widgetId: buttonWidget.widgetId,
alignment: FlexLayerAlignment.Start,
});
(layout as WidgetLayoutProps[]).push({
widgetId: inputWidget.widgetId,
alignment: FlexLayerAlignment.Start,
});
childrenMap[buttonWidget.widgetId] = buttonWidget;
childrenMap[inputWidget.widgetId] = inputWidget;
} else {
type = LayoutComponentTypes.LAYOUT_ROW;
(layout as LayoutComponentProps[]).push(generateLayoutComponentMock());
(layout as LayoutComponentProps[]).push(generateLayoutComponentMock());
}
return {
layout,
layoutId: generateReactKey(),
layoutIndex: 0,
chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-19 20:27:40 +00:00
layoutStyle: {},
layoutType: type,
allowedWidgetTypes: [],
canvasId: "",
children: [],
childTemplate: null,
isDropTarget: false,
insertChild: rendersWidgets,
isPermanent: false,
childrenMap,
layoutOrder: [],
parentDropTarget: "",
renderMode: RenderModes.CANVAS,
...data,
};
}
/**
* 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,
): LayoutComponentProps {
const layout: WidgetLayoutProps[] = [],
childrenMap: { [key: string]: WidgetProps } = {};
if (rendersWidgets) {
const buttonWidget: BaseWidgetProps = mockButtonProps();
const inputWidget: BaseWidgetProps = mockInputProps();
(layout as WidgetLayoutProps[]).push({
widgetId: buttonWidget.widgetId,
alignment: FlexLayerAlignment.Start,
});
(layout as WidgetLayoutProps[]).push({
widgetId: inputWidget.widgetId,
alignment: FlexLayerAlignment.Start,
});
childrenMap[buttonWidget.widgetId] = buttonWidget;
childrenMap[inputWidget.widgetId] = inputWidget;
}
return {
layout,
layoutId: "",
layoutIndex: 0,
chore: add highlight calculation logic for layouts. (#27980) ## Description 1. Add LayoutComponent functionality. 2. Create Basic LayoutComponents. 3. Create LayoutPresets needed for Container-like widgets. 4. Add highlight calculation logic for all basic Layout Components. 5. Create dragging sagas for Anvil. 6. Create DraggingArena associated functionality to handle DnD in Anvil. #### PR fixes following issue(s) Fixes #27004 #### Type of change > Please delete options that are not relevant. - New feature (non-breaking change which adds functionality) ## Testing #### How Has This Been Tested? - [ ] Manual - [ ] JUnit - [x] Jest - [ ] Cypress ## Checklist: #### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [x] My changes generate no new warnings - [x] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [x] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed --------- Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
2023-10-19 20:27:40 +00:00
layoutStyle: {},
layoutType: LayoutComponentTypes.ALIGNED_WIDGET_ROW,
allowedWidgetTypes: [],
canvasId: "",
children: [],
childTemplate: null,
isDropTarget: false,
insertChild: rendersWidgets,
isPermanent: false,
childrenMap,
layoutOrder: [],
parentDropTarget: "",
renderMode: RenderModes.CANVAS,
...data,
};
}