PromucFlow_constructor/app/client/src/selectors/autoLayoutSelectors.tsx
Preet Sidhu 46dcf3a8f0
chore: Create layout system structure for Anvil and AnvilFlexComponent. (#27178)
## Description
1. Add new ```appPositioningType``` : ANVIL.
2. Create new code path and folder structure for Anvil layout system.
3. Move common pieces of functionalities between autoLayout and anvil to
anvil folder structure (e.g. ```CanvasResizer```).
4. Create ```AnvilFlexComponent```.
5. Use WDS Flex component in AnvilFlexComponent.
6. Pass min max size props in a data structure that is supported by
container queries in the Flex component.
    e.g. min-width: { base: "120px", "480px": "200px" }
7. Supply the following flex properties (flex-grow flex-shrink
flex-basis) to widgets depending on their ```responsiveBehvaiour```:
    a) Fill: ```flex: 1 1 0%;```
    b) Hug: ```flex: 0 0 auto;```

#### PR fixes following issue(s)
Fixes # (issue number)
1. [#26987](https://github.com/appsmithorg/appsmith/issues/26987)
2. [#26609](https://github.com/appsmithorg/appsmith/issues/26609)
3. [#26611](https://github.com/appsmithorg/appsmith/issues/26611)

#### Type of change
- New feature (non-breaking change which adds functionality)


## 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
- [x] 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
- [ ] My changes generate no new warnings
- [x] 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
- [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-02 15:41:05 -04:00

121 lines
4.0 KiB
TypeScript

import type { AppState } from "@appsmith/reducers";
import { FLEXBOX_PADDING, GridDefaults } from "constants/WidgetConstants";
import { createSelector } from "reselect";
import { getCanvasAndMetaWidgets } from "sagas/selectors";
import type {
AlignmentColumnInfo,
FlexBoxAlignmentColumnInfo,
} from "layoutSystems/autolayout/utils/types";
import { getAlignmentColumnInfo } from "layoutSystems/autolayout/utils/AutoLayoutUtils";
import { getIsAutoLayoutMobileBreakPoint } from "./editorSelectors";
import type {
FlexLayer,
LayerChild,
} from "layoutSystems/autolayout/utils/types";
export const getIsCurrentlyConvertingLayout = (state: AppState) =>
state.ui.layoutConversion.isConverting;
export const getFlexLayers = (parentId: string) => {
return createSelector(getCanvasAndMetaWidgets, (widgets): FlexLayer[] => {
const parent = widgets[parentId];
if (!parent) return [];
return parent?.flexLayers || [];
});
};
export const getSnapshotUpdatedTime = (state: AppState) =>
state.ui.layoutConversion.snapshotDetails?.lastUpdatedTime;
export const getLayerIndex = (widgetId: string, parentId: string) => {
return createSelector(
getFlexLayers(parentId),
(layers: FlexLayer[]): number => {
if (!layers) return -1;
const selectedLayer = layers.find((layer: FlexLayer) =>
layer.children.some((child: LayerChild) => child.id === widgetId),
);
if (!selectedLayer) return -1;
return selectedLayer.children?.findIndex(
(child: LayerChild) => child.id === widgetId,
);
},
);
};
export const isCurrentCanvasDragging = (widgetId: string) => {
return createSelector(
(state: AppState) => state.ui.widgetDragResize.dragDetails,
(dragDetails): boolean => {
return dragDetails?.draggedOn === widgetId;
},
);
};
export const getTotalTopOffset = (widgetId: string) => {
return createSelector(
getCanvasAndMetaWidgets,
getIsAutoLayoutMobileBreakPoint,
(widgets, isMobile): number => {
let widget = widgets[widgetId];
if (!widget) return 0;
let offset = 0;
while (widget.parentId) {
const parent = widgets[widget.parentId];
const top =
isMobile && parent.mobileTopRow !== undefined
? parent.mobileTopRow
: parent.topRow;
offset += top * GridDefaults.DEFAULT_GRID_ROW_HEIGHT + FLEXBOX_PADDING;
if (parent.type === "TABS_WIDGET" && parent?.shouldShowTabs)
offset += GridDefaults.DEFAULT_GRID_ROW_HEIGHT * 4; // 4 rows for tabs header
widget = parent;
}
return offset;
},
);
};
export const getParentOffsetTop = (widgetId: string) =>
createSelector(
getCanvasAndMetaWidgets,
getIsAutoLayoutMobileBreakPoint,
(widgets, isMobile): number => {
const widget = widgets[widgetId];
if (!widget || !widget.parentId) return 0;
const parent = widgets[widget.parentId];
const top =
isMobile && parent.mobileTopRow !== undefined
? parent.mobileTopRow
: parent.topRow;
return top * GridDefaults.DEFAULT_GRID_ROW_HEIGHT + FLEXBOX_PADDING;
},
);
export const getAlignmentColumns = (widgetId: string, layerIndex: number) =>
createSelector(
getCanvasAndMetaWidgets,
getIsAutoLayoutMobileBreakPoint,
getFlexLayers(widgetId),
(widgets, isMobile, flexLayers): AlignmentColumnInfo => {
const layer: FlexLayer = flexLayers[layerIndex];
return getAlignmentColumnInfo(widgets, layer, isMobile);
},
);
export const getColumnsForAllLayers = (widgetId: string) =>
createSelector(
getCanvasAndMetaWidgets,
getIsAutoLayoutMobileBreakPoint,
getFlexLayers(widgetId),
(widgets, isMobile, flexLayers): FlexBoxAlignmentColumnInfo => {
const res: { [key: number]: AlignmentColumnInfo } = {};
if (!flexLayers || !flexLayers.length) return res;
for (const [index, layer] of flexLayers.entries()) {
const info = getAlignmentColumnInfo(widgets, layer, isMobile);
res[index] = info;
}
return res;
},
);