Skip to content

Commit 15676a3

Browse files
authored
Only show grid lines when selecting grid or during child interaction (#6647)
**Problem:** Grid lines are shown all the time whether a grid or a grid child is selected. The grid sizing pills are also shown all the time. **Fix:** Only show the grid lines if: - the grid itself is selected - a grid child is selected **and** an interaction is in progress Only show the grid sizing pills if: - the grid itself is selected **Note:** I enabled the grid lines also for absolute resize of grid children because they can be affected by the grid so I thought it would be good to have them, but lmk if you feel otherwise. https://github.com/user-attachments/assets/eba83673-fe5d-43a2-8dcf-aba7bcc2cca1 Fixes #6645
1 parent 85df996 commit 15676a3

6 files changed

+142
-98
lines changed

editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx

+20-50
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
11
import * as EP from '../../../../core/shared/element-path'
2-
import {
3-
getRectCenter,
4-
localRectangle,
5-
offsetPoint,
6-
windowPoint,
7-
} from '../../../../core/shared/math-utils'
2+
import { offsetPoint, windowPoint } from '../../../../core/shared/math-utils'
83
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
94
import CanvasActions from '../../canvas-actions'
105
import { GridCellTestId } from '../../controls/grid-controls-for-strategies'
116
import { mouseDownAtPoint, mouseMoveToPoint, mouseUpAtPoint } from '../../event-helpers.test-utils'
127
import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
13-
import { gridCellTargetId } from './grid-cell-bounds'
148
import { runGridMoveTest } from './grid.test-utils'
159

1610
describe('grid element change location strategy', () => {
@@ -22,7 +16,7 @@ describe('grid element change location strategy', () => {
2216
editor,
2317
{
2418
scale: 1,
25-
pathString: `sb/scene/grid/${testId}`,
19+
gridPath: 'sb/scene/grid',
2620
testId: testId,
2721
},
2822
)
@@ -52,7 +46,7 @@ describe('grid element change location strategy', () => {
5246
editor,
5347
{
5448
scale: 1,
55-
pathString: `sb/scene/grid/${testId}`,
49+
gridPath: 'sb/scene/grid',
5650
testId: testId,
5751
},
5852
)
@@ -79,7 +73,7 @@ describe('grid element change location strategy', () => {
7973
editor,
8074
{
8175
scale: 1,
82-
pathString: `sb/scene/grid/${testId}`,
76+
gridPath: 'sb/scene/grid',
8377
testId: testId,
8478
},
8579
(ed) => {
@@ -109,7 +103,7 @@ describe('grid element change location strategy', () => {
109103
editor,
110104
{
111105
scale: 1,
112-
pathString: `sb/scene/grid/${testId}`,
106+
gridPath: 'sb/scene/grid/',
113107
testId: testId,
114108
},
115109
)
@@ -131,7 +125,7 @@ describe('grid element change location strategy', () => {
131125
editor,
132126
{
133127
scale: 1,
134-
pathString: `sb/scene/grid/${testId}`,
128+
gridPath: 'sb/scene/grid',
135129
testId: testId,
136130
targetCell: { row: 2, column: 1 },
137131
draggedCell: { row: 2, column: 2 },
@@ -153,7 +147,7 @@ describe('grid element change location strategy', () => {
153147
editor,
154148
{
155149
scale: 1,
156-
pathString: `sb/scene/grid/${testId}`,
150+
gridPath: 'sb/scene/grid',
157151
testId: testId,
158152
tab: true,
159153
},
@@ -178,7 +172,7 @@ describe('grid element change location strategy', () => {
178172
editor,
179173
{
180174
scale: 1,
181-
pathString: `sb/scene/grid/${testId}`,
175+
gridPath: 'sb/scene/grid',
182176
testId: testId,
183177
targetCell: { row: 3, column: 1 },
184178
},
@@ -200,7 +194,7 @@ describe('grid element change location strategy', () => {
200194
editor,
201195
{
202196
scale: 0.5,
203-
pathString: `sb/scene/grid/${testId}`,
197+
gridPath: 'sb/scene/grid',
204198
testId: testId,
205199
},
206200
)
@@ -220,7 +214,7 @@ describe('grid element change location strategy', () => {
220214
editor,
221215
{
222216
scale: 2,
223-
pathString: `sb/scene/grid/${testId}`,
217+
gridPath: 'sb/scene/grid',
224218
testId: testId,
225219
},
226220
)
@@ -243,7 +237,7 @@ describe('grid element change location strategy', () => {
243237
editor,
244238
{
245239
scale: 1,
246-
pathString: `sb/scene/grid/${testId}`,
240+
gridPath: 'sb/scene/grid',
247241
testId: testId,
248242
},
249243
)
@@ -267,7 +261,7 @@ describe('grid element change location strategy', () => {
267261
editor,
268262
{
269263
scale: 1,
270-
pathString: `sb/scene/grid/${testId}`,
264+
gridPath: 'sb/scene/grid',
271265
testId: testId,
272266
},
273267
)
@@ -291,7 +285,7 @@ describe('grid element change location strategy', () => {
291285
editor,
292286
{
293287
scale: 1,
294-
pathString: `sb/scene/grid/${testId}`,
288+
gridPath: 'sb/scene/grid',
295289
testId: testId,
296290
targetCell: { row: 3, column: 2 },
297291
},
@@ -316,7 +310,7 @@ describe('grid element change location strategy', () => {
316310
editor,
317311
{
318312
scale: 1,
319-
pathString: `sb/scene/grid/${testId}`,
313+
gridPath: 'sb/scene/grid',
320314
testId: testId,
321315
},
322316
)
@@ -340,7 +334,7 @@ describe('grid element change location strategy', () => {
340334
editor,
341335
{
342336
scale: 1,
343-
pathString: `sb/scene/grid/${testId}`,
337+
gridPath: 'sb/scene/grid',
344338
testId: testId,
345339
},
346340
)
@@ -366,8 +360,6 @@ export var storyboard = (
366360
data-testid='grid'
367361
style={{
368362
position: 'absolute',
369-
left: -94,
370-
top: 698,
371363
display: 'grid',
372364
gap: 10,
373365
width: 600,
@@ -428,33 +420,11 @@ export var storyboard = (
428420
)
429421

430422
const testId = 'grid-inside-grid'
431-
const elementPathToDrag = EP.fromString(`sb/grid/${testId}`)
432-
433-
await selectComponentsForTest(editor, [elementPathToDrag])
434-
435-
const sourceGridCell = editor.renderedDOM.getByTestId(GridCellTestId(elementPathToDrag))
436-
const targetGridCell = editor.renderedDOM.getByTestId(
437-
gridCellTargetId(EP.fromString('sb/grid'), 2, 3),
438-
)
439-
440-
const sourceRect = sourceGridCell.getBoundingClientRect()
441-
const targetRect = targetGridCell.getBoundingClientRect()
442-
443-
const dragFrom = {
444-
x: sourceRect.x + 10,
445-
y: sourceRect.y + 10,
446-
}
447-
const dragTo = getRectCenter(
448-
localRectangle({
449-
x: targetRect.x,
450-
y: targetRect.y,
451-
width: targetRect.width,
452-
height: targetRect.height,
453-
}),
454-
)
455-
await mouseDownAtPoint(sourceGridCell, dragFrom)
456-
await mouseMoveToPoint(sourceGridCell, dragTo)
457-
await mouseUpAtPoint(sourceGridCell, dragTo)
423+
await runGridMoveTest(editor, {
424+
scale: 1,
425+
gridPath: 'sb/grid',
426+
testId: testId,
427+
})
458428

459429
const { gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd } =
460430
editor.renderedDOM.getByTestId(testId).style

editor/src/components/canvas/canvas-strategies/strategies/grid-reorder-strategy.spec.browser2.tsx

+8-5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
66
import type { GridCellCoordinates } from './grid-cell-bounds'
77
import { runGridMoveTest } from './grid.test-utils'
88
import * as EP from '../../../../core/shared/element-path'
9+
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
910

1011
describe('grid reorder', () => {
1112
it('reorders an element without setting positioning (inside contiguous area)', async () => {
@@ -111,6 +112,8 @@ describe('grid reorder', () => {
111112

112113
expect(first.cells).toEqual(['pink', 'cyan', 'blue', 'orange'])
113114

115+
await selectComponentsForTest(editor, [])
116+
114117
const second = await runReorderTest(
115118
editor,
116119
'sb/scene/grid',
@@ -242,7 +245,7 @@ describe('grid reorder', () => {
242245

243246
async function runReorderTest(
244247
editor: EditorRenderResult,
245-
gridTestId: string,
248+
gridPath: string,
246249
testId: string,
247250
targetCell: GridCellCoordinates,
248251
options?: { tab?: boolean },
@@ -251,22 +254,22 @@ async function runReorderTest(
251254
editor,
252255
{
253256
scale: 1,
254-
pathString: `${gridTestId}/${testId}`,
257+
gridPath: gridPath,
255258
testId: testId,
256259
targetCell: targetCell,
257260
tab: options?.tab,
258261
},
259262
)
260263

261-
const element = editor.getEditorState().editor.jsxMetadata[gridTestId]
262-
if (isLeft(element.element) || !isJSXElement(element.element.value)) {
264+
const grid = editor.getEditorState().editor.jsxMetadata[gridPath]
265+
if (isLeft(grid.element) || !isJSXElement(grid.element.value)) {
263266
throw new Error('expected jsx element')
264267
}
265268

266269
const cells = MetadataUtils.getChildrenOrdered(
267270
editor.getEditorState().editor.jsxMetadata,
268271
editor.getEditorState().editor.elementPathTree,
269-
element.elementPath,
272+
EP.fromString(gridPath),
270273
)
271274

272275
return {

editor/src/components/canvas/canvas-strategies/strategies/grid-resize-element-strategy.spec.browser2.tsx

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
offsetPoint,
1616
} from '../../../../core/shared/math-utils'
1717
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
18-
import { mouseDragFromPointToPoint } from '../../event-helpers.test-utils'
18+
import { mouseDownAtPoint, mouseDragFromPointToPoint } from '../../event-helpers.test-utils'
1919
import type { EditorRenderResult } from '../../ui-jsx.test-utils'
2020
import { renderTestEditorWithCode } from '../../ui-jsx.test-utils'
2121
import type { GridResizeEdge } from '../interaction-state'
@@ -34,6 +34,9 @@ async function runCellResizeTest(
3434
const resizeControl = editor.renderedDOM.getByTestId(
3535
ResizePointTestId(gridEdgeToEdgePosition(edge)),
3636
)
37+
38+
const resizeControlBox = resizeControl.getBoundingClientRect()
39+
await mouseDownAtPoint(resizeControl, { x: resizeControlBox.x + 5, y: resizeControlBox.y + 5 })
3740
const targetGridCell = editor.renderedDOM.getByTestId(dragToCellTestId)
3841

3942
await mouseDragFromPointToPoint(

0 commit comments

Comments
 (0)