> Pull Request Template > > Use this template to quickly create a well written pull request. Delete all quotes before creating the pull request. > ## Description In This PR, we are cleaning up Canvas Widget implementation and taking measures to remove it from the widget suite. more detailed explanation of Why and How of the solution [here](https://www.notion.so/Canvas-Widget-73776a3364ba42eb8f783c79046777d0) In this solution we are going to remove implementation of Editing and Layouting Specific implementation from Canvas Widget and create a new view component which is Layout system specific. #### PR fixes following issue(s) Fixes #27003 #### Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video > > #### Type of change > Please delete options that are not relevant. - Chore (housekeeping or task changes that don't impact user perception) > > > ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] JUnit - [X] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] 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
150 lines
4.9 KiB
TypeScript
150 lines
4.9 KiB
TypeScript
import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
|
|
import { RenderModes } from "../../constants/WidgetConstants";
|
|
import { AutoLayoutEditorCanvas } from "./canvas/AutoLayoutEditorCanvas";
|
|
import { AutoLayoutViewerCanvas } from "./canvas/AutoLayoutViewerCanvas";
|
|
import { AutoLayoutEditorWrapper } from "./editor/AutoLayoutEditorWrapper";
|
|
import { AutoLayoutViewerWrapper } from "./viewer/AutoLayoutViewerWrapper";
|
|
import { getAutoLayoutComponentDimensions } from "layoutSystems/common/utils/ComponentSizeUtils";
|
|
import type { LayoutSystem } from "layoutSystems/types";
|
|
import { CANVAS_DEFAULT_MIN_HEIGHT_PX } from "constants/AppConstants";
|
|
import type { CanvasProps } from "layoutSystems/fixedlayout/canvas/FixedLayoutEditorCanvas";
|
|
import {
|
|
getAutoDimensionsConfig,
|
|
getAutoLayoutWidgetConfig,
|
|
} from "layoutSystems/common/utils/commonUtils";
|
|
import type { AutoDimensionOptions } from "WidgetProvider/constants";
|
|
|
|
/**
|
|
* getAutoLayoutDimensionsConfig
|
|
*
|
|
* utility function to fetch and process widget specific autoDimensionConfig(specific to Auto Layout Layout system)
|
|
* stored on the WidgetFactory.autoLayoutConfigMap.
|
|
*
|
|
* @returns AutoDimensionValues | undefined
|
|
*/
|
|
export const getAutoLayoutDimensionsConfig = (
|
|
props: BaseWidgetProps,
|
|
): AutoDimensionOptions | undefined => {
|
|
return getAutoDimensionsConfig(getAutoLayoutWidgetConfig(props), props);
|
|
};
|
|
|
|
/**
|
|
* getAutoLayoutSystemWidgetPropsEnhancer
|
|
*
|
|
* utility function to enhance BaseWidgetProps with Auto Layout system specific props
|
|
*
|
|
* @returns EnhancedBaseWidgetProps
|
|
* @property {AutoDimensionValues | undefined} autoDimensionConfig The auto dimension configuration of a widget.
|
|
* @property {number} componentHeight The calculated height of a widget in pixels.
|
|
* @property {number} componentWidth The calculated width of a widget in pixels.
|
|
*
|
|
*/
|
|
|
|
const getAutoLayoutSystemWidgetPropsEnhancer = (props: BaseWidgetProps) => {
|
|
const autoDimensionConfig = getAutoLayoutDimensionsConfig(props);
|
|
const { componentHeight, componentWidth } =
|
|
getAutoLayoutComponentDimensions(props);
|
|
return {
|
|
...props,
|
|
autoDimensionConfig,
|
|
componentHeight,
|
|
componentWidth,
|
|
};
|
|
};
|
|
|
|
const defaultAutoLayoutCanvasProps: Partial<CanvasProps> = {
|
|
parentRowSpace: 1,
|
|
parentColumnSpace: 1,
|
|
topRow: 0,
|
|
leftColumn: 0,
|
|
containerStyle: "none",
|
|
detachFromLayout: true,
|
|
shouldScrollContents: false,
|
|
};
|
|
|
|
/**
|
|
* getAutoLayoutSystemCanvasPropsEnhancer
|
|
*
|
|
* utility function to enhance BaseWidgetProps of canvas with Auto Layout system specific props
|
|
*
|
|
* @returns EnhancedBaseWidgetProps
|
|
* @property {AutoDimensionValues | undefined} autoDimensionConfig The auto dimension configuration of a widget.
|
|
* @property {number} componentHeight The calculated height of a widget in pixels.
|
|
* @property {number} componentWidth The calculated width of a widget in pixels.
|
|
*
|
|
*/
|
|
|
|
const getAutoLayoutSystemCanvasPropsEnhancer = (props: BaseWidgetProps) => {
|
|
const enhancedProps = {
|
|
minHeight: CANVAS_DEFAULT_MIN_HEIGHT_PX,
|
|
...props,
|
|
...defaultAutoLayoutCanvasProps,
|
|
};
|
|
const autoDimensionConfig = getAutoLayoutDimensionsConfig(enhancedProps);
|
|
const { componentHeight, componentWidth } =
|
|
getAutoLayoutComponentDimensions(enhancedProps);
|
|
return {
|
|
...enhancedProps,
|
|
autoDimensionConfig,
|
|
componentHeight,
|
|
componentWidth,
|
|
};
|
|
};
|
|
|
|
/**
|
|
* getAutoLayoutSystemWrapper
|
|
*
|
|
* utility function to return the auto layout system wrapper based on render mode.
|
|
* wrapper is the component that wraps around a widget to provide layout-ing ability and enable editing experience.
|
|
*
|
|
* @returns current render mode specific wrapper.
|
|
*/
|
|
|
|
const getAutoLayoutSystemWrapper = (renderMode: RenderModes) => {
|
|
if (renderMode === RenderModes.CANVAS) {
|
|
return AutoLayoutEditorWrapper;
|
|
} else {
|
|
return AutoLayoutViewerWrapper;
|
|
}
|
|
};
|
|
|
|
/**
|
|
* getAutoLayoutSystemCanvasWrapper
|
|
*
|
|
* utility function to return the auto layout system canvas implementation based on render mode.
|
|
*
|
|
* @returns current render mode specific canvas component.
|
|
*/
|
|
|
|
function getAutoLayoutSystemCanvasWrapper(renderMode: RenderModes) {
|
|
if (renderMode === RenderModes.CANVAS) {
|
|
return AutoLayoutEditorCanvas;
|
|
} else {
|
|
return AutoLayoutViewerCanvas;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* getAutoLayoutSystem
|
|
*
|
|
* utility function to return the auto layout system config for
|
|
* wrapper based on render mode and property enhancer function
|
|
*
|
|
* @returns
|
|
* @property widgetSystem - widget specific wrappers and enhancers of a layout system
|
|
* @property canvasSystem - canvas specific implementation and enhancers of a layout system
|
|
*/
|
|
|
|
export function getAutoLayoutSystem(renderMode: RenderModes): LayoutSystem {
|
|
return {
|
|
widgetSystem: {
|
|
WidgetWrapper: getAutoLayoutSystemWrapper(renderMode),
|
|
propertyEnhancer: getAutoLayoutSystemWidgetPropsEnhancer,
|
|
},
|
|
canvasSystem: {
|
|
Canvas: getAutoLayoutSystemCanvasWrapper(renderMode),
|
|
propertyEnhancer: getAutoLayoutSystemCanvasPropsEnhancer,
|
|
},
|
|
};
|
|
}
|