Files
archived-orca/src/renderer/src/components/NewWorkspaceComposerCard.tsx
T
JinjingandOrca 868b024dbe Fix localized strings getting stuck on language switch (#5150)
* Fix localized strings getting stuck on language switch

Replace static module-level translation evaluations with property
getters and i18n hooks to ensure UI elements update dynamically when
the active language changes.

- Convert static configuration properties to dynamic getters.
- Call `useTranslation()` to trigger re-renders on language updates.
- Recreate Tiptap editor extensions when the active language changes
  to refresh frozen placeholder configurations.

* Evaluate localized strings dynamically in static UI structures

- Use ES6 getters with `translate()` in static object maps (such as SSH
  connection status, usage ranges, and feature tour copy) to evaluate
  strings on demand when the language changes.
- Add the `useTranslation()` hook to `LinearIssueMarkdownToolbar` so it
  subscribes directly to translation updates.
- Extract markdown slash command primitives to a separate file to keep
  catalog configuration clean.

---------

Co-authored-by: Orca <help@stably.ai>
2026-06-11 19:45:50 -07:00

897 lines
36 KiB
TypeScript

/* eslint-disable max-lines -- Why: this component intentionally keeps the full
composer card markup together so the inline and modal variants share one UI
surface without splitting the controlled form into hard-to-follow fragments. */
import React from 'react'
import { useTranslation } from 'react-i18next'
import {
AlertTriangle,
Check,
ChevronDown,
CornerDownLeft,
FolderPlus,
LoaderCircle,
PlugZap,
Settings2
} from 'lucide-react'
import { Button } from '@/components/ui/button'
import { Tooltip, TooltipContent, TooltipTrigger } from '@/components/ui/tooltip'
import RepoCombobox from '@/components/repo/RepoCombobox'
import AgentCombobox from '@/components/agent/AgentCombobox'
import { getAgentCatalog } from '@/lib/agent-catalog'
import { useAppStore } from '@/store'
import { cn } from '@/lib/utils'
import { WORKSPACE_FILE_PATH_MIME } from '@/lib/workspace-file-drag'
import { getScreenSubmitModifierLabel } from '@/lib/screen-submit-shortcut'
import { useContextualTour } from '@/components/contextual-tours/use-contextual-tour'
import { filterEnabledTuiAgents } from '../../../shared/tui-agent-selection'
import type {
GitHubWorkItem,
GitLabWorkItem,
LinearIssue,
SparsePreset,
TuiAgent
} from '../../../shared/types'
import SparseCheckoutPresetSelect from '@/components/sparse/SparseCheckoutPresetSelect'
import SmartWorkspaceNameField, {
type SmartWorkspaceNameSelection
} from '@/components/new-workspace/SmartWorkspaceNameField'
import type { SetupConfig } from '@/lib/new-workspace'
import type { WorkspaceCreateErrorDisplay } from '@/lib/workspace-create-error-format'
import type { SshConnectionStatus } from '../../../shared/ssh-types'
import { translate } from '@/i18n/i18n'
type RepoOption = React.ComponentProps<typeof RepoCombobox>['repos'][number]
type NewWorkspaceComposerCardProps = {
contextualTourSource?: string
containerClassName?: string
composerRef?: React.RefObject<HTMLDivElement | null>
onComposerNodeChange?: (node: HTMLDivElement | null) => void
nameInputRef?: React.RefObject<HTMLInputElement | null>
quickAgent: TuiAgent | null
onQuickAgentChange: (agent: TuiAgent | null) => void
eligibleRepos: RepoOption[]
repoId: string
selectedRepoIsGit: boolean
onRepoChange: (value: string) => void
primaryActionLabel: string
projectLabel?: string
projectPlaceholder?: string
emptyProjectMessage?: string
showAddProjectButton?: boolean
name: string
onNameValueChange: (value: string) => void
onSmartGitHubItemSelect: (item: GitHubWorkItem) => void
onSmartGitLabItemSelect: (item: GitLabWorkItem) => void
onSmartBranchSelect: (refName: string, localBranchName: string) => void
onSmartLinearIssueSelect: (issue: LinearIssue) => void
smartNameSelection: SmartWorkspaceNameSelection | null
onClearSmartNameSelection: () => void
/** Advisory shown under the name field when a fork PR can't accept maintainer pushes. */
forkPushWarning: string | null
detectedAgentIds: Set<TuiAgent> | null
onOpenAgentSettings: () => void
advancedOpen: boolean
onToggleAdvanced: () => void
createDisabled: boolean
projectError: string | null
creating: boolean
onCreate: () => void
note: string
onNoteChange: (value: string) => void
setupConfig: SetupConfig | null
requiresExplicitSetupChoice: boolean
setupDecision: 'run' | 'skip' | null
onSetupDecisionChange: (value: 'run' | 'skip') => void
shouldWaitForSetupCheck: boolean
resolvedSetupDecision: 'run' | 'skip' | null
createError: WorkspaceCreateErrorDisplay | null
selectedRepoConnectionId: string | null
selectedRepoSshStatus: SshConnectionStatus | null
selectedRepoRequiresConnection: boolean
selectedRepoConnectInProgress: boolean
onConnectSelectedRepo: () => Promise<void>
branchesEnabled?: boolean
setupControlsEnabled?: boolean
canUseSparseCheckout: boolean
sparsePresets: SparsePreset[]
sparseSelectedPresetId: string | null
onSparseSelectPreset: (preset: SparsePreset | null) => void
sparseControlsEnabled?: boolean
}
const SSH_STATUS_LABELS: Partial<Record<SshConnectionStatus, string>> = {
get disconnected() {
return translate(
'auto.components.NewWorkspaceComposerCard.sshNotConnected',
'SSH not connected'
)
},
get connecting() {
return translate('auto.components.NewWorkspaceComposerCard.connectingSsh', 'Connecting SSH...')
},
get 'auth-failed'() {
return translate(
'auto.components.NewWorkspaceComposerCard.sshAuthenticationFailed',
'SSH authentication failed'
)
},
get 'deploying-relay'() {
return translate(
'auto.components.NewWorkspaceComposerCard.preparingSshConnection',
'Preparing SSH connection...'
)
},
get connected() {
return translate('auto.components.NewWorkspaceComposerCard.connected', 'Connected')
},
get reconnecting() {
return translate(
'auto.components.NewWorkspaceComposerCard.reconnectingSsh',
'Reconnecting SSH...'
)
},
get 'reconnection-failed'() {
return translate(
'auto.components.NewWorkspaceComposerCard.sshReconnectionFailed',
'SSH reconnection failed'
)
},
get error() {
return translate('auto.components.NewWorkspaceComposerCard.a239038146', 'SSH connection error')
}
}
function getSshStatusLabel(status: SshConnectionStatus): string {
return SSH_STATUS_LABELS[status] ?? status
}
function SetupCommandPreview({
setupConfig,
headerAction
}: {
setupConfig: SetupConfig
headerAction?: React.ReactNode
}): React.JSX.Element {
if (setupConfig.source === 'yaml') {
return (
<div className="rounded-2xl border border-border/60 bg-muted/40 shadow-inner">
<div className="flex items-center justify-between gap-3 border-b border-border/60 px-4 py-2.5">
<div className="font-mono text-[11px] text-muted-foreground">
{translate('auto.components.NewWorkspaceComposerCard.23bb365554', 'orca.yaml')}
</div>
{headerAction}
</div>
{/* Why: long orca.yaml scripts must not grow the create dialog past the viewport. */}
<pre className="max-h-48 overflow-auto whitespace-pre-wrap break-words px-4 py-3 font-mono text-[12px] leading-5 text-emerald-700 scrollbar-sleek dark:text-emerald-300/95">
{setupConfig.command}
</pre>
</div>
)
}
return (
<div className="rounded-2xl border border-border/60 bg-muted/35 px-4 py-3 shadow-inner">
<div className="mb-2 flex items-center justify-between gap-3">
<div className="text-[11px] uppercase tracking-[0.18em] text-muted-foreground">
{setupConfig.source === 'both'
? translate(
'auto.components.NewWorkspaceComposerCard.e5db1b0419',
'Combined setup command'
)
: translate(
'auto.components.NewWorkspaceComposerCard.7711ad5122',
'Local setup command'
)}
</div>
{headerAction}
</div>
<pre className="max-h-48 overflow-auto whitespace-pre-wrap break-words font-mono text-[12px] leading-5 text-foreground scrollbar-sleek">
{setupConfig.command}
</pre>
</div>
)
}
function useComposerFileDragOver(): {
isFileDragOver: boolean
dragHandlers: {
onDragEnter: (event: React.DragEvent<HTMLDivElement>) => void
onDragLeave: (event: React.DragEvent<HTMLDivElement>) => void
}
} {
const [isFileDragOver, setIsFileDragOver] = React.useState(false)
const dragCounterRef = React.useRef(0)
const reset = React.useCallback(() => {
dragCounterRef.current = 0
setIsFileDragOver(false)
}, [])
const onDragEnter = React.useCallback((event: React.DragEvent<HTMLDivElement>): void => {
// Why: "Files" is the DataTransfer type the OS adds for native file drags;
// internal in-app drags must not trigger the
// attachment-drop highlight so they still route to their own handlers.
if (!event.dataTransfer.types.includes('Files')) {
return
}
if (event.dataTransfer.types.includes(WORKSPACE_FILE_PATH_MIME)) {
return
}
dragCounterRef.current += 1
setIsFileDragOver(true)
}, [])
const onDragLeave = React.useCallback(
(event: React.DragEvent<HTMLDivElement>): void => {
if (!event.dataTransfer.types.includes('Files')) {
return
}
// Why: mirror the onDragEnter guard so internal in-app drags (which may
// carry both "Files" and the workspace path MIME type) don't decrement
// the counter when enter skipped incrementing it — otherwise the counter
// goes negative and the native-drag highlight state desyncs.
if (event.dataTransfer.types.includes(WORKSPACE_FILE_PATH_MIME)) {
return
}
dragCounterRef.current -= 1
if (dragCounterRef.current <= 0) {
reset()
}
},
[reset]
)
// Why: the preload bridge calls stopPropagation on native `drop` events so
// React's onDrop never fires on the composer card. Listen at the document
// level (also capture-phase) to reset the drag highlight whenever any drop
// or dragend occurs anywhere in the window.
React.useEffect(() => {
const handler = (): void => {
reset()
}
document.addEventListener('drop', handler, true)
document.addEventListener('dragend', handler, true)
return () => {
document.removeEventListener('drop', handler, true)
document.removeEventListener('dragend', handler, true)
}
}, [reset])
return {
isFileDragOver,
dragHandlers: { onDragEnter, onDragLeave }
}
}
export default function NewWorkspaceComposerCard({
contextualTourSource,
containerClassName,
composerRef,
onComposerNodeChange,
nameInputRef,
quickAgent,
onQuickAgentChange,
eligibleRepos,
repoId,
selectedRepoIsGit,
onRepoChange,
primaryActionLabel,
projectLabel,
projectPlaceholder,
emptyProjectMessage,
showAddProjectButton = true,
name,
onNameValueChange,
onSmartGitHubItemSelect,
onSmartGitLabItemSelect,
onSmartBranchSelect,
onSmartLinearIssueSelect,
smartNameSelection,
onClearSmartNameSelection,
forkPushWarning,
detectedAgentIds,
onOpenAgentSettings,
advancedOpen,
onToggleAdvanced,
createDisabled,
projectError,
creating,
onCreate,
note,
onNoteChange,
setupConfig,
requiresExplicitSetupChoice,
setupDecision,
onSetupDecisionChange,
shouldWaitForSetupCheck,
resolvedSetupDecision,
createError,
selectedRepoConnectionId,
selectedRepoSshStatus,
selectedRepoRequiresConnection,
selectedRepoConnectInProgress,
onConnectSelectedRepo,
branchesEnabled = true,
setupControlsEnabled = true,
canUseSparseCheckout,
sparsePresets,
sparseSelectedPresetId,
onSparseSelectPreset,
sparseControlsEnabled = true
}: NewWorkspaceComposerCardProps): React.JSX.Element {
// Why: this form uses the lightweight translate() helper directly; subscribe
// so an already-open create dialog repaints when the UI language changes.
useTranslation()
const { isFileDragOver, dragHandlers } = useComposerFileDragOver()
const openModal = useAppStore((s) => s.openModal)
const activeModal = useAppStore((s) => s.activeModal)
const defaultTuiAgent = useAppStore((s) => s.settings?.defaultTuiAgent ?? null)
const disabledTuiAgents = useAppStore((s) => s.settings?.disabledTuiAgents ?? [])
const updateSettings = useAppStore((s) => s.updateSettings)
const nameInputFocusFrameRef = React.useRef<number | null>(null)
const submitShortcutModifierLabel = getScreenSubmitModifierLabel()
const selectedRepoName = React.useMemo(() => {
const repo = eligibleRepos.find((candidate) => candidate.id === repoId)
return repo?.displayName ?? repo?.path ?? 'This project'
}, [eligibleRepos, repoId])
const sshStatusLabel = selectedRepoSshStatus
? getSshStatusLabel(selectedRepoSshStatus)
: translate('auto.components.NewWorkspaceComposerCard.notConnected', 'Not connected')
const connectButtonLabel =
selectedRepoSshStatus === 'disconnected' || selectedRepoSshStatus === null
? 'Connect'
: 'Reconnect'
const setupConfigLabel =
setupConfig?.kind === 'default-tabs'
? 'Default tab commands'
: setupConfig?.kind === 'setup-and-default-tabs'
? 'Setup and default tab commands'
: 'Setup script'
const setupRunLabel =
setupConfig?.kind === 'default-tabs'
? 'Run default tab commands'
: setupConfig?.kind === 'setup-and-default-tabs'
? 'Run setup and default tab commands'
: 'Run setup command'
const setupAskLabel =
setupConfig?.kind === 'default-tabs'
? 'Run default tab commands now?'
: setupConfig?.kind === 'setup-and-default-tabs'
? 'Run setup and default tab commands now?'
: 'Run setup now?'
const setupRunButtonLabel =
setupConfig?.kind === 'default-tabs'
? 'Run commands now'
: setupConfig?.kind === 'setup-and-default-tabs'
? 'Run commands now'
: 'Run setup now'
const setupSkipButtonLabel = setupConfig?.kind === 'setup' ? 'Skip for now' : 'Skip commands'
const handleSetDefaultAgent = React.useCallback(
(next: TuiAgent | 'blank' | null) => {
updateSettings({ defaultTuiAgent: next })
},
[updateSettings]
)
const cancelNameInputFocusFrame = React.useCallback((): void => {
if (nameInputFocusFrameRef.current === null) {
return
}
cancelAnimationFrame(nameInputFocusFrameRef.current)
nameInputFocusFrameRef.current = null
}, [])
const setComposerNode = React.useCallback(
(node: HTMLDivElement | null): void => {
// Why: the queued repo-picker focus is only valid while this composer exists.
if (!node) {
cancelNameInputFocusFrame()
}
if (composerRef) {
composerRef.current = node
}
onComposerNodeChange?.(node)
},
[cancelNameInputFocusFrame, composerRef, onComposerNodeChange]
)
const focusNameInput = React.useCallback(() => {
// Why: after the repo picker commits a choice, moving focus to the name
// field keeps the keyboard flow progressing through the form instead of
// trapping the user in the repo popover interaction.
cancelNameInputFocusFrame()
nameInputFocusFrameRef.current = requestAnimationFrame(() => {
nameInputFocusFrameRef.current = null
nameInputRef?.current?.focus()
})
}, [cancelNameInputFocusFrame, nameInputRef])
const visibleQuickAgents = React.useMemo(() => {
const enabledIds = new Set(
filterEnabledTuiAgents(
getAgentCatalog().map((agent) => agent.id),
disabledTuiAgents
)
)
return getAgentCatalog().filter(
(agent) =>
enabledIds.has(agent.id) && (detectedAgentIds === null || detectedAgentIds.has(agent.id))
)
}, [detectedAgentIds, disabledTuiAgents])
const handleAddRepo = React.useCallback((): void => {
openModal('add-repo')
}, [openModal])
const projectDescriptionId = React.useId()
useContextualTour(
'workspace-creation',
eligibleRepos.length > 0 && Boolean(repoId),
contextualTourSource ??
(activeModal === 'new-workspace-composer'
? 'workspace_creation_modal'
: 'workspace_creation_visible')
)
return (
<div
ref={setComposerNode}
// Why: preload classifies native OS file drops by the nearest
// `data-native-file-drop-target` marker in the composedPath. Tagging
// the composer root makes drops anywhere on the card route to the
// composer attachment handler instead of falling back to the default
// editor-open behavior.
data-native-file-drop-target="composer"
onDragEnter={dragHandlers.onDragEnter}
onDragLeave={dragHandlers.onDragLeave}
className={cn(
'grid min-w-0 gap-1 rounded-md transition',
isFileDragOver && 'ring-2 ring-ring/30',
containerClassName
)}
>
<div className="min-w-0 space-y-4 pt-3">
<div className="space-y-1" data-contextual-tour-target="workspace-creation-project">
<div className="flex items-center justify-between gap-2">
<label className="text-xs font-medium text-muted-foreground">
{projectLabel ??
translate('auto.components.NewWorkspaceComposerCard.969a8bff66', 'Project')}
</label>
{showAddProjectButton ? (
<Tooltip>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon-xs"
onClick={handleAddRepo}
className="size-5 shrink-0 rounded-sm text-muted-foreground hover:text-foreground"
aria-label={translate(
'auto.components.NewWorkspaceComposerCard.d6b0a96f32',
'Add project'
)}
>
<FolderPlus className="size-3" />
</Button>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={6}>
{translate('auto.components.NewWorkspaceComposerCard.d6b0a96f32', 'Add project')}
</TooltipContent>
</Tooltip>
) : null}
</div>
<RepoCombobox
repos={eligibleRepos}
value={repoId}
onValueChange={onRepoChange}
onValueSelected={focusNameInput}
placeholder={
projectPlaceholder ??
translate('auto.components.NewWorkspaceComposerCard.dccd26d4e4', 'Choose project')
}
// Why: programmatic .focus() from the Dialog's onOpenAutoFocus
// handler does not reliably trigger :focus-visible in Chromium.
// Mirror the Input component's standard ring (border-ring +
// ring-ring/50, 3px) onto :focus so the autofocused repo trigger
// paints the familiar field ring instead of leaving no visible
// focus state.
triggerClassName="h-9 w-full border-input text-sm focus:border-ring focus:ring-[3px] focus:ring-ring/50"
showStandaloneAddButton={false}
invalid={Boolean(projectError)}
describedBy={projectDescriptionId}
/>
{projectError ? (
<p id={projectDescriptionId} className="text-[11px] text-destructive">
{projectError}
</p>
) : eligibleRepos.length === 0 ? (
<p id={projectDescriptionId} className="text-[11px] text-muted-foreground">
{emptyProjectMessage ??
translate(
'auto.components.NewWorkspaceComposerCard.addProjectBeforeWorkspace',
'Add a project before creating a workspace.'
)}
</p>
) : null}
{selectedRepoRequiresConnection && selectedRepoConnectionId ? (
<div
role="status"
aria-live="polite"
className="flex items-center justify-between gap-3 rounded-md border border-border/70 bg-muted/35 px-3 py-2"
>
<div className="min-w-0">
<div className="truncate text-xs font-medium text-foreground">
{translate('auto.components.NewWorkspaceComposerCard.b5a0796911', 'Connect')}{' '}
{selectedRepoName}
</div>
<div className="mt-0.5 text-[11px] text-muted-foreground">{sshStatusLabel}</div>
</div>
<Button
type="button"
variant="outline"
size="xs"
onClick={() => void onConnectSelectedRepo()}
disabled={selectedRepoConnectInProgress}
className="shrink-0"
>
{selectedRepoConnectInProgress ? (
<LoaderCircle className="size-3.5 animate-spin" />
) : (
<PlugZap className="size-3.5" />
)}
{selectedRepoConnectInProgress
? translate('auto.components.NewWorkspaceComposerCard.f660aa1454', 'Connecting')
: connectButtonLabel}
</Button>
</div>
) : null}
</div>
<div className="min-w-0 space-y-1" data-contextual-tour-target="workspace-creation-name">
<label className="block min-w-0 truncate text-xs font-medium text-muted-foreground">
{selectedRepoIsGit
? translate(
'auto.components.NewWorkspaceComposerCard.ac3748dcda',
"Name or 'Create From'"
)
: translate(
'auto.components.NewWorkspaceComposerCard.0ee17638fe',
'Workspace name'
)}{' '}
<span className="text-muted-foreground/70">
{translate('auto.components.NewWorkspaceComposerCard.0c5d6a479c', '[Optional]')}
</span>
</label>
<SmartWorkspaceNameField
inputRef={nameInputRef}
repos={eligibleRepos}
repoId={repoId}
onRepoChange={onRepoChange}
value={name}
onValueChange={onNameValueChange}
onGitHubItemSelect={onSmartGitHubItemSelect}
onGitLabItemSelect={onSmartGitLabItemSelect}
onBranchSelect={onSmartBranchSelect}
onLinearIssueSelect={onSmartLinearIssueSelect}
selectedSource={smartNameSelection}
onClearSelectedSource={onClearSmartNameSelection}
disabled={selectedRepoRequiresConnection}
disabledPlaceholder="Connect this repo first"
textOnly={!selectedRepoIsGit}
branchesEnabled={branchesEnabled}
onPlainEnter={() => {
// Why: Enter on the workspace name advances focus to the next
// field (Agent combobox) rather than submitting, letting the user
// progress through the form with just the keyboard.
const root = composerRef?.current
const agentTrigger = root?.querySelector<HTMLElement>(
'[data-agent-combobox-root="true"][role="combobox"]'
)
agentTrigger?.focus()
}}
/>
{forkPushWarning ? (
<p className="flex items-start gap-1.5 text-[11px] text-yellow-600 dark:text-yellow-500">
<AlertTriangle className="mt-0.5 size-3 shrink-0" aria-hidden="true" />
<span>{forkPushWarning}</span>
</p>
) : null}
</div>
<div className="space-y-1" data-contextual-tour-target="workspace-creation-agent">
<div className="flex items-center justify-between gap-2">
<label className="text-xs font-medium text-muted-foreground">
{translate('auto.components.NewWorkspaceComposerCard.01d1e8f601', 'Agent')}
</label>
<Tooltip>
<TooltipTrigger asChild>
<Button
type="button"
variant="ghost"
size="icon-xs"
onClick={onOpenAgentSettings}
// Why: keep Tab flow Name → Agent combobox. This settings
// shortcut is a detour; making it tabbable forces a keystroke
// on every workspace creation.
tabIndex={-1}
className="size-5 shrink-0 rounded-sm text-muted-foreground hover:text-foreground"
aria-label={translate(
'auto.components.NewWorkspaceComposerCard.ab63f25397',
'Open agent settings'
)}
>
<Settings2 className="size-3" />
</Button>
</TooltipTrigger>
<TooltipContent side="top" sideOffset={6}>
{translate(
'auto.components.NewWorkspaceComposerCard.ba64270bdb',
'Configure agents'
)}
</TooltipContent>
</Tooltip>
</div>
<AgentCombobox
agents={visibleQuickAgents}
value={quickAgent}
onValueChange={onQuickAgentChange}
onOpenManageAgents={onOpenAgentSettings}
defaultAgent={defaultTuiAgent}
onSetDefault={handleSetDefaultAgent}
triggerClassName="h-9 w-full border-input text-sm focus:border-ring focus:ring-[3px] focus:ring-ring/50"
onTriggerEnter={createDisabled ? undefined : onCreate}
/>
</div>
<div>
<Button
type="button"
variant="ghost"
size="sm"
onClick={onToggleAdvanced}
className="-ml-2 text-xs"
>
{translate('auto.components.NewWorkspaceComposerCard.f0470c7383', 'Advanced')}
<ChevronDown
className={cn('size-4 transition-transform', advancedOpen && 'rotate-180')}
/>
</Button>
</div>
<div
className={cn(
'grid overflow-hidden transition-[grid-template-rows] duration-200 ease-out',
advancedOpen ? 'grid-rows-[1fr]' : 'grid-rows-[0fr]'
)}
aria-hidden={!advancedOpen}
>
<div className="min-h-0">
{/* Why: px-1 insets the content 4px on each side so the Note
textarea's 3px outset focus ring has horizontal breathing room
inside the overflow-hidden drawer above. Without it the ring
gets clipped on the right edge when the field is focused. */}
<div
className={cn(
'space-y-4 px-1 pt-1 pb-3 transition-[opacity,transform] duration-150 ease-out',
advancedOpen
? 'translate-y-0 opacity-100 delay-200'
: '-translate-y-1 opacity-0 delay-0'
)}
>
{smartNameSelection ? (
// Why: when a source (PR/issue/Linear/Jira/branch) is picked the
// smart field shows a pill instead of an editable name, so
// surface the auto-derived workspace name here under Advanced
// where it can be reviewed/overridden. When the user typed an
// explicit name there's no source pill — the smart input is
// already the name field, so we don't duplicate it here.
<div className="space-y-1">
<label className="text-xs font-medium text-muted-foreground">
{translate('auto.components.NewWorkspaceComposerCard.2688050e4b', 'Name')}
</label>
<input
type="text"
value={name}
onChange={(event) => onNameValueChange(event.target.value)}
placeholder={translate(
'auto.components.NewWorkspaceComposerCard.0ee17638fe',
'Workspace name'
)}
className="w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1.5 text-sm shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50"
/>
</div>
) : null}
<div className="space-y-1">
<label className="text-xs font-medium text-muted-foreground">
{translate('auto.components.NewWorkspaceComposerCard.f8728aa4f9', 'Note')}
</label>
<textarea
value={note}
onChange={(event) => onNoteChange(event.target.value)}
onInput={(event) => {
// Why: start at one-line height, grow to fit content so a short
// note keeps the dialog compact while longer notes get room to
// breathe without a scroll bar until the max-h clamps growth.
const ta = event.currentTarget
ta.style.height = 'auto'
ta.style.height = `${ta.scrollHeight}px`
}}
placeholder={translate(
'auto.components.NewWorkspaceComposerCard.090cfedeb4',
'Write a note'
)}
rows={1}
className="w-full min-w-0 resize-none overflow-hidden rounded-md border border-input bg-transparent px-3 py-1.5 text-sm shadow-xs transition-[color,box-shadow] outline-none placeholder:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 max-h-40"
/>
</div>
{setupControlsEnabled && setupConfig ? (
<div className="space-y-2">
<div className="flex flex-wrap items-center justify-between gap-2">
<label className="text-xs font-medium text-muted-foreground">
{setupConfigLabel}
</label>
<span className="rounded-full border border-border/70 bg-muted/45 px-2 py-0.5 text-[10px] font-medium uppercase tracking-[0.14em] text-foreground/70">
{setupConfig.source === 'yaml'
? translate(
'auto.components.NewWorkspaceComposerCard.23bb365554',
'orca.yaml'
)
: setupConfig.source === 'both'
? translate(
'auto.components.NewWorkspaceComposerCard.326a578923',
'orca.yaml + local'
)
: translate(
'auto.components.NewWorkspaceComposerCard.92e34f0311',
'local settings'
)}
</span>
</div>
{/* Why: `orca.yaml` is the committed source of truth for shared setup,
so the preview reconstructs the real YAML shape instead of showing a raw
shell blob that hides where the command came from. */}
<SetupCommandPreview
setupConfig={setupConfig}
headerAction={
requiresExplicitSetupChoice ? null : (
<label className="group flex items-center gap-2 text-xs text-foreground">
<span
className={cn(
'flex size-4 items-center justify-center rounded-[3px] border transition shadow-sm',
resolvedSetupDecision === 'run'
? 'border-emerald-500/60 bg-emerald-500 text-white'
: 'border-foreground/20 bg-background dark:border-white/20 dark:bg-muted/10'
)}
>
<Check
className={cn(
'size-3 transition-opacity',
resolvedSetupDecision === 'run' ? 'opacity-100' : 'opacity-0'
)}
/>
</span>
<input
type="checkbox"
checked={resolvedSetupDecision === 'run'}
onChange={(event) =>
onSetupDecisionChange(event.target.checked ? 'run' : 'skip')
}
className="sr-only"
/>
<span>{setupRunLabel}</span>
</label>
)
}
/>
{requiresExplicitSetupChoice ? (
<div className="space-y-2">
<div className="text-[11px] font-medium text-muted-foreground">
{setupAskLabel}
</div>
<div className="flex flex-wrap items-center gap-2">
<Button
type="button"
onClick={() => onSetupDecisionChange('run')}
variant={setupDecision === 'run' ? 'default' : 'outline'}
size="sm"
>
{setupRunButtonLabel}
</Button>
<Button
type="button"
onClick={() => onSetupDecisionChange('skip')}
variant={setupDecision === 'skip' ? 'secondary' : 'outline'}
size="sm"
>
{setupSkipButtonLabel}
</Button>
</div>
{!setupDecision ? (
<div className="text-xs text-muted-foreground">
{shouldWaitForSetupCheck
? translate(
'auto.components.NewWorkspaceComposerCard.803b7fe72f',
'Checking setup configuration...'
)
: translate(
'auto.components.NewWorkspaceComposerCard.9a70e4859e',
'Choose whether to run setup before creating this workspace.'
)}
</div>
) : null}
</div>
) : null}
</div>
) : null}
{sparseControlsEnabled ? (
<div className="space-y-1.5">
<label className="text-xs font-medium text-muted-foreground">
{translate(
'auto.components.NewWorkspaceComposerCard.d861de981b',
'Sparse checkout'
)}
</label>
<SparseCheckoutPresetSelect
repoId={repoId}
presets={sparsePresets}
selectedPresetId={sparseSelectedPresetId}
onSelectPreset={onSparseSelectPreset}
disabled={!canUseSparseCheckout}
/>
{!canUseSparseCheckout ? (
<p className="text-[11px] text-muted-foreground">
{translate(
'auto.components.NewWorkspaceComposerCard.cbb47ee0dc',
'Only available for local Git projects.'
)}
</p>
) : null}
</div>
) : null}
</div>
</div>
</div>
</div>
{createError ? (
<div
role="alert"
className="rounded-md border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive"
>
{createError.help ? (
<div className="space-y-1">
<p className="font-medium">{createError.title}</p>
<p>{createError.message}</p>
<p className="text-destructive/85">{createError.help}</p>
</div>
) : (
createError.message
)}
</div>
) : null}
<div className="flex justify-end">
<Button
onClick={() => void onCreate()}
disabled={createDisabled}
size="sm"
className="text-xs"
>
{creating ? <LoaderCircle className="size-4 animate-spin" /> : null}
{primaryActionLabel}
<span className="ml-1 inline-flex items-center gap-0.5 rounded border border-white/20 px-1.5 py-0.5 text-[10px] font-medium leading-none text-current/80">
<span>{submitShortcutModifierLabel}</span>
<CornerDownLeft className="size-3" />
</span>
</Button>
</div>
</div>
)
}