Remove project.toml fetch during Open Sample (#5203)
* Fix units in tests * Don't default to mm * Last fix * FIx lint * Remove project.toml fetching from samples
This commit is contained in:
@ -69,7 +69,6 @@ test.describe('Testing in-app sample loading', () => {
|
|||||||
await confirmButton.click()
|
await confirmButton.click()
|
||||||
|
|
||||||
await editor.expectEditor.toContain('// ' + newSample.title)
|
await editor.expectEditor.toContain('// ' + newSample.title)
|
||||||
await expect(unitsToast('in')).toBeVisible()
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -158,7 +157,6 @@ test.describe('Testing in-app sample loading', () => {
|
|||||||
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
await editor.expectEditor.toContain('// ' + sampleOne.title)
|
||||||
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
|
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
|
||||||
await expect(projectMenuButton).toContainText(sampleOne.file)
|
await expect(projectMenuButton).toContainText(sampleOne.file)
|
||||||
await expect(unitsToast('in')).toBeVisible()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
await test.step(`Now overwrite the current file`, async () => {
|
await test.step(`Now overwrite the current file`, async () => {
|
||||||
@ -188,7 +186,6 @@ test.describe('Testing in-app sample loading', () => {
|
|||||||
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
|
await expect(newlyCreatedFile(sampleOne.file)).toBeVisible()
|
||||||
await expect(newlyCreatedFile(sampleTwo.file)).not.toBeVisible()
|
await expect(newlyCreatedFile(sampleTwo.file)).not.toBeVisible()
|
||||||
await expect(projectMenuButton).toContainText(sampleOne.file)
|
await expect(projectMenuButton).toContainText(sampleOne.file)
|
||||||
await expect(unitsToast('mm')).toBeVisible()
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
import { CommandBarOverwriteWarning } from 'components/CommandBarOverwriteWarning'
|
import { CommandBarOverwriteWarning } from 'components/CommandBarOverwriteWarning'
|
||||||
import { Command, CommandArgumentOption } from './commandTypes'
|
import { Command, CommandArgumentOption } from './commandTypes'
|
||||||
import { codeManager, kclManager } from './singletons'
|
import { kclManager } from './singletons'
|
||||||
import { isDesktop } from './isDesktop'
|
import { isDesktop } from './isDesktop'
|
||||||
import { FILE_EXT, PROJECT_SETTINGS_FILE_NAME } from './constants'
|
import { FILE_EXT } from './constants'
|
||||||
import { UnitLength_type } from '@kittycad/lib/dist/types/src/models'
|
import { UnitLength_type } from '@kittycad/lib/dist/types/src/models'
|
||||||
import { parseProjectSettings } from 'lang/wasm'
|
import { reportRejection } from './trap'
|
||||||
import { err, reportRejection } from './trap'
|
|
||||||
import { projectConfigurationToSettingsPayload } from './settings/settingsUtils'
|
|
||||||
import { copyFileShareLink } from './links'
|
|
||||||
import { IndexLoaderData } from './types'
|
import { IndexLoaderData } from './types'
|
||||||
|
|
||||||
interface OnSubmitProps {
|
interface OnSubmitProps {
|
||||||
@ -68,23 +65,9 @@ export function kclCommands(commandProps: KclCommandConfig): Command[] {
|
|||||||
const sampleCodeUrl = `https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/${encodeURIComponent(
|
const sampleCodeUrl = `https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/${encodeURIComponent(
|
||||||
projectPathPart
|
projectPathPart
|
||||||
)}/${encodeURIComponent(primaryKclFile)}`
|
)}/${encodeURIComponent(primaryKclFile)}`
|
||||||
const sampleSettingsFileUrl = `https://raw.githubusercontent.com/KittyCAD/kcl-samples/main/${encodeURIComponent(
|
|
||||||
projectPathPart
|
|
||||||
)}/${PROJECT_SETTINGS_FILE_NAME}`
|
|
||||||
|
|
||||||
Promise.allSettled([fetch(sampleCodeUrl), fetch(sampleSettingsFileUrl)])
|
fetch(sampleCodeUrl)
|
||||||
.then((results) => {
|
.then(async (codeResponse): Promise<OnSubmitProps> => {
|
||||||
const a =
|
|
||||||
'value' in results[0] ? results[0].value : results[0].reason
|
|
||||||
const b =
|
|
||||||
'value' in results[1] ? results[1].value : results[1].reason
|
|
||||||
return [a, b]
|
|
||||||
})
|
|
||||||
.then(
|
|
||||||
async ([
|
|
||||||
codeResponse,
|
|
||||||
settingsResponse,
|
|
||||||
]): Promise<OnSubmitProps> => {
|
|
||||||
if (!codeResponse.ok) {
|
if (!codeResponse.ok) {
|
||||||
console.error(
|
console.error(
|
||||||
'Failed to fetch sample code:',
|
'Failed to fetch sample code:',
|
||||||
@ -93,31 +76,12 @@ export function kclCommands(commandProps: KclCommandConfig): Command[] {
|
|||||||
return Promise.reject(new Error('Failed to fetch sample code'))
|
return Promise.reject(new Error('Failed to fetch sample code'))
|
||||||
}
|
}
|
||||||
const code = await codeResponse.text()
|
const code = await codeResponse.text()
|
||||||
|
|
||||||
// It's possible that a sample doesn't have a project.toml
|
|
||||||
// associated with it.
|
|
||||||
let projectSettingsPayload: ReturnType<
|
|
||||||
typeof projectConfigurationToSettingsPayload
|
|
||||||
> = {}
|
|
||||||
if (settingsResponse.ok) {
|
|
||||||
const parsedProjectSettings = parseProjectSettings(
|
|
||||||
await settingsResponse.text()
|
|
||||||
)
|
|
||||||
if (!err(parsedProjectSettings)) {
|
|
||||||
projectSettingsPayload =
|
|
||||||
projectConfigurationToSettingsPayload(parsedProjectSettings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sampleName: data.sample.split('/')[0] + FILE_EXT,
|
sampleName: data.sample.split('/')[0] + FILE_EXT,
|
||||||
code,
|
code,
|
||||||
method: data.method,
|
method: data.method,
|
||||||
sampleUnits:
|
|
||||||
projectSettingsPayload.modeling?.defaultUnit || 'mm',
|
|
||||||
}
|
}
|
||||||
}
|
})
|
||||||
)
|
|
||||||
.then((props) => {
|
.then((props) => {
|
||||||
if (props?.code) {
|
if (props?.code) {
|
||||||
commandProps.specialPropsForSampleCommand
|
commandProps.specialPropsForSampleCommand
|
||||||
|
Reference in New Issue
Block a user