-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(inspector) When loading component descriptors, take account of fi…
…le mappings. (#5781) - `importedFromWhere` now invokes `applyFilePathMappingsToFilePath` for the path that it returns so that it applies the path mapping rules to the results gained. - Added a call to `getFilePathMappings` in a few places to support a call to `getComponentDescriptorForTarget`.
- Loading branch information
1 parent
425833f
commit 872b256
Showing
10 changed files
with
183 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
139 changes: 139 additions & 0 deletions
139
editor/src/core/property-controls/property-controls-utils.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
import type { ProjectContentTreeRoot } from '../../components/assets' | ||
import { addFileToProjectContents } from '../../components/assets' | ||
import type { | ||
ComponentDescriptor, | ||
PropertyControlsInfo, | ||
} from '../../components/custom-code/code-file' | ||
import { componentDescriptorFromDescriptorFile } from '../../components/custom-code/code-file' | ||
import { simpleDefaultProject } from '../../sample-projects/sample-project-utils' | ||
import { parseProjectContents } from '../../sample-projects/sample-project-utils.test-utils' | ||
import { codeFile } from '../shared/project-file-types' | ||
import { assertNever } from '../shared/utils' | ||
import { getComponentDescriptorForTarget } from './property-controls-utils' | ||
import * as EP from '../shared/element-path' | ||
|
||
describe('getComponentDescriptorForTarget', () => { | ||
function getProjectContents(mappedPath: 'mapped-path' | 'regular-path'): ProjectContentTreeRoot { | ||
let baseProjectContents: ProjectContentTreeRoot = simpleDefaultProject().projectContents | ||
baseProjectContents = addFileToProjectContents( | ||
baseProjectContents, | ||
'/jsconfig.json', | ||
codeFile( | ||
`{ | ||
"compilerOptions": { | ||
"checkJs": true, | ||
"jsx": "react-jsx", | ||
"target": "ES2022", | ||
"module": "ES2022", | ||
"moduleResolution": "Bundler", | ||
"baseUrl": ".", | ||
"paths": { | ||
"~/*": ["app/*"] | ||
} | ||
}, | ||
"include": ["./**/*.d.ts", "./**/*.js", "./**/*.jsx"] | ||
} | ||
`, | ||
null, | ||
), | ||
) | ||
baseProjectContents = addFileToProjectContents( | ||
baseProjectContents, | ||
'/app/components.js', | ||
codeFile( | ||
` | ||
import * as React from 'react' | ||
export const Component = () => { | ||
return <div data-uid='component-div' /> | ||
} | ||
`, | ||
null, | ||
), | ||
) | ||
switch (mappedPath) { | ||
case 'mapped-path': | ||
baseProjectContents = addFileToProjectContents( | ||
baseProjectContents, | ||
'/src/app.js', | ||
codeFile( | ||
` | ||
import * as React from 'react' | ||
import { Component } from '~/components' | ||
export const App = (props) => { | ||
return ( | ||
<div | ||
data-uid='div' | ||
style={{ width: '100%', height: '100%', backgroundcolor: '#ffffff', position: 'relative' }} | ||
> | ||
<Component data-uid='component' /> | ||
</div> | ||
) | ||
}`, | ||
null, | ||
), | ||
) | ||
break | ||
case 'regular-path': | ||
baseProjectContents = addFileToProjectContents( | ||
baseProjectContents, | ||
'/src/app.js', | ||
codeFile( | ||
` | ||
import * as react from 'react' | ||
import { Component } from '/app/components' | ||
export const App = (props) => { | ||
return ( | ||
<div | ||
data-uid='div' | ||
style={{ width: '100%', height: '100%', backgroundcolor: '#ffffff', position: 'relative' }} | ||
> | ||
<Component data-uid='component' /> | ||
</div> | ||
) | ||
}`, | ||
null, | ||
), | ||
) | ||
break | ||
default: | ||
assertNever(mappedPath) | ||
} | ||
|
||
return parseProjectContents(baseProjectContents) | ||
} | ||
const componentDescriptor: ComponentDescriptor = { | ||
properties: {}, | ||
supportsChildren: true, | ||
preferredChildComponents: [], | ||
variants: [], | ||
source: componentDescriptorFromDescriptorFile('/components.utopia.js'), | ||
focus: 'default', | ||
inspector: { type: 'hidden' }, | ||
emphasis: 'regular', | ||
icon: 'component', | ||
label: 'Component', | ||
} | ||
const propertyControlsInfo: PropertyControlsInfo = { | ||
['/app/components']: { | ||
['Component']: componentDescriptor, | ||
}, | ||
} | ||
it('works with the regular path', () => { | ||
const projectContents = getProjectContents('regular-path') | ||
const actualResult = getComponentDescriptorForTarget( | ||
EP.fromString(`sample-storyboard/sample-scene/sample-app:div/component`), | ||
propertyControlsInfo, | ||
projectContents, | ||
) | ||
expect(actualResult).toEqual(componentDescriptor) | ||
}) | ||
it('works with a mapped path', () => { | ||
const projectContents = getProjectContents('mapped-path') | ||
const actualResult = getComponentDescriptorForTarget( | ||
EP.fromString(`sample-storyboard/sample-scene/sample-app:div/component`), | ||
propertyControlsInfo, | ||
projectContents, | ||
) | ||
expect(actualResult).toEqual(componentDescriptor) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters