2022-08-19 10:10:36 +00:00
|
|
|
import equal from "fast-deep-equal/es6";
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
2023-03-04 07:25:54 +00:00
|
|
|
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### 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
- [x] 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
- [x] 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:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { AppState } from "@appsmith/reducers";
|
2023-03-04 07:25:54 +00:00
|
|
|
import { checkContainersForAutoHeightAction } from "actions/autoHeightActions";
|
2022-08-19 10:10:36 +00:00
|
|
|
import {
|
2023-02-03 05:47:40 +00:00
|
|
|
GridDefaults,
|
2022-08-19 10:10:36 +00:00
|
|
|
MAIN_CONTAINER_WIDGET_ID,
|
|
|
|
|
RenderModes,
|
2023-07-04 14:12:00 +00:00
|
|
|
WIDGET_PADDING,
|
2022-08-19 10:10:36 +00:00
|
|
|
} from "constants/WidgetConstants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import { useDispatch, useSelector } from "react-redux";
|
|
|
|
|
import { getWidget } from "sagas/selectors";
|
2022-08-19 10:10:36 +00:00
|
|
|
import {
|
|
|
|
|
getIsWidgetLoading,
|
2023-03-04 07:25:54 +00:00
|
|
|
getWidgetEvalValues,
|
2022-08-19 10:10:36 +00:00
|
|
|
} from "selectors/dataTreeSelectors";
|
|
|
|
|
import {
|
|
|
|
|
computeMainContainerWidget,
|
|
|
|
|
getChildWidgets,
|
2023-03-04 07:25:54 +00:00
|
|
|
getMainCanvasProps,
|
2022-08-19 10:10:36 +00:00
|
|
|
getRenderMode,
|
2023-02-14 16:07:31 +00:00
|
|
|
getMetaWidgetChildrenStructure,
|
|
|
|
|
getMetaWidget,
|
2023-04-07 13:51:35 +00:00
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
2023-05-11 04:45:14 +00:00
|
|
|
getCanvasWidth,
|
2023-11-03 17:13:36 +00:00
|
|
|
combinedPreviewModeSelector,
|
2022-08-19 10:10:36 +00:00
|
|
|
} from "selectors/editorSelectors";
|
|
|
|
|
import {
|
|
|
|
|
createCanvasWidget,
|
|
|
|
|
createLoadingWidget,
|
|
|
|
|
} from "utils/widgetRenderUtils";
|
chore: upgrade to prettier v2 + enforce import types (#21013)Co-authored-by: Satish Gandham <hello@satishgandham.com> Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
## Description
This PR upgrades Prettier to v2 + enforces TypeScript’s [`import
type`](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export)
syntax where applicable. It’s submitted as a separate PR so we can merge
it easily.
As a part of this PR, we reformat the codebase heavily:
- add `import type` everywhere where it’s required, and
- re-format the code to account for Prettier 2’s breaking changes:
https://prettier.io/blog/2020/03/21/2.0.0.html#breaking-changes
This PR is submitted against `release` to make sure all new code by team
members will adhere to new formatting standards, and we’ll have fewer
conflicts when merging `bundle-optimizations` into `release`. (I’ll
merge `release` back into `bundle-optimizations` once this PR is
merged.)
### Why is this needed?
This PR is needed because, for the Lodash optimization from
https://github.com/appsmithorg/appsmith/commit/7cbb12af886621256224be0c93e6a465dd710ad3,
we need to use `import type`. Otherwise, `babel-plugin-lodash` complains
that `LoDashStatic` is not a lodash function.
However, just using `import type` in the current codebase will give you
this:
<img width="962" alt="Screenshot 2023-03-08 at 17 45 59"
src="https://user-images.githubusercontent.com/2953267/223775744-407afa0c-e8b9-44a1-90f9-b879348da57f.png">
That’s because Prettier 1 can’t parse `import type` at all. To parse it,
we need to upgrade to Prettier 2.
### Why enforce `import type`?
Apart from just enabling `import type` support, this PR enforces
specifying `import type` everywhere it’s needed. (Developers will get
immediate TypeScript and ESLint errors when they forget to do so.)
I’m doing this because I believe `import type` improves DX and makes
refactorings easier.
Let’s say you had a few imports like below. Can you tell which of these
imports will increase the bundle size? (Tip: it’s not all of them!)
```ts
// app/client/src/workers/Linting/utils.ts
import { Position } from "codemirror";
import { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
It’s pretty hard, right?
What about now?
```ts
// app/client/src/workers/Linting/utils.ts
import type { Position } from "codemirror";
import type { LintError as JSHintError, LintOptions } from "jshint";
import { get, isEmpty, isNumber, keys, last, set } from "lodash";
```
Now, it’s clear that only `lodash` will be bundled.
This helps developers to see which imports are problematic, but it
_also_ helps with refactorings. Now, if you want to see where
`codemirror` is bundled, you can just grep for `import \{.*\} from
"codemirror"` – and you won’t get any type-only imports.
This also helps (some) bundlers. Upon transpiling, TypeScript erases
type-only imports completely. In some environment (not ours), this makes
the bundle smaller, as the bundler doesn’t need to bundle type-only
imports anymore.
## Type of change
- Chore (housekeeping or task changes that don't impact user perception)
## How Has This Been Tested?
This was tested to not break the build.
### 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
- [x] 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
- [x] 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:
- [ ] Test plan has been approved by relevant developers
- [ ] Test plan has been peer reviewed by QA
- [ ] Cypress test cases have been added and approved by either SDET or
manual QA
- [ ] Organized project review call with relevant stakeholders after
Round 1/2 of QA
- [ ] Added Test Plan Approved label after reveiwing all Cypress test
---------
Co-authored-by: Satish Gandham <hello@satishgandham.com>
Co-authored-by: Satish Gandham <satish.iitg@gmail.com>
2023-03-16 11:41:47 +00:00
|
|
|
import type { WidgetProps } from "./BaseWidget";
|
|
|
|
|
import type BaseWidget from "./BaseWidget";
|
2023-09-29 10:42:14 +00:00
|
|
|
import type { WidgetEntityConfig } from "@appsmith/entities/DataTree/types";
|
2023-10-02 19:41:05 +00:00
|
|
|
import { Positioning } from "layoutSystems/common/utils/constants";
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
import { isAutoHeightEnabledForWidget } from "./WidgetUtils";
|
2023-02-03 05:47:40 +00:00
|
|
|
import { CANVAS_DEFAULT_MIN_HEIGHT_PX } from "constants/AppConstants";
|
2023-04-26 07:18:16 +00:00
|
|
|
import { getGoogleMapsApiKey } from "@appsmith/selectors/tenantSelectors";
|
2023-03-20 11:04:02 +00:00
|
|
|
import ConfigTreeActions from "utils/configTree";
|
2023-03-23 05:43:07 +00:00
|
|
|
import { getSelectedWidgetAncestry } from "../selectors/widgetSelectors";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { getWidgetMinMaxDimensionsInPixel } from "layoutSystems/autolayout/utils/flexWidgetUtils";
|
2023-10-02 19:41:05 +00:00
|
|
|
import { defaultAutoLayoutWidgets } from "layoutSystems/autolayout/utils/constants";
|
2023-09-19 05:22:11 +00:00
|
|
|
import { getFlattenedChildCanvasWidgets } from "selectors/flattenedChildCanvasSelector";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2022-08-19 10:10:36 +00:00
|
|
|
|
|
|
|
|
const WIDGETS_WITH_CHILD_WIDGETS = ["LIST_WIDGET", "FORM_WIDGET"];
|
2023-03-23 05:43:07 +00:00
|
|
|
const WIDGETS_REQUIRING_SELECTED_ANCESTRY = ["MODAL_WIDGET", "TABS_WIDGET"];
|
2022-08-19 10:10:36 +00:00
|
|
|
function withWidgetProps(WrappedWidget: typeof BaseWidget) {
|
|
|
|
|
function WrappedPropsComponent(
|
|
|
|
|
props: WidgetProps & { skipWidgetPropsHydration?: boolean },
|
|
|
|
|
) {
|
2023-02-14 16:07:31 +00:00
|
|
|
const {
|
|
|
|
|
children,
|
|
|
|
|
hasMetaWidgets,
|
|
|
|
|
referencedWidgetId,
|
|
|
|
|
requiresFlatWidgetChildren,
|
|
|
|
|
skipWidgetPropsHydration,
|
|
|
|
|
type,
|
|
|
|
|
widgetId,
|
|
|
|
|
} = props;
|
2023-08-16 05:34:32 +00:00
|
|
|
|
2023-11-03 17:13:36 +00:00
|
|
|
const isPreviewMode = useSelector(combinedPreviewModeSelector);
|
2022-08-19 10:10:36 +00:00
|
|
|
const canvasWidget = useSelector((state: AppState) =>
|
|
|
|
|
getWidget(state, widgetId),
|
|
|
|
|
);
|
2023-05-11 04:45:14 +00:00
|
|
|
|
|
|
|
|
const mainCanvasWidth = useSelector(getCanvasWidth);
|
2023-02-14 16:07:31 +00:00
|
|
|
const metaWidget = useSelector(getMetaWidget(widgetId));
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
const mainCanvasProps = useSelector((state: AppState) =>
|
|
|
|
|
getMainCanvasProps(state),
|
|
|
|
|
);
|
2023-02-07 09:23:15 +00:00
|
|
|
const googleMapsApiKey = useSelector(getGoogleMapsApiKey);
|
2022-08-19 10:10:36 +00:00
|
|
|
const renderMode = useSelector(getRenderMode);
|
2023-02-14 16:07:31 +00:00
|
|
|
|
|
|
|
|
const widgetName = canvasWidget?.widgetName || metaWidget?.widgetName;
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
const evaluatedWidget = useSelector((state: AppState) =>
|
2023-02-14 16:07:31 +00:00
|
|
|
getWidgetEvalValues(state, widgetName),
|
2022-08-19 10:10:36 +00:00
|
|
|
);
|
2023-08-16 05:34:32 +00:00
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
const isLoading = useSelector((state: AppState) =>
|
2023-02-14 16:07:31 +00:00
|
|
|
getIsWidgetLoading(state, widgetName),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const metaWidgetChildrenStructure = useSelector(
|
|
|
|
|
getMetaWidgetChildrenStructure(widgetId, type, hasMetaWidgets),
|
|
|
|
|
equal,
|
2022-08-19 10:10:36 +00:00
|
|
|
);
|
2023-04-07 13:51:35 +00:00
|
|
|
const isMobile = useSelector(getIsAutoLayoutMobileBreakPoint);
|
2023-10-04 08:54:16 +00:00
|
|
|
const layoutSystemType = useSelector(getLayoutSystemType);
|
|
|
|
|
const isAutoLayout = layoutSystemType === LayoutSystemTypes.AUTO;
|
2022-08-19 10:10:36 +00:00
|
|
|
|
2023-03-20 11:04:02 +00:00
|
|
|
const configTree = ConfigTreeActions.getConfigTree();
|
|
|
|
|
const evaluatedWidgetConfig = configTree[
|
|
|
|
|
canvasWidget?.widgetName
|
|
|
|
|
] as WidgetEntityConfig;
|
|
|
|
|
|
2022-11-23 09:48:23 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
const childWidgets = useSelector((state: AppState) => {
|
|
|
|
|
if (!WIDGETS_WITH_CHILD_WIDGETS.includes(type)) return undefined;
|
|
|
|
|
return getChildWidgets(state, widgetId);
|
|
|
|
|
}, equal);
|
|
|
|
|
|
2023-02-14 16:07:31 +00:00
|
|
|
const flattenedChildCanvasWidgets = useSelector((state: AppState) => {
|
|
|
|
|
if (requiresFlatWidgetChildren) {
|
|
|
|
|
return getFlattenedChildCanvasWidgets(
|
|
|
|
|
state,
|
|
|
|
|
referencedWidgetId || widgetId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}, equal);
|
|
|
|
|
|
2023-03-23 05:43:07 +00:00
|
|
|
const selectedWidgetAncestry: string[] = useSelector((state: AppState) => {
|
|
|
|
|
if (!WIDGETS_REQUIRING_SELECTED_ANCESTRY.includes(type)) {
|
|
|
|
|
return [];
|
|
|
|
|
}
|
|
|
|
|
return getSelectedWidgetAncestry(state);
|
|
|
|
|
}, equal);
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
let widgetProps: WidgetProps = {} as WidgetProps;
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2023-02-14 16:07:31 +00:00
|
|
|
const widget = metaWidget || canvasWidget;
|
2022-08-19 10:10:36 +00:00
|
|
|
|
|
|
|
|
if (!skipWidgetPropsHydration) {
|
|
|
|
|
const canvasWidgetProps = (() => {
|
|
|
|
|
if (widgetId === MAIN_CONTAINER_WIDGET_ID) {
|
2023-02-03 05:47:40 +00:00
|
|
|
const computed = computeMainContainerWidget(
|
|
|
|
|
canvasWidget,
|
|
|
|
|
mainCanvasProps,
|
|
|
|
|
);
|
|
|
|
|
if (renderMode === RenderModes.CANVAS) {
|
|
|
|
|
return {
|
|
|
|
|
...computed,
|
|
|
|
|
bottomRow: Math.max(
|
|
|
|
|
computed.minHeight,
|
|
|
|
|
computed.bottomRow +
|
|
|
|
|
GridDefaults.MAIN_CANVAS_EXTENSION_OFFSET *
|
|
|
|
|
GridDefaults.DEFAULT_GRID_ROW_HEIGHT,
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
} else {
|
|
|
|
|
return {
|
|
|
|
|
...computed,
|
|
|
|
|
bottomRow: Math.max(
|
|
|
|
|
CANVAS_DEFAULT_MIN_HEIGHT_PX,
|
|
|
|
|
computed.bottomRow +
|
|
|
|
|
GridDefaults.VIEW_MODE_MAIN_CANVAS_EXTENSION_OFFSET *
|
|
|
|
|
GridDefaults.DEFAULT_GRID_ROW_HEIGHT,
|
|
|
|
|
),
|
|
|
|
|
};
|
|
|
|
|
}
|
2022-08-19 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return evaluatedWidget
|
2023-03-20 11:04:02 +00:00
|
|
|
? createCanvasWidget(widget, evaluatedWidget, evaluatedWidgetConfig)
|
2023-02-14 16:07:31 +00:00
|
|
|
: createLoadingWidget(widget);
|
2022-08-19 10:10:36 +00:00
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
widgetProps = { ...canvasWidgetProps };
|
2022-11-23 09:48:23 +00:00
|
|
|
|
2023-03-04 07:25:54 +00:00
|
|
|
widgetProps.isMobile = !!isMobile;
|
2023-03-23 05:43:07 +00:00
|
|
|
widgetProps.selectedWidgetAncestry = selectedWidgetAncestry || [];
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
/**
|
|
|
|
|
* MODAL_WIDGET by default is to be hidden unless the isVisible property is found.
|
|
|
|
|
* If the isVisible property is undefined and the widget is MODAL_WIDGET then isVisible
|
|
|
|
|
* is set to false
|
|
|
|
|
* If the isVisible property is undefined and the widget is not MODAL_WIDGET then isVisible
|
|
|
|
|
* is set to true
|
|
|
|
|
*/
|
|
|
|
|
widgetProps.isVisible =
|
|
|
|
|
canvasWidgetProps.isVisible ??
|
|
|
|
|
canvasWidgetProps.type !== "MODAL_WIDGET";
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
props.type === "CANVAS_WIDGET" &&
|
|
|
|
|
widgetId !== MAIN_CONTAINER_WIDGET_ID
|
|
|
|
|
) {
|
2022-11-24 18:40:06 +00:00
|
|
|
const isListWidgetCanvas =
|
|
|
|
|
props.noPad && props.dropDisabled && props.openParentPropertyPane;
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetProps.rightColumn = props.rightColumn;
|
2023-02-03 05:47:40 +00:00
|
|
|
if (isListWidgetCanvas) {
|
2022-11-23 09:48:23 +00:00
|
|
|
widgetProps.bottomRow = props.bottomRow;
|
|
|
|
|
widgetProps.minHeight = props.minHeight;
|
|
|
|
|
}
|
2023-02-03 05:47:40 +00:00
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetProps.shouldScrollContents = props.shouldScrollContents;
|
|
|
|
|
widgetProps.canExtend = props.canExtend;
|
|
|
|
|
widgetProps.parentId = props.parentId;
|
|
|
|
|
} else if (widgetId !== MAIN_CONTAINER_WIDGET_ID) {
|
|
|
|
|
widgetProps.parentColumnSpace = props.parentColumnSpace;
|
|
|
|
|
widgetProps.parentRowSpace = props.parentRowSpace;
|
|
|
|
|
widgetProps.parentId = props.parentId;
|
|
|
|
|
// Form Widget Props
|
|
|
|
|
widgetProps.onReset = props.onReset;
|
|
|
|
|
if ("isFormValid" in props) widgetProps.isFormValid = props.isFormValid;
|
|
|
|
|
}
|
2023-03-04 07:25:54 +00:00
|
|
|
if (defaultAutoLayoutWidgets.includes(props.type)) {
|
2023-04-07 13:51:35 +00:00
|
|
|
widgetProps.positioning = isAutoLayout
|
|
|
|
|
? Positioning.Vertical
|
|
|
|
|
: Positioning.Fixed;
|
2023-03-04 07:25:54 +00:00
|
|
|
}
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetProps.children = children;
|
2023-02-14 16:07:31 +00:00
|
|
|
widgetProps.metaWidgetChildrenStructure = metaWidgetChildrenStructure;
|
2022-08-19 10:10:36 +00:00
|
|
|
widgetProps.isLoading = isLoading;
|
|
|
|
|
widgetProps.childWidgets = childWidgets;
|
2023-02-14 16:07:31 +00:00
|
|
|
widgetProps.flattenedChildCanvasWidgets = flattenedChildCanvasWidgets;
|
2022-08-19 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
//merging with original props
|
2023-10-04 08:54:16 +00:00
|
|
|
widgetProps = { ...props, ...widgetProps, layoutSystemType, renderMode };
|
2022-08-19 10:10:36 +00:00
|
|
|
|
2023-02-07 09:23:15 +00:00
|
|
|
// adding google maps api key to widget props (although meant for map widget only)
|
|
|
|
|
widgetProps.googleMapsApiKey = googleMapsApiKey;
|
|
|
|
|
|
2022-08-19 10:10:36 +00:00
|
|
|
// isVisible prop defines whether to render a detached widget
|
2023-03-23 05:43:07 +00:00
|
|
|
if (
|
|
|
|
|
widgetProps.detachFromLayout &&
|
|
|
|
|
!widgetProps.isVisible &&
|
|
|
|
|
!selectedWidgetAncestry.includes(widgetProps.widgetId)
|
|
|
|
|
) {
|
2022-08-19 10:10:36 +00:00
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-23 09:48:23 +00:00
|
|
|
const shouldCollapseWidgetInViewOrPreviewMode =
|
|
|
|
|
!widgetProps.isVisible &&
|
2023-03-23 05:43:07 +00:00
|
|
|
!selectedWidgetAncestry.includes(widgetProps.widgetId) &&
|
2022-11-27 17:12:00 +00:00
|
|
|
(renderMode === RenderModes.PAGE || isPreviewMode);
|
2022-11-23 09:48:23 +00:00
|
|
|
|
|
|
|
|
const shouldResetCollapsedContainerHeightInViewOrPreviewMode =
|
|
|
|
|
widgetProps.isVisible && widgetProps.topRow === widgetProps.bottomRow;
|
|
|
|
|
|
|
|
|
|
const shouldResetCollapsedContainerHeightInCanvasMode =
|
|
|
|
|
widgetProps.topRow === widgetProps.bottomRow &&
|
2022-11-27 17:12:00 +00:00
|
|
|
renderMode === RenderModes.CANVAS &&
|
|
|
|
|
!isPreviewMode;
|
2022-11-23 09:48:23 +00:00
|
|
|
|
2023-09-13 13:57:42 +00:00
|
|
|
widgetProps.mainCanvasWidth = mainCanvasWidth;
|
2023-10-19 20:27:40 +00:00
|
|
|
if (layoutSystemType !== LayoutSystemTypes.ANVIL) {
|
|
|
|
|
// We don't render invisible widgets in view mode
|
|
|
|
|
if (shouldCollapseWidgetInViewOrPreviewMode) {
|
|
|
|
|
// This flag (isMetaWidget) is used to prevent the Auto height saga from updating
|
|
|
|
|
// the List widget Child Widgets. Auto height is disabled in the List widget and
|
|
|
|
|
// this flag serves as a way to avoid any unintended changes to the child widget's height.
|
|
|
|
|
if (
|
|
|
|
|
widgetProps.bottomRow !== widgetProps.topRow &&
|
|
|
|
|
!widgetProps.isMetaWidget
|
|
|
|
|
) {
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.UPDATE_WIDGET_AUTO_HEIGHT,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: props.widgetId,
|
|
|
|
|
height: 0,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
} else if (
|
|
|
|
|
shouldResetCollapsedContainerHeightInViewOrPreviewMode ||
|
|
|
|
|
shouldResetCollapsedContainerHeightInCanvasMode
|
2023-03-20 08:06:28 +00:00
|
|
|
) {
|
2023-10-19 20:27:40 +00:00
|
|
|
// We also need to check if a non-auto height widget has collapsed earlier
|
|
|
|
|
// We can figure this out if the widget height is zero and the beforeCollapse
|
|
|
|
|
// topRow and bottomRow are available.
|
|
|
|
|
|
|
|
|
|
// If the above is true, we call an auto height update call
|
|
|
|
|
// so that the widget can be reset correctly.
|
|
|
|
|
if (
|
|
|
|
|
widgetProps.topRow === widgetProps.bottomRow &&
|
|
|
|
|
widgetProps.topRowBeforeCollapse !== undefined &&
|
|
|
|
|
widgetProps.bottomRowBeforeCollapse !== undefined &&
|
|
|
|
|
!isAutoHeightEnabledForWidget(widgetProps)
|
|
|
|
|
) {
|
|
|
|
|
const heightBeforeCollapse =
|
|
|
|
|
(widgetProps.bottomRowBeforeCollapse -
|
|
|
|
|
widgetProps.topRowBeforeCollapse) *
|
|
|
|
|
GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
dispatch({
|
|
|
|
|
type: ReduxActionTypes.UPDATE_WIDGET_AUTO_HEIGHT,
|
|
|
|
|
payload: {
|
|
|
|
|
widgetId: props.widgetId,
|
|
|
|
|
height: heightBeforeCollapse,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
} else {
|
|
|
|
|
dispatch(checkContainersForAutoHeightAction());
|
|
|
|
|
}
|
2022-11-27 17:12:00 +00:00
|
|
|
}
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
|
2023-10-19 20:27:40 +00:00
|
|
|
// Sets the min/max height/width of the widget
|
|
|
|
|
if (isAutoLayout) {
|
|
|
|
|
const minMaxDimensions = getWidgetMinMaxDimensionsInPixel(
|
|
|
|
|
widgetProps,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
);
|
|
|
|
|
widgetProps = {
|
|
|
|
|
...widgetProps,
|
|
|
|
|
minWidth: minMaxDimensions.minWidth
|
|
|
|
|
? minMaxDimensions.minWidth - 2 * WIDGET_PADDING
|
|
|
|
|
: undefined,
|
|
|
|
|
minHeight: minMaxDimensions.minHeight
|
|
|
|
|
? minMaxDimensions.minHeight - 2 * WIDGET_PADDING
|
|
|
|
|
: undefined,
|
|
|
|
|
maxWidth: minMaxDimensions.maxWidth
|
|
|
|
|
? minMaxDimensions.maxWidth - 2 * WIDGET_PADDING
|
|
|
|
|
: undefined,
|
|
|
|
|
maxHeight: minMaxDimensions.maxHeight
|
|
|
|
|
? minMaxDimensions.maxHeight - 2 * WIDGET_PADDING
|
|
|
|
|
: undefined,
|
|
|
|
|
};
|
feat: Non auto height invisible widgets (#20118)
## Description
This PR adds another feature update we had planned for Auto Height
- [ ] For new applications, in View and Preview mode, any widget which
is invisible will let go of its space and collapse if it's either on the
main Canvas or a container-like widget which has Auto-height enabled.
- [ ] Widgets within a container-like Widget, say Tabs, that doesn't
have Auto-height enabled, will now let go of their space if they're
invisible.
- [ ] The experience in Edit mode has not changed.
TL;DR: In new applications, in the Preview and Published _AKA_ View
modes, if a widget is invisible and within an Auto-height-enabled
container like a Tab, a Modal, a Form, or the main Canvas, it will fully
collapse, allowing widgets below it to move up and take its space. This
changes the behavior today prior to the release of this PR for
Auto-height-enabled widgets.
Fixes #19983
Fixes #18681
2023-02-14 13:36:19 +00:00
|
|
|
}
|
2022-08-19 10:10:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <WrappedWidget {...widgetProps} />;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return WrappedPropsComponent;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default withWidgetProps;
|