2024-08-06 14:52:22 +00:00
import { ReduxActionTypes } from "ee/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 {
2022-11-23 09:48:23 +00:00
PropertyPaneConfig ,
PropertyPaneControlConfig ,
} from "constants/PropertyControlConstants" ;
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 { WidgetType } from "constants/WidgetConstants" ;
import { GridDefaults , WidgetHeightLimits } from "constants/WidgetConstants" ;
import type { WidgetProps } from "widgets/BaseWidget" ;
2023-09-06 12:15:04 +00:00
import type BaseWidget from "widgets/BaseWidget" ;
2022-04-22 09:44:22 +00:00
2022-11-23 09:48:23 +00:00
export enum RegisteredWidgetFeatures {
DYNAMIC_HEIGHT = "dynamicHeight" ,
2022-04-22 09:44:22 +00:00
}
2022-11-24 18:40:06 +00:00
interface WidgetFeatureConfig {
active : boolean ;
defaultValue? : DynamicHeight ;
sectionIndex : number ;
2024-02-07 11:00:50 +00:00
helperText ? : ( props? : WidgetProps ) = > PropertyPaneControlConfig [ "helperText" ] ;
2022-11-24 18:40:06 +00:00
}
export type WidgetFeatures = Record <
RegisteredWidgetFeatures ,
WidgetFeatureConfig
> ;
2022-11-23 09:48:23 +00:00
2022-04-22 09:44:22 +00:00
export enum DynamicHeight {
2022-11-23 09:48:23 +00:00
AUTO_HEIGHT = "AUTO_HEIGHT" ,
2022-04-22 09:44:22 +00:00
FIXED = "FIXED" ,
2022-11-23 09:48:23 +00:00
AUTO_HEIGHT_WITH_LIMITS = "AUTO_HEIGHT_WITH_LIMITS" ,
2022-04-22 09:44:22 +00:00
}
2022-11-24 18:40:06 +00:00
/ * T h i s c o n t a i n s a l l p r o p e r t i e s w h i c h w i l l b e a d d e d
2022-04-22 09:44:22 +00:00
to a widget , automatically , by the Appsmith platform
Each feature , is a unique key , whose value is an object
with the list of properties to be added to a widget along
with their default values
Note : These are added to the widget configs during registration
* /
2022-11-23 09:48:23 +00:00
export const WidgetFeatureProps : Record <
RegisteredWidgetFeatures ,
Record < string , unknown >
> = {
[ RegisteredWidgetFeatures . DYNAMIC_HEIGHT ] : {
minDynamicHeight : WidgetHeightLimits.MIN_HEIGHT_IN_ROWS ,
maxDynamicHeight : WidgetHeightLimits.MAX_HEIGHT_IN_ROWS ,
2022-04-22 09:44:22 +00:00
dynamicHeight : DynamicHeight.FIXED ,
} ,
} ;
2022-11-23 09:48:23 +00:00
export const WidgetFeaturePropertyEnhancements : Record <
RegisteredWidgetFeatures ,
2023-09-06 12:15:04 +00:00
( config : typeof BaseWidget ) = > Record < string , unknown >
2022-11-23 09:48:23 +00:00
> = {
2023-09-06 12:15:04 +00:00
[ RegisteredWidgetFeatures . DYNAMIC_HEIGHT ] : ( widget : typeof BaseWidget ) = > {
const features = widget . getFeatures ( ) ;
const defaults = widget . getDefaults ( ) ;
const config = widget . getConfig ( ) ;
2022-11-23 09:48:23 +00:00
const newProperties : Partial < WidgetProps > = { } ;
2022-11-24 18:40:06 +00:00
newProperties . dynamicHeight =
2023-09-06 12:15:04 +00:00
features ? . dynamicHeight ? . defaultValue || DynamicHeight . AUTO_HEIGHT ;
2022-11-23 09:48:23 +00:00
if ( config . isCanvas ) {
newProperties . dynamicHeight = DynamicHeight . AUTO_HEIGHT ;
2022-11-24 18:40:06 +00:00
newProperties . minDynamicHeight =
2023-09-06 12:15:04 +00:00
defaults . minDynamicHeight ||
2022-11-24 18:40:06 +00:00
WidgetHeightLimits . MIN_CANVAS_HEIGHT_IN_ROWS ;
2022-12-23 11:35:27 +00:00
newProperties . maxDynamicHeight =
2023-09-06 12:15:04 +00:00
defaults . maxDynamicHeight || WidgetHeightLimits . MAX_HEIGHT_IN_ROWS ;
2022-11-23 09:48:23 +00:00
newProperties . shouldScrollContents = true ;
2022-12-23 11:35:27 +00:00
} else {
newProperties . minDynamicHeight =
2023-09-06 12:15:04 +00:00
defaults . minDynamicHeight || WidgetHeightLimits . MIN_HEIGHT_IN_ROWS ;
2022-12-23 11:35:27 +00:00
newProperties . maxDynamicHeight =
2023-09-06 12:15:04 +00:00
defaults . maxDynamicHeight || WidgetHeightLimits . MAX_HEIGHT_IN_ROWS ;
2022-11-23 09:48:23 +00:00
}
2023-09-06 12:15:04 +00:00
if ( defaults . overflow ) newProperties . overflow = "NONE" ;
2022-11-23 09:48:23 +00:00
return newProperties ;
} ,
} ;
function findAndUpdatePropertyPaneControlConfig (
config : PropertyPaneConfig [ ] ,
propertyPaneUpdates : Record < string , Record < string , unknown > > ,
) : PropertyPaneConfig [ ] {
return config . map ( ( sectionConfig : PropertyPaneConfig ) = > {
if (
Array . isArray ( sectionConfig . children ) &&
sectionConfig . children . length > 0
) {
Object . keys ( propertyPaneUpdates ) . forEach ( ( propertyName : string ) = > {
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
const controlConfigIndex : number | undefined =
sectionConfig . children ? . findIndex (
( controlConfig : PropertyPaneConfig ) = >
( controlConfig as PropertyPaneControlConfig ) . propertyName ===
propertyName ,
) ;
2022-11-23 09:48:23 +00:00
if (
controlConfigIndex !== undefined &&
controlConfigIndex > - 1 &&
sectionConfig . children
) {
sectionConfig . children [ controlConfigIndex ] = {
. . . sectionConfig . children [ controlConfigIndex ] ,
. . . propertyPaneUpdates [ propertyName ] ,
} ;
}
} ) ;
}
return sectionConfig ;
} ) ;
}
export const WidgetFeaturePropertyPaneEnhancements : Record <
RegisteredWidgetFeatures ,
2022-11-24 18:40:06 +00:00
(
config : PropertyPaneConfig [ ] ,
widgetType? : WidgetType ,
) = > PropertyPaneConfig [ ]
2022-11-23 09:48:23 +00:00
> = {
2022-11-24 18:40:06 +00:00
[ RegisteredWidgetFeatures . DYNAMIC_HEIGHT ] : (
config : PropertyPaneConfig [ ] ,
widgetType? : WidgetType ,
) = > {
2022-11-23 09:48:23 +00:00
function hideWhenDynamicHeightIsEnabled ( props : WidgetProps ) {
return (
props . dynamicHeight === DynamicHeight . AUTO_HEIGHT_WITH_LIMITS ||
props . dynamicHeight === DynamicHeight . AUTO_HEIGHT
) ;
}
2022-11-24 18:40:06 +00:00
let update = findAndUpdatePropertyPaneControlConfig ( config , {
2022-11-23 09:48:23 +00:00
shouldScrollContents : {
hidden : hideWhenDynamicHeightIsEnabled ,
dependencies : [ "dynamicHeight" ] ,
} ,
scrollContents : {
hidden : hideWhenDynamicHeightIsEnabled ,
dependencies : [ "dynamicHeight" ] ,
} ,
fixedFooter : {
hidden : hideWhenDynamicHeightIsEnabled ,
dependencies : [ "dynamicHeight" ] ,
} ,
overflow : {
hidden : hideWhenDynamicHeightIsEnabled ,
dependencies : [ "dynamicHeight" ] ,
} ,
} ) ;
2022-11-24 18:40:06 +00:00
if ( widgetType === "MODAL_WIDGET" ) {
update = findAndUpdatePropertyPaneControlConfig ( update , {
dynamicHeight : {
options : [
{
label : "Auto Height" ,
value : DynamicHeight.AUTO_HEIGHT ,
} ,
{
label : "Fixed" ,
value : DynamicHeight.FIXED ,
} ,
] ,
} ,
} ) ;
}
return update ;
2022-11-23 09:48:23 +00:00
} ,
} ;
2022-04-22 09:44:22 +00:00
/ * H i d e t h e m i n h e i g h t a n d m a x h e i g h t p r o p e r t i e s u s i n g t h i s f u n c t i o n
as the ` hidden ` hook in the property pane configuration
This function checks if the ` dynamicHeight ` property is enabled
and returns true if disabled , and false if enabled .
* /
export function hideDynamicHeightPropertyControl ( props : WidgetProps ) {
2022-11-23 09:48:23 +00:00
return props . dynamicHeight !== DynamicHeight . AUTO_HEIGHT_WITH_LIMITS ;
2022-04-22 09:44:22 +00:00
}
2022-11-23 09:48:23 +00:00
// TODO (abhinav): ADD_UNIT_TESTS
function updateMinMaxDynamicHeight (
props : WidgetProps ,
propertyName : string ,
propertyValue : unknown ,
) {
const updates = [
{
propertyPath : propertyName ,
propertyValue : propertyValue ,
} ,
] ;
if ( propertyValue === DynamicHeight . AUTO_HEIGHT_WITH_LIMITS ) {
const minDynamicHeight = parseInt ( props . minDynamicHeight , 10 ) ;
if (
isNaN ( minDynamicHeight ) ||
minDynamicHeight < WidgetHeightLimits . MIN_HEIGHT_IN_ROWS
) {
updates . push ( {
propertyPath : "minDynamicHeight" ,
propertyValue : WidgetHeightLimits.MIN_HEIGHT_IN_ROWS ,
} ) ;
}
const maxDynamicHeight = parseInt ( props . maxDynamicHeight , 10 ) ;
if (
isNaN ( maxDynamicHeight ) ||
maxDynamicHeight === WidgetHeightLimits . MAX_HEIGHT_IN_ROWS ||
maxDynamicHeight <= WidgetHeightLimits . MIN_HEIGHT_IN_ROWS
) {
updates . push ( {
propertyPath : "maxDynamicHeight" ,
2022-11-24 18:40:06 +00:00
propertyValue :
props . bottomRow - props . topRow + GridDefaults . CANVAS_EXTENSION_OFFSET ,
2022-11-23 09:48:23 +00:00
} ) ;
}
// Case where maxDynamicHeight is zero
if ( isNaN ( maxDynamicHeight ) || maxDynamicHeight === 0 ) {
updates . push ( {
propertyPath : "maxDynamicHeight" ,
propertyValue : props.bottomRow - props . topRow ,
} ) ;
}
} else if ( propertyValue === DynamicHeight . AUTO_HEIGHT ) {
2022-11-24 18:40:06 +00:00
const minHeightInRows = props . isCanvas
? WidgetHeightLimits . MIN_CANVAS_HEIGHT_IN_ROWS
: WidgetHeightLimits . MIN_HEIGHT_IN_ROWS ;
2022-11-23 09:48:23 +00:00
updates . push (
2022-04-22 09:44:22 +00:00
{
2022-11-23 09:48:23 +00:00
propertyPath : "minDynamicHeight" ,
2022-11-24 18:40:06 +00:00
propertyValue : minHeightInRows ,
2022-04-22 09:44:22 +00:00
} ,
{
2022-11-23 09:48:23 +00:00
propertyPath : "maxDynamicHeight" ,
propertyValue : WidgetHeightLimits.MAX_HEIGHT_IN_ROWS ,
2022-04-22 09:44:22 +00:00
} ,
2022-11-23 09:48:23 +00:00
) ;
}
if ( propertyValue === DynamicHeight . FIXED ) {
updates . push ( {
propertyPath : "originalBottomRow" ,
propertyValue : undefined ,
} ) ;
updates . push ( {
propertyPath : "originalTopRow" ,
propertyValue : undefined ,
} ) ;
}
// The following are updates which apply to specific widgets.
if (
propertyValue === DynamicHeight . AUTO_HEIGHT ||
propertyValue === DynamicHeight . AUTO_HEIGHT_WITH_LIMITS
) {
if ( props . dynamicHeight === DynamicHeight . FIXED ) {
updates . push ( {
propertyPath : "originalBottomRow" ,
propertyValue : props.bottomRow ,
} ) ;
updates . push ( {
propertyPath : "originalTopRow" ,
propertyValue : props.topRow ,
} ) ;
}
if ( ! props . shouldScrollContents ) {
updates . push ( {
propertyPath : "shouldScrollContents" ,
propertyValue : true ,
} ) ;
}
if ( props . overflow !== undefined ) {
updates . push ( {
propertyPath : "overflow" ,
propertyValue : "NONE" ,
} ) ;
}
if ( props . scrollContents === true ) {
updates . push ( {
propertyPath : "scrollContents" ,
propertyValue : false ,
} ) ;
}
if ( props . fixedFooter === true ) {
updates . push ( {
propertyPath : "fixedFooter" ,
propertyValue : false ,
} ) ;
}
}
return updates ;
}
// TODO FEATURE:(abhinav) Add validations to these properties
const CONTAINER_SCROLL_HELPER_TEXT =
2022-11-24 18:40:06 +00:00
"This widget shows an internal scroll when you add widgets in edit mode. It'll resize after you've added widgets. The scroll won't exist in view mode." ;
2022-11-23 09:48:23 +00:00
export const PropertyPaneConfigTemplates : Record <
RegisteredWidgetFeatures ,
2024-02-07 11:00:50 +00:00
( featureConfig : WidgetFeatureConfig ) = > PropertyPaneConfig [ ]
2022-11-23 09:48:23 +00:00
> = {
2024-02-07 11:00:50 +00:00
[ RegisteredWidgetFeatures . DYNAMIC_HEIGHT ] : ( featureConfig ) = > [
2022-11-23 09:48:23 +00:00
{
helpText :
"Auto Height: Configure the way the widget height reacts to content changes." ,
propertyName : "dynamicHeight" ,
label : "Height" ,
controlType : "DROP_DOWN" ,
isBindProperty : false ,
isTriggerProperty : false ,
dependencies : [
"shouldScrollContents" ,
"maxDynamicHeight" ,
"minDynamicHeight" ,
"bottomRow" ,
"topRow" ,
"overflow" ,
"dynamicHeight" ,
"isCanvas" ,
] ,
updateHook : updateMinMaxDynamicHeight ,
2024-02-07 11:00:50 +00:00
//TODO: Canvas widgets should also use the helper text config of dynamic height feature
// instead of using a hardcoded string
2022-11-23 09:48:23 +00:00
helperText : ( props : WidgetProps ) = > {
return props . isCanvas &&
props . dynamicHeight === DynamicHeight . AUTO_HEIGHT
? CONTAINER_SCROLL_HELPER_TEXT
2024-02-07 11:00:50 +00:00
: featureConfig . helperText ? . ( props ) || "" ;
2022-04-22 09:44:22 +00:00
} ,
2022-11-23 09:48:23 +00:00
options : [
{
label : "Auto Height" ,
value : DynamicHeight.AUTO_HEIGHT ,
} ,
{
label : "Auto Height with limits" ,
value : DynamicHeight.AUTO_HEIGHT_WITH_LIMITS ,
} ,
{
label : "Fixed" ,
value : DynamicHeight.FIXED ,
} ,
] ,
postUpdateAction : ReduxActionTypes.CHECK_CONTAINERS_FOR_AUTO_HEIGHT ,
} ,
] ,
2022-04-22 09:44:22 +00:00
} ;