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

Fix unintentional page rows being created #3221

Merged
merged 8 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,7 @@ export default function RenderOverlay({ bridge }: RenderOverlayProps) {
}

if ([DROP_ZONE_RIGHT, DROP_ZONE_LEFT].includes(dragOverZone)) {
if (isOriginalParentLayout || !isDraggingOverHorizontalContainer) {
if (!isDraggingOverHorizontalContainer) {
const hasNewPageRow = isOriginalParentLayout || isOriginalParentColumn;

if (hasNewPageRow) {
Expand Down Expand Up @@ -1064,11 +1064,7 @@ export default function RenderOverlay({ bridge }: RenderOverlayProps) {
}
}

if (
dragOverSlotParentProp &&
!isOriginalParentLayout &&
isDraggingOverHorizontalContainer
) {
if (dragOverSlotParentProp && isDraggingOverHorizontalContainer) {
const isDraggingOverDirectionStart =
dragOverZone ===
(dragOverSlot?.flowDirection === 'row' ? DROP_ZONE_LEFT : DROP_ZONE_RIGHT);
Expand Down
13 changes: 10 additions & 3 deletions test/models/ToolpadEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ export class ToolpadEditor {
await setTimeout(100);
}

async dragTo(sourceLocator: Locator, moveTargetX: number, moveTargetY: number, hasDrop = true) {
async dragTo(
sourceLocator: Locator,
moveTargetX: number,
moveTargetY: number,
hasDrop = true,
steps = 10,
) {
const sourceBoundingBox = await sourceLocator.boundingBox();

await this.page.mouse.move(
Expand All @@ -118,7 +124,7 @@ export class ToolpadEditor {

await this.page.mouse.down();

await this.page.mouse.move(moveTargetX, moveTargetY, { steps: 10 });
await this.page.mouse.move(moveTargetX, moveTargetY, { steps });

if (hasDrop) {
await this.page.mouse.up();
Expand All @@ -134,6 +140,7 @@ export class ToolpadEditor {
moveTargetX?: number,
moveTargetY?: number,
hasDrop = true,
steps?: number,
) {
const style = await this.page.addStyleTag({ content: `* { transition: none !important; }` });

Expand All @@ -155,7 +162,7 @@ export class ToolpadEditor {
const sourceLocator = this.getComponentCatalogItem(componentName);
await expect(sourceLocator).toBeVisible();

await this.dragTo(sourceLocator, moveTargetX!, moveTargetY!, hasDrop);
await this.dragTo(sourceLocator, moveTargetX!, moveTargetY!, hasDrop, steps);

await style.evaluate((elm) => elm.parentNode?.removeChild(elm));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as React from 'react';
import { Box } from '@mui/material';
import { createComponent } from '@mui/toolpad/browser';

function FullWidth() {
return <Box sx={{ width: '100%' }}>fullwidth</Box>;
}

export default createComponent(FullWidth);
6 changes: 6 additions & 0 deletions test/visual/components/fixture/toolpad/pages/blank/page.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: v1
kind: page
spec:
id: QYjq2fJ
title: blank
display: shell
42 changes: 41 additions & 1 deletion test/visual/components/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ test('rendering components in the app runtime', async ({ page, argosScreenshot }

test('rendering components in the app editor', async ({ page, argosScreenshot }) => {
const editorModel = new ToolpadEditor(page);
await editorModel.goto();
await editorModel.goToPage('components');

await editorModel.waitForOverlay();

Expand All @@ -42,6 +42,46 @@ test('rendering components in the app editor', async ({ page, argosScreenshot })
await argosScreenshot('with-selection');
});

test('building layouts', async ({ page, argosScreenshot }) => {
const editorModel = new ToolpadEditor(page);
await editorModel.goToPage('blank');

await editorModel.waitForOverlay();

const getNthFullWidthBoundingBox = (
n: number,
): Promise<{ x: number; y: number; width: number; height: number } | null> =>
editorModel.appCanvas.getByText('fullwidth').nth(n).boundingBox();

await editorModel.dragNewComponentToCanvas('FullWidth');

await argosScreenshot('building-layout-1');

const firstFullWidthBoundingBox = await getNthFullWidthBoundingBox(0);

// Place inside right of first element
await editorModel.dragNewComponentToCanvas(
'FullWidth',
firstFullWidthBoundingBox!.x + (2 / 3) * firstFullWidthBoundingBox!.width,
firstFullWidthBoundingBox!.y + firstFullWidthBoundingBox!.height / 2,
);

await argosScreenshot('building-layout-2');

const secondFullWidthBoundingBox = await getNthFullWidthBoundingBox(1);

// Place outside right of second element
await editorModel.dragNewComponentToCanvas(
'FullWidth',
secondFullWidthBoundingBox!.x + secondFullWidthBoundingBox!.width + 12,
secondFullWidthBoundingBox!.y + secondFullWidthBoundingBox!.height / 2,
true,
1,
);

await argosScreenshot('building-layout-3');
});

test('showing grid while resizing elements', async ({ page, argosScreenshot }) => {
const editorModel = new ToolpadEditor(page);
await editorModel.goToPage('rows');
Expand Down
Loading