diff --git a/src/renderer/src/components/jira-project-picker.tsx b/src/renderer/src/components/jira-project-picker.tsx index 71bfb62850c..fa0d09a8f1e 100644 --- a/src/renderer/src/components/jira-project-picker.tsx +++ b/src/renderer/src/components/jira-project-picker.tsx @@ -1,3 +1,4 @@ +import type React from 'react' import type { JiraProject } from '../../../shared/jira/jira-types' import { normalizeJiraProjectReference, @@ -13,7 +14,9 @@ export function JiraProjectPicker({ onChange, label, emptyLabel, - disabled + disabled, + size, + returnFocusRef }: { projects: readonly JiraProject[] value: JiraProjectReference | null @@ -21,6 +24,8 @@ export function JiraProjectPicker({ label: string emptyLabel: string disabled?: boolean + size?: 'default' | 'xs' + returnFocusRef?: React.RefObject }): React.JSX.Element { const t = useTranslate() const options: WorkItemScopeOption[] = projects.flatMap((project) => { @@ -48,6 +53,8 @@ export function JiraProjectPicker({ searchPlaceholder={t('components.jiraProjectPicker.search', 'Search Jira projects')} emptyLabel={t('components.jiraProjectPicker.empty', 'No projects found.')} disabled={disabled} + size={size} + returnFocusRef={returnFocusRef} /> ) } diff --git a/src/renderer/src/components/linear-workspace-picker.tsx b/src/renderer/src/components/linear-workspace-picker.tsx index a5a135c1de1..9a3f4ce02a8 100644 --- a/src/renderer/src/components/linear-workspace-picker.tsx +++ b/src/renderer/src/components/linear-workspace-picker.tsx @@ -1,3 +1,4 @@ +import type React from 'react' import type { LinearWorkspace } from '../../../shared/linear/workspace-types' import { useTranslate } from '@/i18n/use-translate' import { WorkItemScopePicker } from './work-item-scope-picker' @@ -6,12 +7,16 @@ export function LinearWorkspacePicker({ workspaces, value, onChange, - disabled + disabled, + size, + returnFocusRef }: { workspaces: readonly LinearWorkspace[] value: string | null | undefined onChange: (workspaceId: string) => void disabled?: boolean + size?: 'default' | 'xs' + returnFocusRef?: React.RefObject }): React.JSX.Element { const t = useTranslate() const selected = workspaces.find((workspace) => workspace.id === value) @@ -36,6 +41,8 @@ export function LinearWorkspacePicker({ searchPlaceholder={t('components.linearWorkspacePicker.search', 'Search Linear workspaces')} emptyLabel={t('components.linearWorkspacePicker.empty', 'No workspaces found.')} disabled={disabled} + size={size} + returnFocusRef={returnFocusRef} /> ) } diff --git a/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.fixture.tsx b/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.fixture.tsx new file mode 100644 index 00000000000..9a6d38bda2f --- /dev/null +++ b/src/renderer/src/components/new-workspace/SmartWorkspaceNameField.fixture.tsx @@ -0,0 +1,393 @@ +import { useState } from 'react' +import { ChevronDown } from 'lucide-react' +import { Button } from '@/components/ui/button' +import { getProviderRuntimeContextKey } from '@/runtime/hosts/observations/provider-runtime-context' +import { getLocalPreflightContext } from '@/runtime/hosts/preflight/local-preflight-context' +import { localPreflightContextKey } from '@/runtime/hosts/preflight/local-preflight-context-key' +import { useAppStore } from '@/store' +import { defineFixture } from '../../component-fixtures/component-fixture' +import { buildTaskSourceContextFromRepo } from '../../../../shared/work-items/task-source-context' +import type { + JiraConnectionStatus, + JiraIssue, + JiraProject +} from '../../../../shared/jira/jira-types' +import type { LinearIssue } from '../../../../shared/linear/issue-types' +import type { LinearConnectionStatus } from '../../../../shared/linear/workspace-types' +import type { Repo } from '../../../../shared/repo-types' +import SmartWorkspaceNameField from './SmartWorkspaceNameField' +import type { SmartWorkspaceNameFieldProps } from './smart-workspace-name-field-model' + +const repo: Repo = { + id: 'repo-orca', + path: '/Users/dev/orca', + displayName: 'orca', + badgeColor: '#64748b', + addedAt: 0 +} + +const jiraSourceContext = buildTaskSourceContextFromRepo({ + provider: 'jira', + projectId: repo.id, + repo +}) + +const linearStatusFixture: LinearConnectionStatus = { + connected: true, + viewer: null, + selectedWorkspaceId: 'all', + activeWorkspaceId: 'ws-stably', + workspaces: [ + { + id: 'ws-stably', + organizationId: 'org-stably', + organizationName: 'Stably', + displayName: 'Dev User', + email: 'dev@stably.ai' + }, + { + id: 'ws-platform', + organizationId: 'org-platform', + organizationName: 'Platform Ops', + displayName: 'Dev User', + email: 'dev@stably.ai' + } + ] +} + +function makeLinearIssue( + id: string, + workspaceId: string, + workspaceName: string, + identifier: string, + title: string +): LinearIssue { + return { + id, + workspaceId, + workspaceName, + identifier, + title, + url: `https://linear.app/stably/issue/${identifier}`, + state: { name: 'Todo', type: 'unstarted', color: '#94a3b8' }, + team: { id: 'team-1', name: workspaceName, key: 'STA' }, + labels: [], + labelIds: [], + priority: 2, + updatedAt: '2026-11-12T00:00:00.000Z' + } +} + +const linearIssuesFixture: LinearIssue[] = [ + makeLinearIssue( + 'lin-1', + 'ws-stably', + 'Stably', + 'STA-3699', + 'Update installer swaps app.asar under the running renderer' + ), + makeLinearIssue( + 'lin-2', + 'ws-stably', + 'Stably', + 'STA-6457', + '[Bug]: AppImage squashfs is unmounted before helper exits' + ), + makeLinearIssue( + 'lin-3', + 'ws-platform', + 'Platform Ops', + 'STA-14948', + "Release scan P2: Claude Code doesn't resume after a host reconnect" + ) +] + +const jiraProjectsFixture: JiraProject[] = [ + { + id: '100', + key: 'ORCA', + name: 'Orca Desktop', + siteId: 'site-1', + siteName: 'stably.atlassian.net' + }, + { + id: '101', + key: 'INFRA', + name: 'Runtime Infra', + siteId: 'site-1', + siteName: 'stably.atlassian.net' + } +] + +const jiraStatusFixture: JiraConnectionStatus = { + connected: true, + viewer: null, + selectedSiteId: 'site-1', + activeSiteId: 'site-1', + sites: [ + { + id: 'site-1', + siteUrl: 'https://stably.atlassian.net', + email: 'dev@stably.ai', + displayName: 'stably.atlassian.net', + accountId: 'acc-1' + } + ] +} + +function makeJiraIssue(id: string, key: string, title: string, project: JiraProject): JiraIssue { + return { + id, + key, + siteId: 'site-1', + siteName: 'stably.atlassian.net', + title, + url: `https://stably.atlassian.net/browse/${key}`, + project, + issueType: { id: '1', name: 'Task' }, + status: { + id: '1', + name: 'In Progress', + categoryKey: 'indeterminate', + categoryName: 'In Progress' + }, + labels: [], + updatedAt: '2026-11-12T00:00:00.000Z', + createdAt: '2026-11-11T00:00:00.000Z' + } +} + +const jiraIssuesFixture: JiraIssue[] = [ + makeJiraIssue( + 'jira-1', + 'ORCA-412', + 'Align scope pickers inside workspace source results popover', + jiraProjectsFixture[0] + ), + makeJiraIssue( + 'jira-2', + 'ORCA-389', + 'Keep composer search input stationary across provider tabs', + jiraProjectsFixture[0] + ), + makeJiraIssue( + 'jira-3', + 'INFRA-104', + 'Preserve remote SSH runtime capabilities across daemon upgrades', + jiraProjectsFixture[1] + ) +] + +function seedSourceProviders(): void { + window.api = { + ...window.api, + linear: { + ...window.api.linear, + status: async () => linearStatusFixture, + listIssues: async (payload) => ({ + items: + payload?.workspaceId && payload.workspaceId !== 'all' + ? linearIssuesFixture.filter((issue) => issue.workspaceId === payload.workspaceId) + : linearIssuesFixture + }), + searchIssues: async (payload) => + payload.workspaceId && payload.workspaceId !== 'all' + ? linearIssuesFixture.filter((issue) => issue.workspaceId === payload.workspaceId) + : linearIssuesFixture + }, + jira: { + ...window.api.jira, + status: async () => jiraStatusFixture, + listProjects: async () => jiraProjectsFixture, + searchIssues: async () => jiraIssuesFixture + } + } + + const currentState = useAppStore.getState() + useAppStore.setState({ + repos: [repo], + linearStatus: linearStatusFixture, + linearStatusObserved: true, + linearStatusChecked: true, + linearStatusContextKey: getProviderRuntimeContextKey(currentState.settings), + checkLinearConnection: async () => {}, + preflightStatus: { + git: { installed: true }, + gh: { installed: true, authenticated: true }, + glab: { installed: true, authenticated: true } + }, + preflightStatusChecked: true, + preflightStatusContextKey: localPreflightContextKey(getLocalPreflightContext(currentState)), + refreshPreflightStatus: async () => {}, + fetchWorkItems: async () => {}, + fetchWorkItemsAcrossRepos: async () => {}, + getCachedWorkItems: () => [], + readJiraStatus: async () => jiraStatusFixture, + searchJiraIssues: async () => jiraIssuesFixture + }) +} + +function ComposerSurfacePreview({ initialQuery = '' }: { initialQuery?: string }) { + const [value, setValue] = useState(initialQuery) + const [selectedSource, setSelectedSource] = + useState(null) + return ( +
+
+ + Create From [Optional] + + {}} + value={value} + onValueChange={setValue} + onGitHubItemSelect={() => {}} + onGitLabItemSelect={() => {}} + onBranchSelect={() => {}} + onLinearIssueSelect={(issue) => + setSelectedSource({ + kind: 'linear', + label: `${issue.identifier} ${issue.title}`, + url: issue.url + }) + } + onJiraIssueSelect={(issue) => + setSelectedSource({ + kind: 'jira', + label: `${issue.key} ${issue.title}`, + url: issue.url + }) + } + selectedSource={selectedSource} + onClearSelectedSource={() => setSelectedSource(null)} + jiraSourceContext={jiraSourceContext} + branchesEnabled + /> +
+
+ Agent [Optional] +
+ Claude Code +
+
+
+ +
+
+ +
+
+ ) +} + +function pressControl(element: HTMLElement | null): void { + if (!element) { + return + } + const init = { bubbles: true, cancelable: true, button: 0 } + element.dispatchEvent(new PointerEvent('pointerdown', { ...init, pointerType: 'mouse' })) + element.dispatchEvent(new MouseEvent('mousedown', init)) + element.click() +} + +const wait = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) + +async function selectMode(frame: HTMLElement, mode: string): Promise { + await wait(60) + const tab = frame.querySelector(`[data-smart-name-mode="${mode}"]`) + if (!tab) { + throw new Error(`Missing source tab: ${mode}`) + } + pressControl(tab) + await wait(260) +} + +function openScopeDropdown(ariaLabel: string): void { + const trigger = document.querySelector(`button[aria-label="${ariaLabel}"]`) + if (!trigger) { + throw new Error(`Missing ${ariaLabel} dropdown trigger`) + } + pressControl(trigger) +} + +export const gitlab = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: (frame) => selectMode(frame, 'gitlab') +}) + +export const linear = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: (frame) => selectMode(frame, 'linear') +}) + +export const linearDropdownOpen = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: async (frame) => { + await selectMode(frame, 'linear') + openScopeDropdown('Linear workspace') + await wait(80) + if (!document.querySelector('[data-workspace-source-suggestions="true"]')) { + throw new Error('Source suggestions popover closed when opening Linear workspace dropdown') + } + } +}) + +export const linearFilteredWorkspace = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: async (frame) => { + await selectMode(frame, 'linear') + openScopeDropdown('Linear workspace') + await wait(80) + const option = [...document.querySelectorAll('[role="option"]')].find((node) => + node.textContent?.includes('Platform Ops') + ) + if (!option) { + throw new Error('Missing Platform Ops workspace option') + } + pressControl(option) + await wait(120) + if (!document.querySelector('[data-workspace-source-suggestions="true"]')) { + throw new Error('Source suggestions popover closed after selecting Linear workspace') + } + if (document.activeElement?.getAttribute('data-workspace-name-input') !== 'true') { + throw new Error('Focus did not return to workspace search input after workspace selection') + } + } +}) + +export const jira = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: (frame) => selectMode(frame, 'jira') +}) + +export const jiraDropdownOpen = defineFixture({ + width: 480, + setup: seedSourceProviders, + render: () => , + interact: async (frame) => { + await selectMode(frame, 'jira') + openScopeDropdown('Jira project') + await wait(80) + if (!document.querySelector('[data-workspace-source-suggestions="true"]')) { + throw new Error('Source suggestions popover closed when opening Jira project dropdown') + } + } +}) diff --git a/src/renderer/src/components/new-workspace/smart-workspace-name-field-surface.tsx b/src/renderer/src/components/new-workspace/smart-workspace-name-field-surface.tsx index c0e62b041e7..ba3ddbab71a 100644 --- a/src/renderer/src/components/new-workspace/smart-workspace-name-field-surface.tsx +++ b/src/renderer/src/components/new-workspace/smart-workspace-name-field-surface.tsx @@ -12,8 +12,6 @@ import { renderSmartWorkspaceNameInput } from './smart-workspace-name-input-surf import { renderSmartWorkspaceSourceResults } from './smart-workspace-source-results-surface' import { getJiraSourceStatusMessage } from './jira-source-status-message' import type { SmartWorkspaceNameFieldController } from './use-smart-workspace-name-field-controller' -import { JiraProjectPicker } from '../jira-project-picker' -import { LinearWorkspacePicker } from '../linear-workspace-picker' export function renderSmartWorkspaceNameField( controller: SmartWorkspaceNameFieldController, @@ -52,24 +50,6 @@ export function renderSmartWorkspaceNameField( tabsListRef={controller.tabsListRef} /> )} - {mode === 'jira' && selectedSource === null ? ( - - ) : null} - {mode === 'linear' && selectedSource === null ? ( - - ) : null}
{renderSmartWorkspaceNameInput(controller, t)}
- {renderSmartWorkspaceSourceResults(controller)} + {renderSmartWorkspaceSourceResults(controller, t)}
{jiraSource.intent ? ( diff --git a/src/renderer/src/components/new-workspace/smart-workspace-source-results-surface.tsx b/src/renderer/src/components/new-workspace/smart-workspace-source-results-surface.tsx index 7afb13d76e2..a34c48d7e9a 100644 --- a/src/renderer/src/components/new-workspace/smart-workspace-source-results-surface.tsx +++ b/src/renderer/src/components/new-workspace/smart-workspace-source-results-surface.tsx @@ -1,12 +1,21 @@ import React from 'react' -import { SmartWorkspaceSourceResultList } from './SmartWorkspaceSourceResultList' import { PopoverContent } from '@/components/ui/popover' +import { translate } from '@/i18n/i18n' +import type { Translate } from '@/i18n/use-translate' +import { JiraProjectPicker } from '../jira-project-picker' +import { LinearWorkspacePicker } from '../linear-workspace-picker' +import { SmartWorkspaceSourceResultList } from './SmartWorkspaceSourceResultList' import type { SmartWorkspaceNameFieldController } from './use-smart-workspace-name-field-controller' export function renderSmartWorkspaceSourceResults( - controller: SmartWorkspaceNameFieldController + controller: SmartWorkspaceNameFieldController, + t: Translate = translate ): React.JSX.Element { - const { localInputRef, tabsListRef } = controller + const { disabled, localInputRef, mode, tabsListRef } = controller + const hasFilterHeader = mode === 'gitlab' || mode === 'linear' || mode === 'jira' + const maxHeight = hasFilterHeader + ? 'min(var(--radix-popover-content-available-height,8rem),8rem)' + : 'min(var(--radix-popover-content-available-height,7rem),7rem)' return ( event.preventDefault()} onPointerDownOutside={(event) => { // Input/mode tabs are anchors outside Radix content; interacting with them must keep results open. @@ -33,6 +42,37 @@ export function renderSmartWorkspaceSourceResults( } }} > + {mode === 'jira' ? ( +
event.preventDefault()} + > + +
+ ) : mode === 'linear' ? ( +
event.preventDefault()} + > + +
+ ) : null}
) diff --git a/src/renderer/src/components/work-item-scope-picker.tsx b/src/renderer/src/components/work-item-scope-picker.tsx index 2509b7c82b4..a1243e7dc18 100644 --- a/src/renderer/src/components/work-item-scope-picker.tsx +++ b/src/renderer/src/components/work-item-scope-picker.tsx @@ -1,8 +1,17 @@ -import { useState } from 'react' +import type React from 'react' +import { useRef, useState } from 'react' import { Check, ChevronsUpDown } from 'lucide-react' +import { cn } from '@/lib/class-names' import { Button } from './ui/button' import { Popover, PopoverContent, PopoverTrigger } from './ui/popover' -import { Command, CommandInput, CommandList, CommandEmpty, CommandItem } from './ui/command' +import { + Command, + CommandEmpty, + CommandGroup, + CommandInput, + CommandItem, + CommandList +} from './ui/command' export type WorkItemScopeOption = { key: string @@ -21,7 +30,9 @@ export function WorkItemScopePicker({ allLabel, searchPlaceholder, emptyLabel, - disabled + disabled, + size = 'default', + returnFocusRef }: { options: readonly WorkItemScopeOption[] selectedKey: string | null @@ -32,9 +43,13 @@ export function WorkItemScopePicker({ searchPlaceholder: string emptyLabel: string disabled?: boolean + size?: 'default' | 'xs' + returnFocusRef?: React.RefObject }): React.JSX.Element { const [open, setOpen] = useState(false) + const returnFocusOnCloseRef = useRef(false) const select = (value: T | null) => { + returnFocusOnCloseRef.current = true onChange(value) setOpen(false) } @@ -42,43 +57,67 @@ export function WorkItemScopePicker({ - - + event.stopPropagation()} + onEscapeKeyDown={() => { + returnFocusOnCloseRef.current = true + }} + onCloseAutoFocus={(event) => { + const shouldReturnFocus = returnFocusOnCloseRef.current + returnFocusOnCloseRef.current = false + if (!shouldReturnFocus || !returnFocusRef?.current) { + return + } + event.preventDefault() + returnFocusRef.current.focus({ preventScroll: true }) + }} + > + {emptyLabel} - select(null)}> - {allLabel} - {selectedKey === null ? : null} - - {options.map((option) => ( - select(option.value)} - > - - {option.label} - {option.description ? ( - - {option.description} - - ) : null} - - {selectedKey === option.key ? : null} + + select(null)}> + {allLabel} + {selectedKey === null ? : null} - ))} + {options.map((option) => ( + select(option.value)} + > + + {option.label} + {option.description ? ( + + {option.description} + + ) : null} + + {selectedKey === option.key ? : null} + + ))} +