-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Anvil only: Automatically delete redundant zones (#34879)
## Description Delete redundant zones when drag last widget out or remove it. https://www.notion.so/appsmith/Removing-redundant-zones-8a2cf907c97246adb618664940e298b0 Fixes #34854 https://github.com/user-attachments/assets/686dbee3-d16c-4ea1-bbd1-b9e48c73ea8f https://github.com/user-attachments/assets/c2fe52b8-6a3e-4dcb-993a-03cb65e9672c ## Automation /ok-to-test tags="@tag.Anvil" ### 🔍 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/9953698717> > Commit: d2a5392 > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=9953698717&attempt=1" target="_blank">Cypress dashboard</a>. > Tags: `@tag.Anvil` > Spec: > <hr>Tue, 16 Jul 2024 09:12:41 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <!-- end of auto-generated comment: release notes by coderabbit.ai --> --------- Co-authored-by: Ilia Znamenskii <ilia@appsmith.com>
- Loading branch information
1 parent
3ba2f25
commit 48c782a
Showing
6 changed files
with
411 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
216 changes: 216 additions & 0 deletions
216
app/client/src/layoutSystems/anvil/utils/layouts/update/zoneUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,216 @@ | ||
import { RenderModes } from "../../../../../constants/WidgetConstants"; | ||
import { mockButtonProps } from "../../../../../mocks/widgetProps/button"; | ||
import { isRedundantZoneWidget, isZoneWidget } from "./zoneUtils"; | ||
|
||
describe("isZoneWidget", () => { | ||
it("should return true if the widget is a zone widget", () => { | ||
// TODO: Use factory to generate widget | ||
const widget = { | ||
type: "ZONE_WIDGET", | ||
widgetId: "123", | ||
widgetName: "Button1", | ||
renderMode: RenderModes.CANVAS, | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isZoneWidget(widget)).toBe(true); | ||
}); | ||
|
||
it("should return false if the widget is not a zone widget", () => { | ||
const widget = mockButtonProps(); | ||
|
||
expect(isZoneWidget(widget)).toBe(false); | ||
}); | ||
}); | ||
|
||
describe("isRedundantZoneWidget", () => { | ||
it("should return true if the widget is a redundant zone widget", () => { | ||
const widget = { | ||
type: "ZONE_WIDGET", | ||
widgetId: "123", | ||
widgetName: "Zone1", | ||
renderMode: RenderModes.CANVAS, | ||
children: [], | ||
dynamicPropertyPathList: [], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
const parentWidget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isRedundantZoneWidget(widget, parentWidget)).toBe(true); | ||
}); | ||
|
||
it("should return false if the widget is not empty", () => { | ||
const widget = { | ||
type: "ZONE_WIDGET", | ||
widgetId: "123", | ||
widgetName: "Zone1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["000"], | ||
dynamicPropertyPathList: [], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
const parentWidget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isRedundantZoneWidget(widget, parentWidget)).toBe(false); | ||
}); | ||
|
||
it("should return false if the widget is not zone", () => { | ||
const widget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
const parentWidget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isRedundantZoneWidget(widget, parentWidget)).toBe(false); | ||
}); | ||
|
||
it("should return false if the widget is not the only child", () => { | ||
const widget = { | ||
type: "ZONE_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
const parentWidget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123", "877"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isRedundantZoneWidget(widget, parentWidget)).toBe(false); | ||
}); | ||
|
||
it("should return false if the widget has JS props enabled", () => { | ||
const widget = { | ||
type: "ZONE_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
dynamicPropertyPathList: [{ key: "isVisible" }], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
const parentWidget = { | ||
type: "SECTION_WIDGET", | ||
widgetId: "567", | ||
widgetName: "Section1", | ||
renderMode: RenderModes.CANVAS, | ||
children: ["123"], | ||
version: 1, | ||
isLoading: false, | ||
parentColumnSpace: 10, | ||
parentRowSpace: 10, | ||
leftColumn: 0, | ||
rightColumn: 10, | ||
topRow: 0, | ||
bottomRow: 4, | ||
}; | ||
|
||
expect(isRedundantZoneWidget(widget, parentWidget)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.