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 {
|
2021-09-21 07:55:56 +00:00
|
|
|
MultipleWidgetDeletePayload,
|
|
|
|
|
WidgetDelete,
|
|
|
|
|
} from "actions/pageActions";
|
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 { updateAndSaveLayout } from "actions/pageActions";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { closePropertyPane, closeTableFilterPane } from "actions/widgetActions";
|
|
|
|
|
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
|
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 { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
2021-09-21 07:55:56 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
WidgetReduxActionTypes,
|
2022-04-12 10:50:01 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { ENTITY_TYPE } from "entities/AppsmithConsole";
|
|
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
2022-03-17 10:58:26 +00:00
|
|
|
import { flattenDeep, omit, orderBy } from "lodash";
|
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 {
|
2021-09-21 07:55:56 +00:00
|
|
|
CanvasWidgetsReduxState,
|
|
|
|
|
FlattenedWidgetProps,
|
|
|
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
|
import { all, call, put, select, takeEvery } from "redux-saga/effects";
|
2023-04-07 13:51:35 +00:00
|
|
|
import {
|
|
|
|
|
getCanvasWidth,
|
|
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
|
|
|
|
} from "selectors/editorSelectors";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { getSelectedWidgets } from "selectors/ui";
|
|
|
|
|
import AnalyticsUtil from "utils/AnalyticsUtil";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
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 "widgets/BaseWidget";
|
2023-05-11 04:45:14 +00:00
|
|
|
import {
|
|
|
|
|
getSelectedWidget,
|
|
|
|
|
getWidget,
|
|
|
|
|
getWidgets,
|
|
|
|
|
getWidgetsMeta,
|
|
|
|
|
} from "./selectors";
|
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 { WidgetsInTree } from "./WidgetOperationUtils";
|
2021-11-08 12:22:41 +00:00
|
|
|
import {
|
|
|
|
|
getAllWidgetsInTree,
|
|
|
|
|
updateListWidgetPropertiesOnChildDelete,
|
|
|
|
|
} from "./WidgetOperationUtils";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { showUndoRedoToast } from "utils/replayHelpers";
|
2023-09-06 12:15:04 +00:00
|
|
|
import WidgetFactory from "WidgetProvider/factory";
|
2022-01-25 13:56:52 +00:00
|
|
|
import {
|
|
|
|
|
inGuidedTour,
|
|
|
|
|
isExploringSelector,
|
|
|
|
|
} from "selectors/onboardingSelectors";
|
|
|
|
|
import { toggleShowDeviationDialog } from "actions/onboardingActions";
|
2022-11-23 09:48:23 +00:00
|
|
|
import { generateAutoHeightLayoutTreeAction } from "actions/autoHeightActions";
|
2023-01-28 02:17:06 +00:00
|
|
|
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { updateFlexLayersOnDelete } from "../layoutSystems/autolayout/utils/AutoLayoutUtils";
|
2023-10-19 20:27:40 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
|
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
|
|
|
|
import { updateAnvilParentPostWidgetDeletion } from "layoutSystems/anvil/utils/layouts/update/deletionUtils";
|
2023-01-28 02:17:06 +00:00
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
const WidgetTypes = WidgetFactory.widgetTypes;
|
|
|
|
|
|
2023-10-11 07:35:24 +00:00
|
|
|
interface WidgetDeleteTabChild {
|
2021-09-21 07:55:56 +00:00
|
|
|
id: string;
|
|
|
|
|
index: number;
|
|
|
|
|
isVisible: boolean;
|
|
|
|
|
label: string;
|
|
|
|
|
widgetId: string;
|
2023-10-11 07:35:24 +00:00
|
|
|
}
|
2021-09-21 07:55:56 +00:00
|
|
|
|
|
|
|
|
function* deleteTabChildSaga(
|
|
|
|
|
deleteChildTabAction: ReduxAction<WidgetDeleteTabChild>,
|
|
|
|
|
) {
|
|
|
|
|
const { index, label, widgetId } = deleteChildTabAction.payload;
|
|
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
const tabWidget = allWidgets[widgetId];
|
|
|
|
|
if (tabWidget && tabWidget.parentId) {
|
|
|
|
|
const tabParentWidget = allWidgets[tabWidget.parentId];
|
2022-03-17 10:58:26 +00:00
|
|
|
const tabsArray: any = orderBy(
|
|
|
|
|
Object.values(tabParentWidget.tabsObj),
|
|
|
|
|
"index",
|
|
|
|
|
"asc",
|
|
|
|
|
);
|
2021-09-21 07:55:56 +00:00
|
|
|
if (tabsArray && tabsArray.length === 1) return;
|
|
|
|
|
const updatedArray = tabsArray.filter((eachItem: any, i: number) => {
|
|
|
|
|
return i !== index;
|
|
|
|
|
});
|
|
|
|
|
const updatedObj = updatedArray.reduce(
|
|
|
|
|
(obj: any, each: any, index: number) => {
|
|
|
|
|
obj[each.id] = {
|
|
|
|
|
...each,
|
|
|
|
|
index,
|
|
|
|
|
};
|
|
|
|
|
return obj;
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
);
|
|
|
|
|
const updatedDslObj: UpdatedDSLPostDelete = yield call(
|
|
|
|
|
getUpdatedDslAfterDeletingWidget,
|
|
|
|
|
widgetId,
|
|
|
|
|
tabWidget.parentId,
|
|
|
|
|
);
|
|
|
|
|
if (updatedDslObj) {
|
|
|
|
|
const { finalWidgets, otherWidgetsToDelete } = updatedDslObj;
|
|
|
|
|
const parentUpdatedWidgets = {
|
|
|
|
|
...finalWidgets,
|
|
|
|
|
[tabParentWidget.widgetId]: {
|
|
|
|
|
...finalWidgets[tabParentWidget.widgetId],
|
|
|
|
|
tabsObj: updatedObj,
|
|
|
|
|
},
|
|
|
|
|
};
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes =
|
|
|
|
|
yield select(getLayoutSystemType);
|
|
|
|
|
let finalData: CanvasWidgetsReduxState = parentUpdatedWidgets;
|
|
|
|
|
if (layoutSystemType === LayoutSystemTypes.AUTO) {
|
|
|
|
|
// Update flex layers of a canvas upon deletion of a widget.
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getCanvasWidth);
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
finalData = yield call(
|
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
|
|
|
updateFlexLayersOnDelete,
|
|
|
|
|
parentUpdatedWidgets,
|
|
|
|
|
widgetId,
|
|
|
|
|
tabWidget.parentId,
|
|
|
|
|
isMobile,
|
2023-04-07 13:51:35 +00:00
|
|
|
mainCanvasWidth,
|
2023-05-11 04:45:14 +00:00
|
|
|
metaProps,
|
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
|
|
|
);
|
2023-10-19 20:27:40 +00:00
|
|
|
} else if (layoutSystemType === LayoutSystemTypes.ANVIL) {
|
|
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
|
|
|
|
parentUpdatedWidgets,
|
|
|
|
|
tabWidget.parentId,
|
|
|
|
|
widgetId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
yield put(updateAndSaveLayout(finalData));
|
2021-09-21 07:55:56 +00:00
|
|
|
yield call(postDelete, widgetId, label, otherWidgetsToDelete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* deleteSagaInit(deleteAction: ReduxAction<WidgetDelete>) {
|
|
|
|
|
const { widgetId } = deleteAction.payload;
|
2023-10-11 07:14:38 +00:00
|
|
|
const selectedWidget: FlattenedWidgetProps | undefined =
|
|
|
|
|
yield select(getSelectedWidget);
|
2021-09-21 07:55:56 +00:00
|
|
|
const selectedWidgets: string[] = yield select(getSelectedWidgets);
|
2022-06-21 13:57:34 +00:00
|
|
|
const guidedTourEnabled: boolean = yield select(inGuidedTour);
|
|
|
|
|
const isExploring: boolean = yield select(isExploringSelector);
|
2022-01-25 13:56:52 +00:00
|
|
|
|
|
|
|
|
if (guidedTourEnabled && !isExploring) {
|
|
|
|
|
yield put(toggleShowDeviationDialog(true));
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
if (selectedWidgets.length > 1) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: WidgetReduxActionTypes.WIDGET_BULK_DELETE,
|
|
|
|
|
payload: deleteAction.payload,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
if (!!widgetId || !!selectedWidget) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: WidgetReduxActionTypes.WIDGET_SINGLE_DELETE,
|
|
|
|
|
payload: deleteAction.payload,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type UpdatedDSLPostDelete =
|
|
|
|
|
| {
|
|
|
|
|
finalWidgets: CanvasWidgetsReduxState;
|
|
|
|
|
otherWidgetsToDelete: (WidgetProps & {
|
|
|
|
|
children?: string[] | undefined;
|
|
|
|
|
})[];
|
|
|
|
|
widgetName: string;
|
|
|
|
|
}
|
|
|
|
|
| undefined;
|
|
|
|
|
|
|
|
|
|
function* getUpdatedDslAfterDeletingWidget(widgetId: string, parentId: string) {
|
|
|
|
|
const stateWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
if (widgetId && parentId) {
|
|
|
|
|
const widgets = { ...stateWidgets };
|
|
|
|
|
const stateWidget: WidgetProps = yield select(getWidget, widgetId);
|
|
|
|
|
const widget = { ...stateWidget };
|
|
|
|
|
|
|
|
|
|
const stateParent: FlattenedWidgetProps = yield select(getWidget, parentId);
|
|
|
|
|
let parent = { ...stateParent };
|
|
|
|
|
|
|
|
|
|
// Remove entry from parent's children
|
|
|
|
|
|
|
|
|
|
if (parent.children) {
|
|
|
|
|
parent = {
|
|
|
|
|
...parent,
|
|
|
|
|
children: parent.children.filter((c) => c !== widgetId),
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
widgets[parentId] = parent;
|
|
|
|
|
|
|
|
|
|
const otherWidgetsToDelete = getAllWidgetsInTree(widgetId, widgets);
|
|
|
|
|
let widgetName = widget.widgetName;
|
|
|
|
|
// SPECIAL HANDLING FOR TABS IN A TABS WIDGET
|
|
|
|
|
if (parent.type === WidgetTypes.TABS_WIDGET && widget.tabName) {
|
|
|
|
|
widgetName = widget.tabName;
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
let finalWidgets: CanvasWidgetsReduxState =
|
|
|
|
|
updateListWidgetPropertiesOnChildDelete(widgets, widgetId, widgetName);
|
2021-09-21 07:55:56 +00:00
|
|
|
|
|
|
|
|
finalWidgets = omit(
|
|
|
|
|
finalWidgets,
|
|
|
|
|
otherWidgetsToDelete.map((widgets) => widgets.widgetId),
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
finalWidgets,
|
|
|
|
|
otherWidgetsToDelete,
|
|
|
|
|
widgetName,
|
|
|
|
|
} as UpdatedDSLPostDelete;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* deleteSaga(deleteAction: ReduxAction<WidgetDelete>) {
|
|
|
|
|
try {
|
|
|
|
|
let { parentId, widgetId } = deleteAction.payload;
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
const { disallowUndo, isShortcut } = deleteAction.payload;
|
|
|
|
|
|
|
|
|
|
if (!widgetId) {
|
2023-10-11 07:14:38 +00:00
|
|
|
const selectedWidget: FlattenedWidgetProps | undefined =
|
|
|
|
|
yield select(getSelectedWidget);
|
2021-09-21 07:55:56 +00:00
|
|
|
if (!selectedWidget) return;
|
|
|
|
|
|
2022-01-25 13:56:52 +00:00
|
|
|
// if widget is not deletable, don't do anything
|
2021-09-21 07:55:56 +00:00
|
|
|
if (selectedWidget.isDeletable === false) return false;
|
|
|
|
|
|
|
|
|
|
widgetId = selectedWidget.widgetId;
|
|
|
|
|
parentId = selectedWidget.parentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (widgetId && parentId) {
|
|
|
|
|
const stateWidget: WidgetProps = yield select(getWidget, widgetId);
|
|
|
|
|
const widget = { ...stateWidget };
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
const updatedObj: UpdatedDSLPostDelete = yield call(
|
|
|
|
|
getUpdatedDslAfterDeletingWidget,
|
|
|
|
|
widgetId,
|
|
|
|
|
parentId,
|
|
|
|
|
);
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
if (updatedObj) {
|
|
|
|
|
const { finalWidgets, otherWidgetsToDelete, widgetName } = updatedObj;
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes =
|
|
|
|
|
yield select(getLayoutSystemType);
|
|
|
|
|
let finalData: CanvasWidgetsReduxState = finalWidgets;
|
|
|
|
|
if (layoutSystemType === LayoutSystemTypes.AUTO) {
|
|
|
|
|
const isMobile: boolean = yield select(
|
|
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
|
|
|
|
);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getCanvasWidth);
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
// Update flex layers of a canvas upon deletion of a widget.
|
|
|
|
|
finalData = updateFlexLayersOnDelete(
|
2023-04-07 13:51:35 +00:00
|
|
|
finalWidgets,
|
|
|
|
|
widgetId,
|
|
|
|
|
parentId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
2023-05-11 04:45:14 +00:00
|
|
|
metaProps,
|
2023-04-07 13:51:35 +00:00
|
|
|
);
|
2023-10-19 20:27:40 +00:00
|
|
|
} else if (layoutSystemType === LayoutSystemTypes.ANVIL) {
|
|
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
|
|
|
|
finalWidgets,
|
|
|
|
|
parentId,
|
|
|
|
|
widgetId,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
yield put(updateAndSaveLayout(finalData));
|
2022-11-23 09:48:23 +00:00
|
|
|
yield put(generateAutoHeightLayoutTreeAction(true, true));
|
2021-09-21 07:55:56 +00:00
|
|
|
const analyticsEvent = isShortcut
|
|
|
|
|
? "WIDGET_DELETE_VIA_SHORTCUT"
|
|
|
|
|
: "WIDGET_DELETE";
|
|
|
|
|
|
|
|
|
|
AnalyticsUtil.logEvent(analyticsEvent, {
|
|
|
|
|
widgetName: widget.widgetName,
|
|
|
|
|
widgetType: widget.type,
|
|
|
|
|
});
|
|
|
|
|
if (!disallowUndo) {
|
|
|
|
|
// close property pane after delete
|
|
|
|
|
yield put(closePropertyPane());
|
2023-01-28 02:17:06 +00:00
|
|
|
yield put(
|
|
|
|
|
selectWidgetInitAction(SelectionRequestType.Unselect, [widgetId]),
|
|
|
|
|
);
|
2021-09-21 07:55:56 +00:00
|
|
|
yield call(postDelete, widgetId, widgetName, otherWidgetsToDelete);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.WIDGET_OPERATION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
action: WidgetReduxActionTypes.WIDGET_DELETE,
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* deleteAllSelectedWidgetsSaga(
|
|
|
|
|
deleteAction: ReduxAction<MultipleWidgetDeletePayload>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const { disallowUndo = false } = deleteAction.payload;
|
2022-06-21 13:57:34 +00:00
|
|
|
const stateWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
2021-09-21 07:55:56 +00:00
|
|
|
const widgets = { ...stateWidgets };
|
|
|
|
|
const selectedWidgets: string[] = yield select(getSelectedWidgets);
|
|
|
|
|
if (!(selectedWidgets && selectedWidgets.length !== 1)) return;
|
2022-06-21 13:57:34 +00:00
|
|
|
const widgetsToBeDeleted: WidgetsInTree = yield all(
|
2021-09-21 07:55:56 +00:00
|
|
|
selectedWidgets.map((eachId) => {
|
|
|
|
|
return call(getAllWidgetsInTree, eachId, widgets);
|
|
|
|
|
}),
|
|
|
|
|
);
|
2022-06-21 13:57:34 +00:00
|
|
|
const flattenedWidgets = flattenDeep(widgetsToBeDeleted);
|
2023-02-14 16:07:31 +00:00
|
|
|
|
2022-01-28 11:10:05 +00:00
|
|
|
const parentUpdatedWidgets = flattenedWidgets.reduce(
|
2021-09-21 07:55:56 +00:00
|
|
|
(allWidgets: any, eachWidget: any) => {
|
|
|
|
|
const { parentId, widgetId } = eachWidget;
|
|
|
|
|
const stateParent: FlattenedWidgetProps = allWidgets[parentId];
|
|
|
|
|
let parent = { ...stateParent };
|
|
|
|
|
if (parent.children) {
|
|
|
|
|
parent = {
|
|
|
|
|
...parent,
|
|
|
|
|
children: parent.children.filter((c) => c !== widgetId),
|
|
|
|
|
};
|
|
|
|
|
allWidgets[parentId] = parent;
|
|
|
|
|
}
|
|
|
|
|
return allWidgets;
|
|
|
|
|
},
|
|
|
|
|
widgets,
|
|
|
|
|
);
|
|
|
|
|
const finalWidgets: CanvasWidgetsReduxState = omit(
|
|
|
|
|
parentUpdatedWidgets,
|
2022-01-28 11:10:05 +00:00
|
|
|
flattenedWidgets.map((widgets: any) => widgets.widgetId),
|
2021-09-21 07:55:56 +00:00
|
|
|
);
|
2023-10-19 20:27:40 +00:00
|
|
|
let finalData = finalWidgets;
|
2023-03-04 07:25:54 +00:00
|
|
|
// assuming only widgets with same parent can be selected
|
|
|
|
|
const parentId = widgets[selectedWidgets[0]].parentId;
|
|
|
|
|
if (parentId) {
|
2023-10-19 20:27:40 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes =
|
|
|
|
|
yield select(getLayoutSystemType);
|
|
|
|
|
if (layoutSystemType === LayoutSystemTypes.AUTO) {
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getCanvasWidth);
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
for (const widgetId of selectedWidgets) {
|
|
|
|
|
finalData = yield call(
|
|
|
|
|
updateFlexLayersOnDelete,
|
|
|
|
|
finalWidgets,
|
|
|
|
|
widgetId,
|
|
|
|
|
parentId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
metaProps,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} else if (layoutSystemType === LayoutSystemTypes.ANVIL) {
|
|
|
|
|
for (const widgetId of selectedWidgets) {
|
|
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
|
|
|
|
finalWidgets,
|
|
|
|
|
parentId,
|
|
|
|
|
widgetId,
|
|
|
|
|
);
|
|
|
|
|
}
|
2023-03-04 07:25:54 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
//Main canvas's minheight keeps varying, hence retrieving updated value
|
|
|
|
|
// let mainCanvasMinHeight;
|
|
|
|
|
// if (parentId === MAIN_CONTAINER_WIDGET_ID) {
|
|
|
|
|
// const mainCanvasProps: MainCanvasReduxState = yield select(
|
|
|
|
|
// getMainCanvasProps,
|
|
|
|
|
// );
|
|
|
|
|
// mainCanvasMinHeight = mainCanvasProps?.height;
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// if (parentId && widgetsAfterUpdatingFlexLayers[parentId]) {
|
|
|
|
|
// widgetsAfterUpdatingFlexLayers[
|
|
|
|
|
// parentId
|
|
|
|
|
// ].bottomRow = resizePublishedMainCanvasToLowestWidget(
|
|
|
|
|
// widgetsAfterUpdatingFlexLayers,
|
|
|
|
|
// parentId,
|
|
|
|
|
// finalWidgets[parentId].bottomRow,
|
|
|
|
|
// mainCanvasMinHeight,
|
|
|
|
|
// );
|
|
|
|
|
// }
|
2021-09-21 07:55:56 +00:00
|
|
|
|
2023-10-19 20:27:40 +00:00
|
|
|
yield put(updateAndSaveLayout(finalData));
|
2022-11-23 09:48:23 +00:00
|
|
|
yield put(generateAutoHeightLayoutTreeAction(true, true));
|
|
|
|
|
|
2023-01-28 02:17:06 +00:00
|
|
|
yield put(selectWidgetInitAction(SelectionRequestType.Empty));
|
2021-09-21 07:55:56 +00:00
|
|
|
const bulkDeleteKey = selectedWidgets.join(",");
|
|
|
|
|
if (!disallowUndo) {
|
|
|
|
|
// close property pane after delete
|
|
|
|
|
yield put(closePropertyPane());
|
|
|
|
|
yield put(closeTableFilterPane());
|
|
|
|
|
showUndoRedoToast(`${selectedWidgets.length}`, true, false, true);
|
|
|
|
|
if (bulkDeleteKey) {
|
2022-01-28 11:10:05 +00:00
|
|
|
flattenedWidgets.map((widget: any) => {
|
2021-09-21 07:55:56 +00:00
|
|
|
AppsmithConsole.info({
|
|
|
|
|
logType: LOG_TYPE.ENTITY_DELETED,
|
|
|
|
|
text: "Widget was deleted",
|
|
|
|
|
source: {
|
|
|
|
|
name: widget.widgetName,
|
|
|
|
|
type: ENTITY_TYPE.WIDGET,
|
|
|
|
|
id: widget.widgetId,
|
|
|
|
|
},
|
|
|
|
|
analytics: {
|
|
|
|
|
widgetType: widget.type,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.WIDGET_OPERATION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
action: WidgetReduxActionTypes.WIDGET_DELETE,
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* postDelete(
|
|
|
|
|
widgetId: string,
|
|
|
|
|
widgetName: string,
|
|
|
|
|
otherWidgetsToDelete: (WidgetProps & {
|
|
|
|
|
children?: string[] | undefined;
|
|
|
|
|
})[],
|
|
|
|
|
) {
|
|
|
|
|
showUndoRedoToast(widgetName, false, false, true);
|
|
|
|
|
|
|
|
|
|
if (widgetId) {
|
|
|
|
|
otherWidgetsToDelete.map((widget) => {
|
|
|
|
|
AppsmithConsole.info({
|
|
|
|
|
logType: LOG_TYPE.ENTITY_DELETED,
|
|
|
|
|
text: "Widget was deleted",
|
|
|
|
|
source: {
|
|
|
|
|
name: widget.widgetName,
|
|
|
|
|
type: ENTITY_TYPE.WIDGET,
|
|
|
|
|
id: widget.widgetId,
|
|
|
|
|
},
|
|
|
|
|
analytics: {
|
|
|
|
|
widgetType: widget.type,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function* widgetDeletionSagas() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeEvery(WidgetReduxActionTypes.WIDGET_DELETE, deleteSagaInit),
|
|
|
|
|
takeEvery(WidgetReduxActionTypes.WIDGET_SINGLE_DELETE, deleteSaga),
|
|
|
|
|
takeEvery(
|
|
|
|
|
WidgetReduxActionTypes.WIDGET_BULK_DELETE,
|
|
|
|
|
deleteAllSelectedWidgetsSaga,
|
|
|
|
|
),
|
|
|
|
|
takeEvery(ReduxActionTypes.WIDGET_DELETE_TAB_CHILD, deleteTabChildSaga),
|
|
|
|
|
]);
|
|
|
|
|
}
|