PromucFlow_constructor/app/client/src/widgets/CanvasWidget.tsx
ashit-rath 893fd34cdd
perf: Widget re-rendering refactor (#14485)
* initial commit

* props hoc

* changes

* removed ignores and withWidgetProps

* added extra props to canvasStructure

* widget props changes

* list widget changes

* reintroduced widget props hook and other refactors

* remove warnings

* added deepequal for childWidgets selector

* fix global hotkeys and tabs widget jest test

* fix main container test fix

* fixed view mode width

* fix form widget values

* minor fix

* fix skeleton

* form widget validity fix

* jest test fix

* fixed tests: GlobalHotkeys, Tabs, CanvasSelectectionArena and fixed main container rendering

* minor fix

* minor comments

* reverted commented code

* simplified structure, selective redux state updates and other inconsistencies

* fix junit test cases

* stop form widget from force rendering children

* fix test case

* random commit to re run tests

* update isFormValid prop only if it exists

* detangling circular dependency

* fixing cypress tests

* cleaned up code

* clean up man cnavas props and fix jest cases

* fix rendering order of child widgets for canvas

* fix dropdown reset spec

* adding comments

* cleaning up unwanted code

* fix multiselect widget on deploy

* adressing review comments

* addressing minor review comment changes

* destructuring modal widget child and fix test case

* fix communityIssues cypress spec

* rewrite isVisible logic to match previous behaviour

* merging widget props with component props before checking isVisible

* adressing review comments for modal widget's isVisible

Co-authored-by: rahulramesha <rahul@appsmith.com>
2022-08-19 15:40:36 +05:30

125 lines
3.4 KiB
TypeScript

import React, { CSSProperties } from "react";
import { WidgetProps } from "widgets/BaseWidget";
import ContainerWidget, {
ContainerWidgetProps,
} from "widgets/ContainerWidget/widget";
import { GridDefaults } from "constants/WidgetConstants";
import DropTargetComponent from "components/editorComponents/DropTargetComponent";
import { getCanvasSnapRows } from "utils/WidgetPropsUtils";
import { getCanvasClassName } from "utils/generators";
import WidgetFactory, { DerivedPropertiesMap } from "utils/WidgetFactory";
import { CanvasWidgetStructure } from "./constants";
import { CANVAS_DEFAULT_MIN_HEIGHT_PX } from "constants/AppConstants";
class CanvasWidget extends ContainerWidget {
static getPropertyPaneConfig() {
return [];
}
static getWidgetType() {
return "CANVAS_WIDGET";
}
getCanvasProps(): ContainerWidgetProps<WidgetProps> {
return {
...this.props,
parentRowSpace: 1,
parentColumnSpace: 1,
topRow: 0,
leftColumn: 0,
containerStyle: "none",
detachFromLayout: true,
};
}
renderAsDropTarget() {
const canvasProps = this.getCanvasProps();
return (
<DropTargetComponent
{...canvasProps}
{...this.getSnapSpaces()}
minHeight={this.props.minHeight || CANVAS_DEFAULT_MIN_HEIGHT_PX}
>
{this.renderAsContainerComponent(canvasProps)}
</DropTargetComponent>
);
}
renderChildWidget(childWidgetData: CanvasWidgetStructure): React.ReactNode {
if (!childWidgetData) return null;
const childWidget = { ...childWidgetData };
const snapSpaces = this.getSnapSpaces();
childWidget.parentColumnSpace = snapSpaces.snapColumnSpace;
childWidget.parentRowSpace = snapSpaces.snapRowSpace;
if (this.props.noPad) childWidget.noContainerOffset = true;
childWidget.parentId = this.props.widgetId;
return WidgetFactory.createWidget(childWidget, this.props.renderMode);
}
getPageView() {
let height = 0;
const snapRows = getCanvasSnapRows(
this.props.bottomRow,
this.props.canExtend,
);
height = snapRows * GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
const style: CSSProperties = {
width: "100%",
height: `${height}px`,
background: "none",
position: "relative",
};
// This div is the DropTargetComponent alternative for the page view
// DropTargetComponent and this div are responsible for the canvas height
return (
<div className={getCanvasClassName()} style={style}>
{this.renderAsContainerComponent(this.getCanvasProps())}
</div>
);
}
getCanvasView() {
if (!this.props.dropDisabled) {
return this.renderAsDropTarget();
}
return this.getPageView();
}
static getDerivedPropertiesMap(): DerivedPropertiesMap {
return {};
}
static getDefaultPropertiesMap(): Record<string, string> {
return {};
}
// TODO Find a way to enforce this, (dont let it be set)
static getMetaPropertiesMap(): Record<string, any> {
return {};
}
}
export const CONFIG = {
type: CanvasWidget.getWidgetType(),
name: "Canvas",
hideCard: true,
defaults: {
rows: 0,
columns: 0,
widgetName: "Canvas",
version: 1,
detachFromLayout: true,
},
properties: {
derived: CanvasWidget.getDerivedPropertiesMap(),
default: CanvasWidget.getDefaultPropertiesMap(),
meta: CanvasWidget.getMetaPropertiesMap(),
config: CanvasWidget.getPropertyPaneConfig(),
},
};
export default CanvasWidget;