Always give new files and dirs a new index if their names are taken (#3460)

* Add actual support for makeUnique parameter

* Add uniqueness logic to dirs, make text-to-cad receive unique filename

* No longer need makeUnique flag, it's always on

* fmt

* Don't show toast when name hasn't changed during a rename

* fmt

* Get "interact with many" text-to-cad test passing again

* Get "engine fails export" back to reliably green

* Maybe more stable click target for text-to-cad test

* Make "export is already going" test moderately more reliable

* Mark "export is already going" as fixme

* Undo that fixme thing I take it back
This commit is contained in:
Frank Noirot
2024-08-15 14:24:27 -04:00
committed by GitHub
parent 55a3e2a4ed
commit 545e610bbc
10 changed files with 240 additions and 99 deletions

View File

@ -21,11 +21,13 @@ import {
rename,
create,
writeTextFile,
exists,
} from '@tauri-apps/plugin-fs'
import { isTauri } from 'lib/isTauri'
import { join, sep } from '@tauri-apps/api/path'
import { DEFAULT_FILE_NAME, FILE_EXT } from 'lib/constants'
import { getProjectInfo } from 'lib/tauri'
import { getNextDirName, getNextFileName } from 'lib/tauriFS'
type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
@ -105,14 +107,20 @@ export const FileMachineProvider = ({
let createdPath: string
if (event.data.makeDir) {
createdPath = await join(context.selectedDirectory.path, createdName)
let { name, path } = await getNextDirName({
entryName: createdName,
baseDir: context.selectedDirectory.path,
})
createdName = name
createdPath = path
await mkdir(createdPath)
} else {
createdPath =
context.selectedDirectory.path +
sep() +
createdName +
(createdName.endsWith(FILE_EXT) ? '' : FILE_EXT)
const { name, path } = await getNextFileName({
entryName: createdName,
baseDir: context.selectedDirectory.path,
})
createdName = name
createdPath = path
await create(createdPath)
if (event.data.content) {
await writeTextFile(createdPath, event.data.content)
@ -129,14 +137,20 @@ export const FileMachineProvider = ({
let createdPath: string
if (event.data.makeDir) {
createdPath = await join(context.selectedDirectory.path, createdName)
let { name, path } = await getNextDirName({
entryName: createdName,
baseDir: context.selectedDirectory.path,
})
createdName = name
createdPath = path
await mkdir(createdPath)
} else {
createdPath =
context.selectedDirectory.path +
sep() +
createdName +
(createdName.endsWith(FILE_EXT) ? '' : FILE_EXT)
const { name, path } = await getNextFileName({
entryName: createdName,
baseDir: context.selectedDirectory.path,
})
createdName = name
createdPath = path
await create(createdPath)
if (event.data.content) {
await writeTextFile(createdPath, event.data.content)

View File

@ -382,11 +382,17 @@ export const FileTreeMenu = () => {
const { send } = useFileContext()
async function createFile() {
send({ type: 'Create file', data: { name: '', makeDir: false } })
send({
type: 'Create file',
data: { name: '', makeDir: false },
})
}
async function createFolder() {
send({ type: 'Create file', data: { name: '', makeDir: true } })
send({
type: 'Create file',
data: { name: '', makeDir: true },
})
}
useHotkeyWrapper(['meta + n'], createFile)

View File

@ -85,6 +85,7 @@ import {
} from 'lang/std/engineConnection'
import { submitAndAwaitTextToKcl } from 'lib/textToCad'
import { useFileContext } from 'hooks/useFileContext'
import { PLAYWRIGHT_MOCK_EXPORT_DURATION } from 'lib/constants'
type MachineContext<T extends AnyStateMachine> = {
state: StateFrom<T>
@ -393,10 +394,24 @@ export const ModelingMachineProvider = ({
selection: { type: 'default_scene' },
}
const mockExportDuration = window.localStorage.getItem(
PLAYWRIGHT_MOCK_EXPORT_DURATION
)
console.log('mockExportDuration', mockExportDuration)
// Artificially delay the export in playwright tests
toast.promise(
exportFromEngine({
format: format,
}),
Promise.all([
exportFromEngine({
format: format,
}),
mockExportDuration
? new Promise((resolve) =>
setTimeout(resolve, Number(mockExportDuration))
)
: Promise.resolve(),
]),
{
loading: 'Starting print...',
success: 'Started print successfully',