Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Anvil only: Automatically delete redundant zones #34879

Merged
merged 6 commits into from
Jul 16, 2024

Conversation

znamenskii-ilia
Copy link
Contributor

@znamenskii-ilia znamenskii-ilia commented Jul 11, 2024

Description

Delete redundant zones when drag last widget out or remove it.

https://www.notion.so/appsmith/Removing-redundant-zones-8a2cf907c97246adb618664940e298b0

Fixes #34854

Screen.Recording.2024-07-12.at.13.32.02.mov
Screen.Recording.2024-07-12.at.13.28.31.mov

Automation

/ok-to-test tags="@tag.Anvil"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/9953698717
Commit: d2a5392
Cypress dashboard.
Tags: @tag.Anvil
Spec:


Tue, 16 Jul 2024 09:12:41 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Improved widget management by adding new functions to handle deletion of redundant zones and manage widget children.
  • Bug Fixes

    • Enhanced widget dragging and deletion logic to ensure redundant zones are properly handled.
  • Tests

    • Added tests for new utility functions to validate their behavior in different scenarios.

@znamenskii-ilia znamenskii-ilia added skip-changelog Adding this label to a PR prevents it from being listed in the changelog ok-to-test Required label for CI labels Jul 11, 2024
Copy link
Contributor

coderabbitai bot commented Jul 11, 2024

Walkthrough

The changes introduce new functions and tests related to widget handling in the Appsmith platform. These modifications aim to enhance the deletion logic by removing redundant zones when widgets are moved or deleted. Key updates include adding new utility functions to check widget properties and integrating these functions into existing sagas and utilities.

Changes

File Path Change Summary
.../anvil/integrations/sagas/anvilDraggingSagas/index.ts Added DraggedWidget type, functions handleDeleteRedundantZones, widgetChildren, and updated moveWidgetsSaga to manage redundant zones.
...utils/layouts/update/zoneUtils.test.ts Introduced tests for isZoneWidget and isRedundantZoneWidget functions.
.../utils/layouts/update/zoneUtils.ts Added isZoneWidget and isRedundantZoneWidget functions to check conditions related to zone widgets.
.../utils/layouts/widgetUtils.test.ts Introduced tests for isEmptyWidget, widgetChildren, and hasWidgetJsPropertiesEnabled functions.
.../utils/layouts/widgetUtils.ts Added functions isEmptyWidget, hasWidgetJsPropertiesEnabled, and widgetChildren for enhanced widget property checks.
.../sagas/WidgetDeletionSagas.ts Added imports and function handleDeleteRedundantZones to manage redundant zone deletion during widget deletion processes. Updated deleteSaga logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Saga
    participant Utils
    participant Store

    User->>Saga: Move widget
    Saga->>Utils: Call handleDeleteRedundantZones
    Utils->>Store: Check widget properties and determine redundant zones
    Store-->>Utils: Return redundant zone information
    Utils-->>Saga: Delete redundant zones
    Saga-->>User: Update UI to reflect changes
Loading

Assessment against linked issues

Objective (Issue #) Addressed Explanation
Remove zone when it got empty (#34854)
Handle dragging widget out or cutting it (Scenario 1)
Maintain zone if parent section has other zones (Scenario 2)
Maintain zone if JS is enabled (Scenario 3)

Possibly related issues

Poem

In the realm where widgets play,
Zones will vanish, clear the way.
Drag and drop, with logic keen,
Redundant spaces now unseen.
Enhanced by tests, the saga flows,
In Appsmith's world, efficiency grows.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added Anvil Pod Issue related to Anvil project Anvil team issues related to the new layout system anvil Task A simple Todo and removed skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Jul 11, 2024
@znamenskii-ilia
Copy link
Contributor Author

/build-deploy-preview skip-tests=true

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9891175547.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34879.
recreate: .

@znamenskii-ilia znamenskii-ilia added the skip-changelog Adding this label to a PR prevents it from being listed in the changelog label Jul 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6f856b5 and 2262349.

Files selected for processing (5)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts (5 hunks)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.test.ts (1 hunks)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts (2 hunks)
  • app/client/src/layoutSystems/anvil/utils/layouts/widgetUtils.test.ts (1 hunks)
  • app/client/src/layoutSystems/anvil/utils/layouts/widgetUtils.ts (2 hunks)
Files skipped from review due to trivial changes (1)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.test.ts
Additional comments not posted (11)
app/client/src/layoutSystems/anvil/utils/layouts/widgetUtils.ts (3)

32-33: LGTM!

The isEmptyWidget function correctly checks if a widget has no children.


35-37: LGTM!

The hasWidgetJsPropertiesEnabled function correctly checks for dynamic properties.


39-40: LGTM!

The widgetChildren function correctly returns the children of a widget.

app/client/src/layoutSystems/anvil/utils/layouts/widgetUtils.test.ts (3)

8-34: LGTM!

The test cases for isEmptyWidget are thorough and correctly implemented.


37-54: LGTM!

The test cases for widgetChildren are thorough and correctly implemented.


57-81: LGTM!

The test cases for hasWidgetJsPropertiesEnabled are thorough and correctly implemented.

app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts (2)

251-252: LGTM!

The isZoneWidget function correctly checks if a widget is a zone widget.


254-261: LGTM!

The isRedundantZoneWidget function correctly checks if a zone widget is redundant based on the specified conditions.

app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts (3)

396-424: LGTM!

The handleDeleteRedundantZones function correctly handles the deletion of redundant zones based on the specified conditions.


50-50: LGTM!

The widgetChildren function correctly returns the children of a widget.


337-341: LGTM!

The updates to moveWidgetsSaga correctly incorporate the handleDeleteRedundantZones function.

Copy link

Deploy-Preview-URL: https://ce-34879.dp.appsmith.com

@KelvinOm KelvinOm changed the title Feat: Delete redundant zones feat: delete redundant zones Jul 11, 2024
@github-actions github-actions bot added Enhancement New feature or request and removed skip-changelog Adding this label to a PR prevents it from being listed in the changelog labels Jul 11, 2024
@KelvinOm KelvinOm added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 11, 2024
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 2262349 and a6d2c7c.

Files selected for processing (1)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts

@KelvinOm KelvinOm requested a review from ramsaptami July 11, 2024 14:11
): boolean =>
isZoneWidget(widget) &&
isEmptyWidget(widget) &&
widgetChildren(parentSection).length === 1 &&
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we checking by this line?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That the zone is the only child in the parent. I will add a comment

widget: FlattenedWidgetProps,
): boolean => (widget.dynamicPropertyPathList || []).length > 0;

export const widgetChildren = (widget: FlattenedWidgetProps): string[] =>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't really understand the meaning of this method. It seems easier and clearer to just get children through a dot(widget.children). When using the method, it is not obvious what is happening inside, whether we somehow modify the children or maybe filter them, etc. what operations are performed in this function.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, it is easier to use widget.children directly. However, right now children is optional field and we always have to check it is array or not.

Here is one example found in code:

return (a.children || []).length - (b.children || []).length;

widgetChildren increases readability a bit imo

return widgetChildren(a).length - widgetChildren(b).length;

Once we define clear entities and split widgets by types we will not need to have children optional and we will remove this utility.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still write something more specific for section, something like sectionHasOnlyOneZone. In this method you can incapsulate all necessary child checks, etc., Also you won't need to add the comment, and the code will be more readable.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between a6d2c7c and a9f47e9.

Files selected for processing (1)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts (2 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.ts

Copy link

Deploying Your Preview: https://github.com/appsmithorg/appsmith/actions/runs/9906867344.
Workflow: On demand build Docker image and deploy preview.
skip-tests: true.
env: ``.
PR: 34879.
recreate: .

Copy link

Deploy-Preview-URL: https://ce-34879.dp.appsmith.com

@@ -440,6 +452,37 @@ function* deleteAllSelectedWidgetsSaga(
}
}

// TODO: Find a way to reuse identical code from anvilDraggingSagas/index.ts
export function handleDeleteRedundantZones(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. This can be a utility function that only applies to Anvil. We'll refactor widget delete to be Anvil specific.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@znamenskii-ilia Would you mind creating an issue on Github for this? You could assign it to both of us, and the Anvil team, so that it shows up on our Zenhub board.

Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c250347 and 6eb7fa1.

Files selected for processing (1)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts (5 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/layoutSystems/anvil/integrations/sagas/anvilDraggingSagas/index.ts

coderabbitai[bot]
coderabbitai bot previously approved these changes Jul 12, 2024
riodeuno
riodeuno previously approved these changes Jul 15, 2024
@riodeuno riodeuno added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 15, 2024
@riodeuno riodeuno changed the title feat: delete redundant zones chore: Anvil only: Automatically delete redundant zones Jul 15, 2024
@github-actions github-actions bot added skip-changelog Adding this label to a PR prevents it from being listed in the changelog and removed Enhancement New feature or request labels Jul 15, 2024
@riodeuno riodeuno added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 15, 2024
@znamenskii-ilia znamenskii-ilia added the ok-to-test Required label for CI label Jul 16, 2024
Copy link

⚠️ Cyclic Dependency Check:

This PR has increased the number of cyclic dependencies by 1, when compared with the release branch.

Refer this document to identify the cyclic dependencies introduced by this PR.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 6eb7fa1 and d2a5392.

Files selected for processing (1)
  • app/client/src/sagas/WidgetDeletionSagas.ts (3 hunks)
Files skipped from review as they are similar to previous changes (1)
  • app/client/src/sagas/WidgetDeletionSagas.ts

@znamenskii-ilia znamenskii-ilia added ok-to-test Required label for CI and removed ok-to-test Required label for CI labels Jul 16, 2024
@znamenskii-ilia znamenskii-ilia merged commit 48c782a into release Jul 16, 2024
72 checks passed
@znamenskii-ilia znamenskii-ilia deleted the feat/34854-remove-redundant-zones branch July 16, 2024 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Anvil Pod Issue related to Anvil project Anvil team issues related to the new layout system anvil ok-to-test Required label for CI skip-changelog Adding this label to a PR prevents it from being listed in the changelog Task A simple Todo
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove a zone when it got empty
3 participants