fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { generateAutoHeightLayoutTreeAction } from "actions/autoHeightActions";
|
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";
|
|
|
|
|
import { closePropertyPane, closeTableFilterPane } from "actions/widgetActions";
|
|
|
|
|
import { selectWidgetInitAction } from "actions/widgetSelectionActions";
|
2024-08-22 04:19:30 +00:00
|
|
|
import type { ReduxAction } from "ee/constants/ReduxActionConstants";
|
2021-09-21 07:55:56 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
|
|
|
|
WidgetReduxActionTypes,
|
2024-08-06 14:52:22 +00:00
|
|
|
} from "ee/constants/ReduxActionConstants";
|
|
|
|
|
import { ENTITY_TYPE } from "ee/entities/AppsmithConsole/utils";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { widgetURL } from "ee/RouteBuilder";
|
|
|
|
|
import { getCurrentApplication } from "ee/selectors/applicationSelectors";
|
|
|
|
|
import AnalyticsUtil from "ee/utils/AnalyticsUtil";
|
|
|
|
|
import type { ApplicationPayload } from "entities/Application";
|
2021-09-21 07:55:56 +00:00
|
|
|
import LOG_TYPE from "entities/AppsmithConsole/logtype";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { getIsAnvilLayout } from "layoutSystems/anvil/integrations/selectors";
|
|
|
|
|
import { updateAndSaveAnvilLayout } from "layoutSystems/anvil/utils/anvilChecksUtils";
|
|
|
|
|
import { updateAnvilParentPostWidgetDeletion } from "layoutSystems/anvil/utils/layouts/update/deletionUtils";
|
|
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
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";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { SelectionRequestType } from "sagas/WidgetSelectUtils";
|
2023-04-07 13:51:35 +00:00
|
|
|
import {
|
|
|
|
|
getCanvasWidth,
|
|
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
|
|
|
|
} from "selectors/editorSelectors";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2021-09-21 07:55:56 +00:00
|
|
|
import { getSelectedWidgets } from "selectors/ui";
|
|
|
|
|
import AppsmithConsole from "utils/AppsmithConsole";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import { showUndoRedoToast } from "utils/replayHelpers";
|
|
|
|
|
import WidgetFactory from "WidgetProvider/factory";
|
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";
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
import type { DraggedWidget } from "../layoutSystems/anvil/utils/anvilTypes";
|
|
|
|
|
import { severTiesFromParents } from "../layoutSystems/anvil/utils/layouts/update/moveUtils";
|
|
|
|
|
import {
|
|
|
|
|
isRedundantZoneWidget,
|
|
|
|
|
isZoneWidget,
|
|
|
|
|
} from "../layoutSystems/anvil/utils/layouts/update/zoneUtils";
|
|
|
|
|
import { widgetChildren } from "../layoutSystems/anvil/utils/layouts/widgetUtils";
|
|
|
|
|
import { updateFlexLayersOnDelete } from "../layoutSystems/autolayout/utils/AutoLayoutUtils";
|
|
|
|
|
import FocusRetention from "./FocusRetentionSaga";
|
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";
|
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];
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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;
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-09-21 07:55:56 +00:00
|
|
|
const updatedArray = tabsArray.filter((eachItem: any, i: number) => {
|
|
|
|
|
return i !== index;
|
|
|
|
|
});
|
|
|
|
|
const updatedObj = updatedArray.reduce(
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2021-09-21 07:55:56 +00:00
|
|
|
(obj: any, each: any, index: number) => {
|
|
|
|
|
obj[each.id] = {
|
|
|
|
|
...each,
|
|
|
|
|
index,
|
|
|
|
|
};
|
|
|
|
|
return obj;
|
|
|
|
|
},
|
|
|
|
|
{},
|
|
|
|
|
);
|
2023-12-26 14:16:58 +00:00
|
|
|
const widgetType: string = allWidgets[widgetId].type;
|
2021-09-21 07:55:56 +00:00
|
|
|
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);
|
2024-04-12 17:24:04 +00:00
|
|
|
const isAnvilLayout: boolean = yield select(getIsAnvilLayout);
|
2023-10-19 20:27:40 +00:00
|
|
|
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);
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-10-19 20:27:40 +00:00
|
|
|
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
|
|
|
);
|
2024-04-12 17:24:04 +00:00
|
|
|
} else if (isAnvilLayout) {
|
2023-10-19 20:27:40 +00:00
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
2023-10-25 05:46:32 +00:00
|
|
|
finalData,
|
2023-10-19 20:27:40 +00:00
|
|
|
tabWidget.parentId,
|
|
|
|
|
widgetId,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgetType,
|
2023-10-19 20:27:40 +00:00
|
|
|
);
|
|
|
|
|
}
|
2023-12-29 02:41:49 +00:00
|
|
|
yield call(updateAndSaveAnvilLayout, 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-01-25 13:56:52 +00:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
export function* deleteSaga(deleteAction: ReduxAction<WidgetDelete>) {
|
2021-09-21 07:55:56 +00:00
|
|
|
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
|
|
|
|
fix: Prevent Errors in Debugger When Deleting List Widget (#35820)
## Description
**Problem**
When deleting a List widget in the EE environment, the widget is
successfully removed, but errors are displayed in the in-app debugger.
These errors disappear upon refreshing the page, leaving users confused
as to why the errors appeared in the first place, despite the widget
being deleted correctly.
**Root Cause**
- The issue arises from the sequence in which widgets and their
associated meta widgets are deleted.
- When deleting a widget with meta widgets (e.g., a List widget):
- The main widget is removed first via the deleteWidget saga.
- Meta widgets are then deleted later during the componentWillUnmount
lifecycle method.
- The lint evaluation runs between these two processes, detecting meta
widgets still present in the state without a parent widget.
- This mismatch triggers errors in the in-app debugger, which disappear
once the page is refreshed, as the meta widgets have already been
deleted by then.
**Solution**
- We have modified the deletion process to ensure that both the main
widget and its associated meta widgets are removed within the same
action.
- Instead of handling meta widget deletion in the general deleteSaga:
- We now check for widgets with the hasMetaWidgets flag within the
deleteWidget saga.
- If such widgets are found, their meta widgets are deleted before the
main widget is removed from the layout.
- This adjustment ensures that the lint evaluation occurs after both the
main widget and its meta widgets have been removed, preventing errors in
the debugger.
Fixes #35628
## Automation
/ok-to-test tags="@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity"
### :mag: Cypress test results
<!-- This is an auto-generated comment: Cypress test results -->
> [!TIP]
> 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
> Workflow run:
<https://github.com/appsmithorg/appsmith/actions/runs/10629216245>
> Commit: 56a4c85076d574cc2ebfef12d3b9f998ee1a4ece
> <a
href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10629216245&attempt=1"
target="_blank">Cypress dashboard</a>.
> Tags: `@tag.Widget, @tag.List, @tag.IDE, @tag.Sanity`
> Spec:
> <hr>Fri, 30 Aug 2024 09:25:02 UTC
<!-- end of auto-generated comment: Cypress test results -->
## Communication
Should the DevRel and Marketing teams inform users about this change?
- [ ] Yes
- [ ] No
<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit
## Summary by CodeRabbit
- **New Features**
- Enhanced testing for the list widget to include verification of the
drag, drop, and delete functionalities.
- Improved widget deletion process by ensuring related meta widgets are
also addressed during deletion.
- Updated test descriptions for better clarity and scope, specifically
focusing on deletion functionality.
- Introduced a factory for creating instances of version 2 list widgets,
streamlining widget generation.
- **Bug Fixes**
- Expanded test coverage for potential issues in widget behavior,
particularly concerning deletion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2024-08-30 09:38:19 +00:00
|
|
|
/**
|
|
|
|
|
* This change ensures that meta widgets are deleted before the main widget.
|
|
|
|
|
* By handling meta widget deletion within the deleteWidget saga, we prevent
|
|
|
|
|
* lint evaluation from detecting orphaned meta widgets, which previously
|
|
|
|
|
* caused errors in the in-app debugger. This resolves the issue of transient
|
|
|
|
|
* errors appearing after widget deletion.
|
|
|
|
|
*
|
|
|
|
|
* For more details, refer to the PR: https://github.com/appsmithorg/appsmith/pull/35820
|
|
|
|
|
*/
|
|
|
|
|
if (widget.hasMetaWidgets) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.DELETE_META_WIDGETS,
|
|
|
|
|
payload: {
|
|
|
|
|
creatorIds: [widgetId],
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
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);
|
2024-04-12 17:24:04 +00:00
|
|
|
const isAnvilLayout: boolean = yield select(getIsAnvilLayout);
|
2023-10-19 20:27:40 +00:00
|
|
|
let finalData: CanvasWidgetsReduxState = finalWidgets;
|
|
|
|
|
if (layoutSystemType === LayoutSystemTypes.AUTO) {
|
|
|
|
|
const isMobile: boolean = yield select(
|
|
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
|
|
|
|
);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getCanvasWidth);
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-10-19 20:27:40 +00:00
|
|
|
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
|
|
|
);
|
2024-04-12 17:24:04 +00:00
|
|
|
} else if (isAnvilLayout) {
|
2023-10-19 20:27:40 +00:00
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
2023-10-25 05:46:32 +00:00
|
|
|
finalData,
|
2023-10-19 20:27:40 +00:00
|
|
|
parentId,
|
|
|
|
|
widgetId,
|
2023-12-26 14:16:58 +00:00
|
|
|
widget.type,
|
2023-10-19 20:27:40 +00:00
|
|
|
);
|
2024-07-16 09:16:50 +00:00
|
|
|
|
|
|
|
|
finalData = handleDeleteRedundantZones(
|
|
|
|
|
finalData,
|
|
|
|
|
otherWidgetsToDelete,
|
|
|
|
|
);
|
2023-10-19 20:27:40 +00:00
|
|
|
}
|
2023-12-29 02:41:49 +00:00
|
|
|
yield call(updateAndSaveAnvilLayout, finalData);
|
2022-11-23 09:48:23 +00:00
|
|
|
yield put(generateAutoHeightLayoutTreeAction(true, true));
|
2023-11-09 04:19:02 +00:00
|
|
|
|
|
|
|
|
const currentApplication: ApplicationPayload = yield select(
|
|
|
|
|
getCurrentApplication,
|
|
|
|
|
);
|
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,
|
2023-11-09 04:19:02 +00:00
|
|
|
templateTitle: currentApplication?.forkedFromTemplateTitle,
|
2021-09-21 07:55:56 +00:00
|
|
|
});
|
2023-12-27 08:47:35 +00:00
|
|
|
const currentUrl = window.location.pathname;
|
2024-04-05 12:26:17 +00:00
|
|
|
yield call(FocusRetention.handleRemoveFocusHistory, currentUrl);
|
2021-09-21 07:55:56 +00:00
|
|
|
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(
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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,
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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);
|
2024-04-12 17:24:04 +00:00
|
|
|
const isAnvilLayout: boolean = yield select(getIsAnvilLayout);
|
2023-10-19 20:27:40 +00:00
|
|
|
if (layoutSystemType === LayoutSystemTypes.AUTO) {
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getCanvasWidth);
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
2023-10-19 20:27:40 +00:00
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
for (const widgetId of selectedWidgets) {
|
|
|
|
|
finalData = yield call(
|
|
|
|
|
updateFlexLayersOnDelete,
|
|
|
|
|
finalWidgets,
|
|
|
|
|
widgetId,
|
|
|
|
|
parentId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
metaProps,
|
|
|
|
|
);
|
|
|
|
|
}
|
2024-04-12 17:24:04 +00:00
|
|
|
} else if (isAnvilLayout) {
|
2023-10-19 20:27:40 +00:00
|
|
|
for (const widgetId of selectedWidgets) {
|
|
|
|
|
finalData = updateAnvilParentPostWidgetDeletion(
|
2023-10-25 05:46:32 +00:00
|
|
|
finalData,
|
2023-10-19 20:27:40 +00:00
|
|
|
parentId,
|
|
|
|
|
widgetId,
|
2023-12-26 14:16:58 +00:00
|
|
|
widgets[widgetId].type,
|
2023-10-19 20:27:40 +00:00
|
|
|
);
|
|
|
|
|
}
|
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-12-29 02:41:49 +00:00
|
|
|
yield call(updateAndSaveAnvilLayout, 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(",");
|
2024-04-05 12:26:17 +00:00
|
|
|
for (const widget of selectedWidgets) {
|
|
|
|
|
yield call(
|
|
|
|
|
FocusRetention.handleRemoveFocusHistory,
|
|
|
|
|
widgetURL({ selectedWidgets: [widget] }),
|
|
|
|
|
);
|
|
|
|
|
}
|
2021-09-21 07:55:56 +00:00
|
|
|
if (!disallowUndo) {
|
|
|
|
|
// close property pane after delete
|
|
|
|
|
yield put(closePropertyPane());
|
|
|
|
|
yield put(closeTableFilterPane());
|
|
|
|
|
showUndoRedoToast(`${selectedWidgets.length}`, true, false, true);
|
|
|
|
|
if (bulkDeleteKey) {
|
2024-07-31 15:41:28 +00:00
|
|
|
// TODO: Fix this the next time the file is edited
|
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
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,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-16 09:16:50 +00:00
|
|
|
// TODO: Find a way to reuse identical code from anvilDraggingSagas/index.ts
|
|
|
|
|
export function handleDeleteRedundantZones(
|
|
|
|
|
allWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
movedWidgets: DraggedWidget[],
|
|
|
|
|
) {
|
|
|
|
|
let updatedWidgets: CanvasWidgetsReduxState = { ...allWidgets };
|
|
|
|
|
const parentIds = movedWidgets
|
|
|
|
|
.map((widget) => widget.parentId)
|
|
|
|
|
.filter(Boolean) as string[];
|
|
|
|
|
|
|
|
|
|
for (const parentId of parentIds) {
|
|
|
|
|
const zone = updatedWidgets[parentId];
|
|
|
|
|
|
|
|
|
|
if (!zone || !isZoneWidget(zone) || !zone.parentId) continue;
|
|
|
|
|
|
|
|
|
|
const parentSection = updatedWidgets[zone.parentId];
|
|
|
|
|
|
|
|
|
|
if (!parentSection || !isRedundantZoneWidget(zone, parentSection)) continue;
|
|
|
|
|
|
|
|
|
|
updatedWidgets = severTiesFromParents(updatedWidgets, [zone.widgetId]);
|
|
|
|
|
delete updatedWidgets[zone.widgetId];
|
|
|
|
|
|
|
|
|
|
if (widgetChildren(parentSection).length === 1) {
|
|
|
|
|
updatedWidgets = severTiesFromParents(updatedWidgets, [zone.parentId]);
|
|
|
|
|
delete updatedWidgets[zone.parentId];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return updatedWidgets;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-21 07:55:56 +00:00
|
|
|
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),
|
|
|
|
|
]);
|
|
|
|
|
}
|