Allow point-and-click Insert to suggest nested files (#7130)

* fix: saving off code

* fix: saving off progress

* chore: implemented kcl sample assembly unique sub dir creation

* fix: removing testing console logs

* fix: cleaning up old comment

* fix: add to file always does subdir/main.kcl now for single files

* fix: auto fmt

* fix: delete project and folder from ttc

* fix: fixed deleting projects and subdirs

* fix: if statement logic fixed for deleting project or subdir

* fix: TTC isProjectNew makes main.kcl not a subdir.

* fix: fixing e2e test

* fix: this should pass now

* pierremtb/make-insert-take-over-the-import-world

* Add test that doesn't work locally yet :(

* Fix test 🤦

* Change splice for push

* Fix up windows path

---------

Co-authored-by: Kevin Nadro <kevin@zoo.dev>
Co-authored-by: Kevin Nadro <nadr0@users.noreply.github.com>
This commit is contained in:
Pierre Jacquier
2025-05-20 20:44:22 -04:00
committed by GitHub
parent 0753987b5a
commit c48d9fd4d7
2 changed files with 71 additions and 39 deletions

View File

@ -70,22 +70,28 @@ test.describe('Point-and-click assemblies tests', () => {
await test.step('Setup parts and expect empty assembly scene', async () => {
const projectName = 'assembly'
await context.folderSetupFn(async (dir) => {
const bracketDir = path.join(dir, projectName)
await fsp.mkdir(bracketDir, { recursive: true })
const projDir = path.join(dir, projectName)
const nestedProjDir = path.join(dir, projectName, 'nested', 'twice')
await fsp.mkdir(projDir, { recursive: true })
await fsp.mkdir(nestedProjDir, { recursive: true })
await Promise.all([
fsp.copyFile(
executorInputPath('cylinder.kcl'),
path.join(bracketDir, 'cylinder.kcl')
path.join(projDir, 'cylinder.kcl')
),
fsp.copyFile(
executorInputPath('cylinder.kcl'),
path.join(nestedProjDir, 'main.kcl')
),
fsp.copyFile(
executorInputPath('e2e-can-sketch-on-chamfer.kcl'),
path.join(bracketDir, 'bracket.kcl')
path.join(projDir, 'bracket.kcl')
),
fsp.copyFile(
testsInputPath('cube.step'),
path.join(bracketDir, 'cube.step')
path.join(projDir, 'cube.step')
),
fsp.writeFile(path.join(bracketDir, 'main.kcl'), ''),
fsp.writeFile(path.join(projDir, 'main.kcl'), ''),
])
})
await page.setBodyDimensions({ width: 1000, height: 500 })
@ -167,6 +173,25 @@ test.describe('Point-and-click assemblies tests', () => {
await expect(
page.getByText('This file is already imported')
).toBeVisible()
await cmdBar.closeCmdBar()
})
await test.step('Insert a nested kcl part', async () => {
await insertPartIntoAssembly(
'nested/twice/main.kcl',
'main',
toolbar,
cmdBar,
page
)
await toolbar.openPane('code')
await page.waitForTimeout(10000)
await editor.expectEditor.toContain(
`
import "nested/twice/main.kcl" as main
`,
{ shouldNormalise: true }
)
})
}
)

View File

@ -441,39 +441,46 @@ export const FileMachineProvider = ({
)
useMenuListener(cb)
const kclCommandMemo = useMemo(
() =>
kclCommands({
authToken: token ?? '',
projectData,
settings: {
defaultUnit:
settings.modeling.defaultUnit.current ??
DEFAULT_DEFAULT_LENGTH_UNIT,
},
specialPropsForInsertCommand: {
providedOptions: (isDesktop() && project?.children
? project.children
: []
).flatMap((v) => {
// TODO: add support for full tree traversal when KCL support subdir imports
const relativeFilePath = v.path.replace(
project?.path + window.electron.sep,
''
)
const isDirectory = v.children
const isCurrentFile = v.path === file?.path
return isDirectory || isCurrentFile
? []
: {
name: relativeFilePath,
value: relativeFilePath,
}
}),
},
}),
[codeManager, kclManager, send, project, file]
)
const kclCommandMemo = useMemo(() => {
const providedOptions = []
if (isDesktop() && project?.children && file?.path) {
const projectPath = project.path
const filePath = file.path
let children = project.children
while (children.length > 0) {
const v = children.pop()
if (!v) {
continue
}
if (v.children) {
children.push(...v.children)
continue
}
const relativeFilePath = v.path.replace(
projectPath + window.electron.sep,
''
)
const isCurrentFile = v.path === filePath
if (!isCurrentFile) {
providedOptions.push({
name: relativeFilePath.replaceAll(window.electron.sep, '/'),
value: relativeFilePath.replaceAll(window.electron.sep, '/'),
})
}
}
}
return kclCommands({
authToken: token ?? '',
projectData,
settings: {
defaultUnit:
settings.modeling.defaultUnit.current ?? DEFAULT_DEFAULT_LENGTH_UNIT,
},
specialPropsForInsertCommand: { providedOptions },
})
}, [codeManager, kclManager, send, project, file])
useEffect(() => {
commandBarActor.send({