Skip to content

Commit

Permalink
Remix Outlet should be autolocked (#4209)
Browse files Browse the repository at this point in the history
* Autolock Outlets

* Added test

* Fix test
  • Loading branch information
gbalint authored Sep 19, 2023
1 parent 526e5d8 commit d3d549d
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,65 @@ describe('Remix content', () => {
})
})

it('Remix Outlet is automatically locked', async () => {
const project = createModifiedProject({
[StoryboardFilePath]: `import * as React from 'react'
import { RemixScene, Storyboard } from 'utopia-api'
export var storyboard = (
<Storyboard data-uid='storyboard'>
<RemixScene
style={{
width: 700,
height: 759,
position: 'absolute',
left: 212,
top: 128,
}}
data-label='Playground'
data-uid='remix-scene'
/>
</Storyboard>
)
`,
['/src/root.js']: `import React from 'react'
import { Outlet } from '@remix-run/react'
export default function Root() {
return (
<div data-uid='rootdiv'>
${RootTextContent}
<Outlet data-uid='outlet'/>
</div>
)
}
`,
['/src/routes/_index.js']: `import React from 'react'
export default function Index() {
return <div
style={{
width: 200,
height: 200,
position: 'absolute',
left: 0,
top: 0,
}}
data-uid='remix-div'
>
${DefaultRouteTextContent}
</div>
}
`,
})

const renderResult = await renderRemixProject(project)

expect(
renderResult.getEditorState().editor.lockedElements.simpleLock.map(EP.toString),
).toContain('storyboard/remix-scene:rootdiv/outlet')
})

it('Two remix scenes, both have metadata', async () => {
const project = createModifiedProject({
[StoryboardFilePath]: `import * as React from 'react'
Expand Down
8 changes: 6 additions & 2 deletions editor/src/core/shared/element-locking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ export function updateSimpleLocks(
): Array<ElementPath> {
let result: Array<ElementPath> = [...currentSimpleLockedItems]
for (const [key, value] of Object.entries(newMetadata)) {
// This entry is the root element of an instance and it isn't present in the previous metadata,
// This entry is the root element of an instance or a remix Outlet, and it isn't present in the previous metadata,
// which implies that it has been newly added.
if (EP.isRootElementOfInstance(value.elementPath) && !(key in priorMetadata)) {
if (
(EP.isRootElementOfInstance(value.elementPath) ||
MetadataUtils.isProbablyRemixOutlet(newMetadata, value.elementPath)) &&
!(key in priorMetadata)
) {
result.push(value.elementPath)
}
}
Expand Down

0 comments on commit d3d549d

Please sign in to comment.