Skip to content

Commit ed52f09

Browse files
authored
Use node name in the canvas HUD (#1818)
1 parent e0e6924 commit ed52f09

File tree

5 files changed

+11
-19
lines changed

5 files changed

+11
-19
lines changed

packages/toolpad-app/cli/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export default async function cli(argv: string[]) {
143143
);
144144

145145
const command: string | undefined = args._[0];
146-
const dir: string = args._[1];
146+
const dir: string = path.resolve(process.cwd(), args._[1] || '.');
147147

148148
const runArgs = {
149149
devMode: args['--dev'],

packages/toolpad-app/src/toolpad/AppEditor/BindingEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ export function BindingEditorDialog<V>({
306306
open,
307307
onClose,
308308
}: BindingEditorDialogProps<V>) {
309-
const { propType } = useBindingEditorContext();
309+
const { propType, label } = useBindingEditorContext();
310310

311311
const [input, setInput] = React.useState(value);
312312
React.useEffect(() => {
@@ -360,7 +360,7 @@ export function BindingEditorDialog<V>({
360360
scroll="body"
361361
maxWidth="lg"
362362
>
363-
<DialogTitle>Bind a property</DialogTitle>
363+
<DialogTitle>Bind property &quot;{label}&quot;</DialogTitle>
364364
<DialogContent>
365365
{propType?.type === 'event' ? (
366366
<ActionEditor value={input} onChange={(newValue) => setInput(newValue)} />

packages/toolpad-app/src/toolpad/AppEditor/PageEditor/RenderPanel/NodeHud.tsx

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ import {
1313
RECTANGLE_EDGE_LEFT,
1414
RECTANGLE_EDGE_RIGHT,
1515
} from '../../../../utils/geometry';
16-
import { useDom } from '../../../AppState';
17-
import { useToolpadComponent } from '../../toolpadComponents';
18-
import { getElementNodeComponentId } from '../../../../toolpadComponents';
1916

2017
const HINT_POSITION_TOP = 'top';
2118
const HINT_POSITION_BOTTOM = 'bottom';
@@ -175,11 +172,6 @@ export default function NodeHud({
175172
isOutlineVisible = false,
176173
isHoverable = true,
177174
}: NodeHudProps) {
178-
const { dom } = useDom();
179-
180-
const componentId = appDom.isElement(node) ? getElementNodeComponentId(node) : '';
181-
const component = useToolpadComponent(dom, componentId);
182-
183175
const hintPosition = rect.y > HUD_HEIGHT ? HINT_POSITION_TOP : HINT_POSITION_BOTTOM;
184176

185177
return (
@@ -202,14 +194,15 @@ export default function NodeHud({
202194
<SelectionHintWrapper style={absolutePositionCss(rect)} hintPosition={hintPosition}>
203195
<div
204196
draggable
197+
data-testid="node-hud-tag"
205198
className={nodeHudClasses.selectionHint}
206199
onDragStart={onNodeDragStart}
207200
role="presentation"
208201
onClick={stopPropagationHandler}
209202
onMouseDown={stopPropagationHandler}
210203
onMouseUp={stopPropagationHandler}
211204
>
212-
{component?.displayName || '<unknown>'}
205+
{node.name}
213206
<DragIndicatorIcon color="inherit" />
214207
<IconButton aria-label="Duplicate" color="inherit" onMouseUp={onDuplicate}>
215208
<Tooltip title="Duplicate" enterDelay={400}>

test/integration/editor/index.spec.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,13 @@ test.describe('with fixture', () => {
5858

5959
test('can move elements in page', async ({ page }) => {
6060
const editorModel = new ToolpadEditor(page);
61-
const TEXT_FIELD_COMPONENT_DISPLAY_NAME = 'Text field';
6261

6362
await editorModel.goto();
6463

6564
await editorModel.waitForOverlay();
6665

67-
const canvasMoveElementHandleSelector = `:has-text("${TEXT_FIELD_COMPONENT_DISPLAY_NAME}")[draggable]`;
68-
6966
const canvasInputLocator = editorModel.appCanvas.locator('input');
70-
const canvasMoveElementHandleLocator = editorModel.appCanvas.locator(
71-
canvasMoveElementHandleSelector,
72-
);
67+
const canvasMoveElementHandleLocator = editorModel.appCanvas.getByTestId('node-hud-tag');
7368

7469
const firstTextFieldLocator = canvasInputLocator.first();
7570
const secondTextFieldLocator = canvasInputLocator.nth(1);
@@ -96,7 +91,7 @@ test.describe('with fixture', () => {
9691
const moveTargetY = secondTextFieldBoundingBox!.y + secondTextFieldBoundingBox!.height / 2;
9792

9893
await editorModel.dragToAppCanvas(
99-
editorModel.appCanvas.locator(canvasMoveElementHandleSelector),
94+
editorModel.appCanvas.getByTestId('node-hud-tag'),
10095
moveTargetX,
10196
moveTargetY,
10297
);

test/models/ToolpadEditor.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { expect, FrameLocator, Locator, Page } from '@playwright/test';
2+
import { setTimeout } from 'timers/promises';
23
import { gotoIfNotCurrent } from './shared';
34

45
class CreatePageDialog {
@@ -109,6 +110,9 @@ export class ToolpadEditor {
109110

110111
async waitForOverlay() {
111112
await this.pageOverlay.waitFor({ state: 'visible' });
113+
// Some tests seem to be flaky around this waitFor and perform better with a short timeout
114+
// Not sure yet where the race condition is happening
115+
await setTimeout(100);
112116
}
113117

114118
async dragToAppCanvas(sourceLocator: Locator, moveTargetX: number, moveTargetY: number) {

0 commit comments

Comments
 (0)