PromucFlow_constructor/app/client/src/layoutSystems/withLayoutSystemWidgetHOC.tsx
Preet Sidhu 69f4a412bf
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 16:27:40 -04:00

63 lines
2.2 KiB
TypeScript

import type { RenderModes } from "constants/WidgetConstants";
import React from "react";
import { useSelector } from "react-redux";
import { getRenderMode } from "selectors/editorSelectors";
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
import type { WidgetProps } from "widgets/BaseWidget";
import { getAutoLayoutSystem } from "./autolayout";
import { getFixedLayoutSystem } from "./fixedlayout";
import type { LayoutSystem } from "./types";
import { LayoutSystemTypes } from "./types";
import { getAnvilLayoutSystem } from "./anvil";
/**
*
* @param renderMode - render mode specifies whether the application is in edit/deploy mode.
* @param layoutSystemType - layout system of the application.
* @returns
* @property — widgetSystem - widget specific wrappers and enhancers of a layout system
* @property — canvasSystem - canvas specific implementation and enhancers of a layout system
*/
export const getLayoutSystem = (
renderMode: RenderModes,
layoutSystemType: LayoutSystemTypes,
): LayoutSystem => {
switch (layoutSystemType) {
case LayoutSystemTypes.ANVIL:
return getAnvilLayoutSystem(renderMode);
case LayoutSystemTypes.AUTO:
return getAutoLayoutSystem(renderMode);
default:
return getFixedLayoutSystem(renderMode);
}
};
const LayoutSystemWrapper = ({
Widget,
widgetProps,
}: {
widgetProps: WidgetProps;
Widget: (props: WidgetProps) => JSX.Element;
}) => {
const renderMode = useSelector(getRenderMode);
const layoutSystemType = useSelector(getLayoutSystemType);
// based on layoutSystemType and renderMode
// get the layout system wrapper(adds layout system specific functionality) and
// properties enhancer(adds/modifies properties of a widget based on layout system)
const { widgetSystem } = getLayoutSystem(renderMode, layoutSystemType);
const { propertyEnhancer, WidgetWrapper } = widgetSystem;
const enhancedProperties = propertyEnhancer(widgetProps);
return (
<WidgetWrapper {...enhancedProperties}>
<Widget {...enhancedProperties} />
</WidgetWrapper>
);
};
export const withLayoutSystemWidgetHOC = (Widget: any) => {
return function LayoutWrappedWidget(props: WidgetProps) {
return <LayoutSystemWrapper Widget={Widget} widgetProps={props} />;
};
};