Add uniqueness check to "Create project" command (#5100)
* Add failing playwright test * Make create generate a unique name if the given one collides * Add a new consolidated getUniqueProjectName function with tests * Use getUniqueProjectName * Replace "New project" button text with "Create project" cc @pierremtb * Extend the e2e test to show the incrementing behavior cc @lf94
This commit is contained in:
@ -134,6 +134,7 @@ function CommandArgOptionInput({
|
||||
</label>
|
||||
<Combobox.Input
|
||||
id="option-input"
|
||||
data-testid="cmd-bar-arg-value"
|
||||
ref={inputRef}
|
||||
onChange={(event) =>
|
||||
!event.target.disabled && setQuery(event.target.value)
|
||||
|
@ -52,6 +52,7 @@ function CommandComboBox({
|
||||
className="w-5 h-5 bg-primary/10 dark:bg-primary text-primary dark:text-inherit"
|
||||
/>
|
||||
<Combobox.Input
|
||||
data-testid="cmd-bar-search"
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
className="w-full bg-transparent focus:outline-none selection:bg-primary/20 dark:selection:bg-primary/40 dark:focus:outline-none"
|
||||
onKeyDown={(event) => {
|
||||
@ -85,6 +86,7 @@ function CommandComboBox({
|
||||
value={option}
|
||||
className="flex items-center gap-4 px-4 py-1.5 first:mt-2 last:mb-2 ui-active:bg-primary/10 dark:ui-active:bg-chalkboard-90 ui-disabled:!text-chalkboard-50"
|
||||
disabled={optionIsDisabled(option)}
|
||||
data-testid={`cmd-bar-option`}
|
||||
>
|
||||
{'icon' in option && option.icon && (
|
||||
<CustomIcon name={option.icon} className="w-5 h-5" />
|
||||
|
@ -18,6 +18,7 @@ import {
|
||||
getNextProjectIndex,
|
||||
interpolateProjectNameWithIndex,
|
||||
doesProjectNameNeedInterpolated,
|
||||
getUniqueProjectName,
|
||||
} from 'lib/desktopFS'
|
||||
import { useSettingsAuthContext } from 'hooks/useSettingsAuthContext'
|
||||
import useStateMachineCommands from 'hooks/useStateMachineCommands'
|
||||
@ -195,15 +196,11 @@ const ProjectsContextDesktop = ({
|
||||
: settings.projects.defaultProjectName.current
|
||||
).trim()
|
||||
|
||||
if (doesProjectNameNeedInterpolated(name)) {
|
||||
const nextIndex = getNextProjectIndex(name, input.projects)
|
||||
name = interpolateProjectNameWithIndex(name, nextIndex)
|
||||
}
|
||||
|
||||
await createNewProjectDirectory(name)
|
||||
const uniqueName = getUniqueProjectName(name, input.projects)
|
||||
await createNewProjectDirectory(uniqueName)
|
||||
|
||||
return {
|
||||
message: `Successfully created "${name}"`,
|
||||
message: `Successfully created "${uniqueName}"`,
|
||||
name,
|
||||
}
|
||||
}),
|
||||
|
Reference in New Issue
Block a user