fix: Anvil editor zone stretch fix in mobile mode (#30592)

> Pull Request Template
>
> Use this template to quickly create a well written pull request.
Delete all quotes before creating the pull request.
>
## Description
In this PR, we are making sure zones don't stretch to fill sections in
low resolution screens exclusively on the Appsmith Anvil Editor.

#### PR fixes following issue(s)
Fixes # (issue number)
> if no issue exists, please create an issue and ask the maintainers
about this first
>
>
#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
> Please delete options that are not relevant.
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- Chore (housekeeping or task changes that don't impact user perception)
- This change requires a documentation update
>
>
>
## Testing
>
#### How Has This Been Tested?
> Please describe the tests that you ran to verify your changes. Also
list any relevant details for your test configuration.
> Delete anything that is not relevant
- [ ] Manual
- [ ] JUnit
- [ ] Jest
- [ ] Cypress
>
>
#### 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
- [ ] 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
- [ ] 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:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#areas-of-interest-)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

- **New Features**
- Enhanced the canvas interaction experience in the Anvil layout system
for better usability.
- **Bug Fixes**
- Fixed an issue with incorrect `minWidth` settings for widgets,
improving responsiveness and layout accuracy on mobile devices.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Ashok Kumar M 2024-01-29 19:23:15 +05:30 committed by GitHub
parent 7da11d9eca
commit dcabb56503
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 22 deletions

View File

@ -1,14 +1,18 @@
import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC"; import type { BaseWidgetProps } from "widgets/BaseWidgetHOC/withBaseWidgetHOC";
import { AnvilCanvas } from "./AnvilCanvas"; import { AnvilCanvas } from "./AnvilCanvas";
import React from "react"; import React from "react";
import { useCanvasActivationStates } from "../canvasArenas/hooks/mainCanvas/useCanvasActivationStates";
import { useCanvasActivation } from "../canvasArenas/hooks/mainCanvas/useCanvasActivation"; import { useCanvasActivation } from "../canvasArenas/hooks/mainCanvas/useCanvasActivation";
import { useSelectWidgetListener } from "../common/hooks/useSelectWidgetListener"; import { useSelectWidgetListener } from "../common/hooks/useSelectWidgetListener";
export const AnvilMainCanvas = (props: BaseWidgetProps) => { /**
const anvilCanvasActivationStates = useCanvasActivationStates(); * Anvil Main Canvas is just a wrapper around AnvilCanvas.
useCanvasActivation(anvilCanvasActivationStates); * Why do we need this?
* Because we need to use useCanvasActivation hook which is only needed to be used once and it is also exclusive to edit mode.
* checkout useCanvasActivation for more details.
*/
export const AnvilMainCanvas = (props: BaseWidgetProps) => {
useCanvasActivation();
useSelectWidgetListener(); useSelectWidgetListener();
return <AnvilCanvas {...props} />; return <AnvilCanvas {...props} />;
}; };

View File

@ -7,7 +7,7 @@ import { getAnvilLayoutDOMId } from "layoutSystems/common/utils/LayoutElementPos
import { debounce, uniq } from "lodash"; import { debounce, uniq } from "lodash";
import { useEffect, useRef } from "react"; import { useEffect, useRef } from "react";
import { useWidgetDragResize } from "utils/hooks/dragResizeHooks"; import { useWidgetDragResize } from "utils/hooks/dragResizeHooks";
import type { AnvilCanvasActivationStates } from "./useCanvasActivationStates"; import { useCanvasActivationStates } from "./useCanvasActivationStates";
import { canActivateCanvasForDraggedWidget } from "../utils"; import { canActivateCanvasForDraggedWidget } from "../utils";
import { LayoutComponentTypes } from "layoutSystems/anvil/utils/anvilTypes"; import { LayoutComponentTypes } from "layoutSystems/anvil/utils/anvilTypes";
@ -39,7 +39,12 @@ const checkIfMousePositionIsInsideBlock = (
const MAIN_CANVAS_BUFFER = 20; const MAIN_CANVAS_BUFFER = 20;
const SECTION_BUFFER = 20; const SECTION_BUFFER = 20;
export const useCanvasActivation = ({ /**
* This hook handles the activation and deactivation of the canvas(Drop targets) while dragging.
*/
export const useCanvasActivation = () => {
const {
activateOverlayWidgetDrop, activateOverlayWidgetDrop,
dragDetails, dragDetails,
draggedWidgetTypes, draggedWidgetTypes,
@ -48,7 +53,7 @@ export const useCanvasActivation = ({
layoutElementPositions, layoutElementPositions,
mainCanvasLayoutId, mainCanvasLayoutId,
selectedWidgets, selectedWidgets,
}: AnvilCanvasActivationStates) => { } = useCanvasActivationStates();
// Getting the main canvas DOM node // Getting the main canvas DOM node
const mainContainerDOMNode = document.getElementById(CANVAS_ART_BOARD); const mainContainerDOMNode = document.getElementById(CANVAS_ART_BOARD);

View File

@ -7,12 +7,12 @@ export const anvilConfig: AnvilConfig = {
isLargeWidget: true, isLargeWidget: true,
widgetSize: (props: WidgetProps, isPreviewMode: boolean): SizeConfig => { widgetSize: (props: WidgetProps, isPreviewMode: boolean): SizeConfig => {
return { return {
minWidth: { minWidth:
base: "100%",
[`${MOBILE_BREAKPOINT}px`]:
props?.renderMode === RenderModes.CANVAS && !isPreviewMode props?.renderMode === RenderModes.CANVAS && !isPreviewMode
? "unset" ? {}
: "min-content", : {
base: "100%",
[`${MOBILE_BREAKPOINT}px`]: "min-content",
}, },
}; };
}, },