Clear generated name when enabling auto-name tour

Co-authored-by: Orca <help@stably.ai>
This commit is contained in:
brennanb2025
2026-05-31 22:28:09 -07:00
co-authored by Orca
parent bf1b88577c
commit cc801d8f33
4 changed files with 76 additions and 1 deletions
@@ -0,0 +1,36 @@
import { describe, expect, it, vi } from 'vitest'
import { toggleAutoRenameBranchFromWork } from './ContextualTourControl'
import { CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT } from './contextual-tour-composer-events'
describe('toggleAutoRenameBranchFromWork', () => {
it('clears the generated workspace name when enabling first-message auto-name', () => {
const updateSettings = vi.fn()
const dispatchEvent = vi.fn()
toggleAutoRenameBranchFromWork({
enabled: false,
updateSettings,
dispatchEvent
})
expect(updateSettings).toHaveBeenCalledWith({ autoRenameBranchFromWork: true })
expect(dispatchEvent).toHaveBeenCalledTimes(1)
expect(dispatchEvent.mock.calls[0]?.[0]).toMatchObject({
type: CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT
})
})
it('does not clear the workspace name when disabling first-message auto-name', () => {
const updateSettings = vi.fn()
const dispatchEvent = vi.fn()
toggleAutoRenameBranchFromWork({
enabled: true,
updateSettings,
dispatchEvent
})
expect(updateSettings).toHaveBeenCalledWith({ autoRenameBranchFromWork: false })
expect(dispatchEvent).not.toHaveBeenCalled()
})
})
@@ -2,6 +2,7 @@ import type { JSX } from 'react'
import { cn } from '@/lib/utils'
import { useAppStore } from '@/store'
import type { ContextualTourStepControl } from '../../../../shared/contextual-tours'
import { CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT } from './contextual-tour-composer-events'
export function ContextualTourControl({
control
@@ -14,6 +15,18 @@ export function ContextualTourControl({
}
}
export function toggleAutoRenameBranchFromWork(args: {
enabled: boolean
updateSettings: (settings: { autoRenameBranchFromWork: boolean }) => void | Promise<unknown>
dispatchEvent: (event: Event) => void
}): void {
const nextEnabled = !args.enabled
void args.updateSettings({ autoRenameBranchFromWork: nextEnabled })
if (nextEnabled) {
args.dispatchEvent(new Event(CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT))
}
}
function AutoRenameBranchFromWorkControl(): JSX.Element {
const enabled = useAppStore((s) => s.settings?.autoRenameBranchFromWork === true)
const updateSettings = useAppStore((s) => s.updateSettings)
@@ -33,7 +46,11 @@ function AutoRenameBranchFromWorkControl(): JSX.Element {
aria-checked={enabled}
aria-label="Auto-name workspace from first agent message"
onClick={() => {
void updateSettings({ autoRenameBranchFromWork: !enabled })
toggleAutoRenameBranchFromWork({
enabled,
updateSettings,
dispatchEvent: (event) => window.dispatchEvent(event)
})
}}
className={cn(
'relative inline-flex h-5 w-9 shrink-0 cursor-pointer items-center rounded-full border border-transparent transition-colors',
@@ -0,0 +1,2 @@
export const CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT =
'orca:contextual-tour-enable-auto-workspace-name'
@@ -65,6 +65,7 @@ import {
} from '@/lib/new-workspace-ssh-gate'
import { getSuggestedCreatureName } from '@/components/sidebar/worktree-name-suggestions'
import type { SmartWorkspaceNameSelection } from '@/components/new-workspace/SmartWorkspaceNameField'
import { CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT } from '@/components/contextual-tours/contextual-tour-composer-events'
import { ensureHooksConfirmed } from '@/lib/ensure-hooks-confirmed'
import { normalizeSparseDirectoryLines, sparseDirectoriesMatch } from '@/lib/sparse-paths'
import { joinPath } from '@/lib/path'
@@ -447,6 +448,8 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
const lastAutoNameRef = useRef<string>(
persistDraft ? (newWorkspaceDraft?.name ?? initialName) : initialName
)
const nameRef = useRef<string>(name)
nameRef.current = name
const branchAutoNameRef = useRef<string>('')
// Why: tracks the note value we auto-prefilled from a Start-from PR pick, so
// a subsequent PR change can replace it without clobbering user-typed text.
@@ -457,6 +460,23 @@ export function useComposerState(options: UseComposerStateOptions): UseComposerS
useEffect(() => {
noteRef.current = note
}, [note])
useEffect(() => {
const clearAutoManagedName = (): void => {
if (nameRef.current === lastAutoNameRef.current) {
setName('')
lastAutoNameRef.current = ''
setCreateError(null)
}
}
window.addEventListener(CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT, clearAutoManagedName)
return () => {
window.removeEventListener(
CONTEXTUAL_TOUR_ENABLE_AUTO_WORKSPACE_NAME_EVENT,
clearAutoManagedName
)
}
}, [])
const composerRef = useRef<HTMLDivElement | null>(null)
const promptTextareaRef = useRef<HTMLTextAreaElement | null>(null)
const nameInputRef = useRef<HTMLInputElement | null>(null)