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

Activating the escape hatch fixes the size of the target #4356

Merged
merged 3 commits into from
Oct 11, 2023
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 @@ -37,6 +37,7 @@ import {
keyDown,
mouseDownAtPoint,
mouseDragFromPointToPoint,
mouseDragFromPointWithDelta,
mouseMoveToPoint,
mouseUpAtPoint,
pressKey,
Expand Down Expand Up @@ -1170,7 +1171,7 @@ describe('Convert to absolute/escape hatch', () => {
data-uid='aaa'
>
<View
style={{ backgroundColor: '#aaaaaa33', width: '50%', height: '20%', right: 185, bottom: 305, top: 15, left: 15, position: 'absolute', }}
style={{ backgroundColor: '#aaaaaa33', width: 200, height: 80, right: 185, bottom: 305, top: 15, left: 15, position: 'absolute', }}
data-uid='bbb'
data-testid='bbb'
/>
Expand Down Expand Up @@ -1290,7 +1291,7 @@ describe('Convert to absolute/escape hatch', () => {
data-uid='aaa'
>
<View
style={{ backgroundColor: '#aaaaaa33', width: '50%', height: '20%', right: 185, bottom: 305, top: 15, left: 15, position: 'absolute', }}
style={{ backgroundColor: '#aaaaaa33', width: 200, height: 80, right: 185, bottom: 305, top: 15, left: 15, position: 'absolute', }}
data-uid='bbb'
data-testid='bbb'
/>
Expand All @@ -1301,6 +1302,148 @@ describe('Convert to absolute/escape hatch', () => {
})
})

describe('Escape hatch strategy on awkward project', () => {
it('Fixes the size of the dragged element to stop it growing out of control', async () => {
const renderResult = await renderTestEditorWithCode(
`
import * as React from 'react'
import { Scene, Storyboard } from 'utopia-api'

export var storyboard = (
<Storyboard data-uid='sb'>
<div
style={{
backgroundColor: '#aaaaaa33',
position: 'absolute',
left: 0,
top: 0,
width: 400,
height: 400,
display: 'flex',
flexDirection: 'column',
gap: 60,
}}
data-uid='root'
>
<div
style={{
display: 'flex',
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
}}
data-uid='container'
>
<div
style={{
height: '100%',
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
backgroundColor: '#FFEE00',
}}
data-testid='drag-me'
data-uid='drag-me'
>
<div
style={{
height: 100,
width: 100,
backgroundColor: '#FD1919',
}}
data-uid='child'
/>
</div>
</div>
</div>
</Storyboard>
)
`,
'await-first-dom-report',
)

const targetElement = EP.elementPath([['sb', 'root', 'container', 'drag-me']])

await selectComponentsForTest(renderResult, [targetElement])

const targetBounds = renderResult.renderedDOM.getByTestId('drag-me').getBoundingClientRect()
const canvasControlsLayer = renderResult.renderedDOM.getByTestId(CanvasControlsContainerID)

await mouseDragFromPointWithDelta(
canvasControlsLayer,
{
x: targetBounds.left + targetBounds.width / 2,
y: targetBounds.top + targetBounds.height / 2,
},
{
x: 15,
y: 15,
},
)

expect(getPrintedUiJsCode(renderResult.getEditorState())).toEqual(
formatTestProjectCode(`
import * as React from 'react'
import { Scene, Storyboard } from 'utopia-api'

export var storyboard = (
<Storyboard data-uid='sb'>
<div
style={{
backgroundColor: '#aaaaaa33',
position: 'absolute',
left: 0,
top: 0,
width: 400,
height: 400,
display: 'flex',
flexDirection: 'column',
gap: 60,
}}
data-uid='root'
>
<div
style={{
display: 'flex',
flexDirection: 'row',
width: '100%',
justifyContent: 'space-between',
}}
data-uid='container'
>
<div
style={{
height: 100,
overflow: 'hidden',
display: 'flex',
flexDirection: 'column',
backgroundColor: '#FFEE00',
width: 100,
position: 'absolute',
left: 15,
top: 15,
}}
data-testid='drag-me'
data-uid='drag-me'
>
<div
style={{
height: 100,
width: 100,
backgroundColor: '#FD1919',
}}
data-uid='child'
/>
</div>
</div>
</div>
</Storyboard>
)
`),
)
})
})

function codeForDragToEscapeHatchProject(flowOrFlex: 'flow' | 'flex'): string {
return `
<div
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ import type { ElementPathTrees } from '../../../../core/shared/element-path-tree
import { cssPixelLength } from '../../../inspector/common/css-utils'
import type { ProjectContentTreeRoot } from '../../../assets'
import { showToastCommand } from '../../commands/show-toast-command'
import { sizeToVisualDimensions } from '../../../inspector/inspector-common'

export const ConvertToAbsoluteAndMoveStrategyID = 'CONVERT_TO_ABSOLUTE_AND_MOVE_STRATEGY'

Expand Down Expand Up @@ -387,7 +388,10 @@ function collectSetLayoutPropCommands(
})()

if (newLocalFrame != null) {
let commands: Array<CanvasCommand> = [convertToAbsolute('always', path)]
let commands: Array<CanvasCommand> = [
...sizeToVisualDimensions(metadata, canvasState.startingElementPathTree, path),
convertToAbsolute('always', path),
]
const updatePinsCommands = createUpdatePinsCommands(
path,
metadata,
Expand Down