[Fix] Using main.kcl for more of the workflows that generate kcl files (#7017)
* fix: when creating a t2c in a new project make the file name main.kcl * fix: when creating a sample in a new project and there is only 1 file make the filename main.kcl * fix: auto fixes * fix: share links generate main.kcl * fix: codespell typoe * fix: fixing E2E tests * Fix 3 more tests * fix: share url link e2e file name fix --------- Co-authored-by: Pierre Jacquier <pierre@zoo.dev> Co-authored-by: Pierre Jacquier <pierrejacquier39@gmail.com> Co-authored-by: Frank Noirot <frank@zoo.dev>
This commit is contained in:
@ -410,7 +410,7 @@ test.describe('Command bar tests', () => {
|
||||
currentArgValue: '',
|
||||
headerArguments: {
|
||||
Method: '',
|
||||
Name: 'test',
|
||||
Name: 'main.kcl',
|
||||
Code: '1 line',
|
||||
},
|
||||
highlightedHeaderArg: 'method',
|
||||
@ -421,7 +421,7 @@ test.describe('Command bar tests', () => {
|
||||
commandName: 'Import file from URL',
|
||||
headerArguments: {
|
||||
Method: 'New project',
|
||||
Name: 'test',
|
||||
Name: 'main.kcl',
|
||||
Code: '1 line',
|
||||
},
|
||||
})
|
||||
@ -474,7 +474,7 @@ test.describe('Command bar tests', () => {
|
||||
currentArgValue: '',
|
||||
headerArguments: {
|
||||
Method: '',
|
||||
Name: 'test',
|
||||
Name: 'main.kcl',
|
||||
Code: '1 line',
|
||||
},
|
||||
highlightedHeaderArg: 'method',
|
||||
@ -487,7 +487,7 @@ test.describe('Command bar tests', () => {
|
||||
currentArgValue: '',
|
||||
headerArguments: {
|
||||
Method: 'Existing project',
|
||||
Name: 'test',
|
||||
Name: 'main.kcl',
|
||||
ProjectName: '',
|
||||
Code: '1 line',
|
||||
},
|
||||
@ -500,7 +500,7 @@ test.describe('Command bar tests', () => {
|
||||
headerArguments: {
|
||||
Method: 'Existing project',
|
||||
ProjectName: 'testProjectDir',
|
||||
Name: 'test',
|
||||
Name: 'main.kcl',
|
||||
Code: '1 line',
|
||||
},
|
||||
})
|
||||
@ -510,7 +510,7 @@ test.describe('Command bar tests', () => {
|
||||
await test.step(`Ensure we created the project and are in the modeling scene`, async () => {
|
||||
await editor.expectEditor.toContain('extrusionDistance = 12')
|
||||
await toolbar.openPane('files')
|
||||
await toolbar.expectFileTreeState(['main.kcl', 'test.kcl'])
|
||||
await toolbar.expectFileTreeState(['main-1.kcl', 'main.kcl'])
|
||||
})
|
||||
})
|
||||
|
||||
|
@ -773,12 +773,12 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
|
||||
)
|
||||
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
|
||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||
'2x2x2-cube.kcl'
|
||||
'main.kcl'
|
||||
)
|
||||
|
||||
await u.openFilePanel()
|
||||
await expect(
|
||||
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
|
||||
page.getByTestId('file-tree-item').getByText('main.kcl')
|
||||
).toBeVisible()
|
||||
}
|
||||
)
|
||||
@ -913,7 +913,7 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
|
||||
)
|
||||
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
|
||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||
'2x2x2-cube.kcl'
|
||||
'main.kcl'
|
||||
)
|
||||
|
||||
await page.getByRole('button', { name: 'Reject' }).click()
|
||||
@ -961,7 +961,7 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
|
||||
)
|
||||
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
|
||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||
'2x2x2-cube.kcl'
|
||||
'main.kcl'
|
||||
)
|
||||
}
|
||||
)
|
||||
@ -1213,18 +1213,14 @@ test.describe('Mocked Text-to-CAD API tests', { tag: ['@skipWin'] }, () => {
|
||||
)
|
||||
await expect(page.getByTestId('app-header-file-name')).toBeVisible()
|
||||
await expect(page.getByTestId('app-header-file-name')).toContainText(
|
||||
'2x2x2-cube.kcl'
|
||||
'main.kcl'
|
||||
)
|
||||
|
||||
// Check file is created
|
||||
await u.openFilePanel()
|
||||
await expect(
|
||||
page.getByTestId('file-tree-item').getByText('2x2x2-cube.kcl')
|
||||
).toBeVisible()
|
||||
|
||||
await expect(
|
||||
page.getByTestId('file-tree-item').getByText('main.kcl')
|
||||
).not.toBeVisible()
|
||||
).toBeVisible()
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -5,11 +5,14 @@ import { useNetworkContext } from '@src/hooks/useNetworkContext'
|
||||
import { EngineConnectionStateType } from '@src/lang/std/engineConnection'
|
||||
import { base64ToString } from '@src/lib/base64'
|
||||
import type { ProjectsCommandSchema } from '@src/lib/commandBarConfigs/projectsCommandConfig'
|
||||
import { CREATE_FILE_URL_PARAM, DEFAULT_FILE_NAME } from '@src/lib/constants'
|
||||
import {
|
||||
CREATE_FILE_URL_PARAM,
|
||||
DEFAULT_FILE_NAME,
|
||||
PROJECT_ENTRYPOINT,
|
||||
} from '@src/lib/constants'
|
||||
import { isDesktop } from '@src/lib/isDesktop'
|
||||
import type { FileLinkParams } from '@src/lib/links'
|
||||
import { PATHS } from '@src/lib/paths'
|
||||
import { useSettings } from '@src/lib/singletons'
|
||||
|
||||
// For initializing the command arguments, we actually want `method` to be undefined
|
||||
// so that we don't skip it in the command palette.
|
||||
@ -32,7 +35,6 @@ export function useCreateFileLinkQuery(
|
||||
const { immediateState } = useNetworkContext()
|
||||
const { pathname } = useLocation()
|
||||
const [searchParams] = useSearchParams()
|
||||
const settings = useSettings()
|
||||
|
||||
useEffect(() => {
|
||||
const isHome = pathname === PATHS.HOME
|
||||
@ -53,13 +55,7 @@ export function useCreateFileLinkQuery(
|
||||
}
|
||||
|
||||
const argDefaultValues: CreateFileSchemaMethodOptional = {
|
||||
name: params.name
|
||||
? isDesktop()
|
||||
? params.name.replace('.kcl', '')
|
||||
: params.name
|
||||
: isDesktop()
|
||||
? settings.projects.defaultProjectName.current
|
||||
: DEFAULT_FILE_NAME,
|
||||
name: PROJECT_ENTRYPOINT,
|
||||
code: params.code || '',
|
||||
method: isDesktop() ? undefined : 'existingProject',
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import {
|
||||
kclSamplesManifestWithNoMultipleFiles,
|
||||
} from '@src/lib/kclSamples'
|
||||
import { getUniqueProjectName } from '@src/lib/desktopFS'
|
||||
import { IS_ML_EXPERIMENTAL } from '@src/lib/constants'
|
||||
import { IS_ML_EXPERIMENTAL, PROJECT_ENTRYPOINT } from '@src/lib/constants'
|
||||
import toast from 'react-hot-toast'
|
||||
import { reportRejection } from '@src/lib/trap'
|
||||
import { relevantFileExtensions } from '@src/lang/wasmUtils'
|
||||
@ -22,11 +22,13 @@ function onSubmitKCLSampleCreation({
|
||||
kclSample,
|
||||
uniqueNameIfNeeded,
|
||||
systemIOActor,
|
||||
isProjectNew,
|
||||
}: {
|
||||
sample: any
|
||||
kclSample: ReturnType<typeof findKclSample>
|
||||
uniqueNameIfNeeded: any
|
||||
systemIOActor: ActorRefFrom<typeof systemIOMachine>
|
||||
isProjectNew: boolean
|
||||
}) {
|
||||
if (!kclSample) {
|
||||
toast.error('The command could not be submitted, unable to find Zoo sample')
|
||||
@ -72,11 +74,15 @@ function onSubmitKCLSampleCreation({
|
||||
* Navigates to the single file that could be renamed on disk for duplicates
|
||||
*/
|
||||
const folderNameBecomesKCLFileName = projectPathPart + FILE_EXT
|
||||
// If the project is new create the single file as main.kcl
|
||||
const requestedFileNameWithExtension = isProjectNew
|
||||
? PROJECT_ENTRYPOINT
|
||||
: folderNameBecomesKCLFileName
|
||||
systemIOActor.send({
|
||||
type: SystemIOMachineEvents.importFileFromURL,
|
||||
data: {
|
||||
requestedProjectName: requestedFiles[0].requestedProjectName,
|
||||
requestedFileNameWithExtension: folderNameBecomesKCLFileName,
|
||||
requestedFileNameWithExtension: requestedFileNameWithExtension,
|
||||
requestedCode: requestedFiles[0].requestedCode,
|
||||
},
|
||||
})
|
||||
@ -206,6 +212,7 @@ export function createApplicationCommands({
|
||||
kclSample,
|
||||
uniqueNameIfNeeded,
|
||||
systemIOActor,
|
||||
isProjectNew,
|
||||
})
|
||||
} else if (data.source === 'local' && data.path) {
|
||||
const clonePath = data.path
|
||||
@ -396,6 +403,7 @@ export function createApplicationCommands({
|
||||
kclSample,
|
||||
uniqueNameIfNeeded,
|
||||
systemIOActor,
|
||||
isProjectNew: true,
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
ToastTextToCadError,
|
||||
ToastTextToCadSuccess,
|
||||
} from '@src/components/ToastTextToCad'
|
||||
import { FILE_EXT } from '@src/lib/constants'
|
||||
import { FILE_EXT, PROJECT_ENTRYPOINT } from '@src/lib/constants'
|
||||
import crossPlatformFetch from '@src/lib/crossPlatformFetch'
|
||||
import { getNextFileName } from '@src/lib/desktopFS'
|
||||
import { isDesktop } from '@src/lib/isDesktop'
|
||||
@ -196,12 +196,18 @@ export async function submitAndAwaitTextToKclSystemIO({
|
||||
}
|
||||
|
||||
const TRUNCATED_PROMPT_LENGTH = 24
|
||||
// Only add the prompt name if it is a preexisting project
|
||||
newFileName = `${value.prompt
|
||||
.slice(0, TRUNCATED_PROMPT_LENGTH)
|
||||
.replace(/\s/gi, '-')
|
||||
.replace(/\W/gi, '-')
|
||||
.toLowerCase()}${FILE_EXT}`
|
||||
|
||||
// If the project is new generate a main.kcl
|
||||
if (isProjectNew) {
|
||||
newFileName = PROJECT_ENTRYPOINT
|
||||
}
|
||||
|
||||
if (isDesktop()) {
|
||||
// We have to preemptively run our unique file name logic,
|
||||
// so that we can pass the unique file name to the toast,
|
||||
|
Reference in New Issue
Block a user