mirror of
https://github.com/stablyai/orca.git
synced 2026-11-17 19:34:29 +00:00
fix(new-workspace): move Linear and Jira scope pickers into source results popover (#41472)
* fix(new-workspace): move Linear and Jira scope pickers into source results popover * fix(workspace): preserve focus around nested scope pickers
This commit is contained in:
@@ -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<HTMLElement | null>
|
||||
}): React.JSX.Element {
|
||||
const t = useTranslate()
|
||||
const options: WorkItemScopeOption<JiraProjectReference>[] = 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}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<HTMLElement | null>
|
||||
}): 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}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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<SmartWorkspaceNameFieldProps['selectedSource']>(null)
|
||||
return (
|
||||
<div className="space-y-4 rounded-xl border border-border bg-background p-4">
|
||||
<div className="space-y-1">
|
||||
<span className="text-xs font-medium text-muted-foreground">
|
||||
Create From <span className="text-muted-foreground/70">[Optional]</span>
|
||||
</span>
|
||||
<SmartWorkspaceNameField
|
||||
repos={[repo]}
|
||||
selectedRepo={repo}
|
||||
repoId={repo.id}
|
||||
onRepoChange={() => {}}
|
||||
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
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<span className="text-xs font-medium text-muted-foreground">Agent [Optional]</span>
|
||||
<div className="flex h-9 items-center rounded-md border border-input bg-background px-3 text-sm text-muted-foreground">
|
||||
Claude Code
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<Button type="button" variant="ghost" size="xs" className="-ml-2">
|
||||
Advanced
|
||||
<ChevronDown />
|
||||
</Button>
|
||||
</div>
|
||||
<div className="flex justify-end">
|
||||
<Button type="button" size="sm">
|
||||
Create
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
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<void> {
|
||||
await wait(60)
|
||||
const tab = frame.querySelector<HTMLElement>(`[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<HTMLButtonElement>(`button[aria-label="${ariaLabel}"]`)
|
||||
if (!trigger) {
|
||||
throw new Error(`Missing ${ariaLabel} dropdown trigger`)
|
||||
}
|
||||
pressControl(trigger)
|
||||
}
|
||||
|
||||
export const gitlab = defineFixture({
|
||||
width: 480,
|
||||
setup: seedSourceProviders,
|
||||
render: () => <ComposerSurfacePreview />,
|
||||
interact: (frame) => selectMode(frame, 'gitlab')
|
||||
})
|
||||
|
||||
export const linear = defineFixture({
|
||||
width: 480,
|
||||
setup: seedSourceProviders,
|
||||
render: () => <ComposerSurfacePreview />,
|
||||
interact: (frame) => selectMode(frame, 'linear')
|
||||
})
|
||||
|
||||
export const linearDropdownOpen = defineFixture({
|
||||
width: 480,
|
||||
setup: seedSourceProviders,
|
||||
render: () => <ComposerSurfacePreview />,
|
||||
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: () => <ComposerSurfacePreview />,
|
||||
interact: async (frame) => {
|
||||
await selectMode(frame, 'linear')
|
||||
openScopeDropdown('Linear workspace')
|
||||
await wait(80)
|
||||
const option = [...document.querySelectorAll<HTMLElement>('[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: () => <ComposerSurfacePreview initialQuery="ORCA" />,
|
||||
interact: (frame) => selectMode(frame, 'jira')
|
||||
})
|
||||
|
||||
export const jiraDropdownOpen = defineFixture({
|
||||
width: 480,
|
||||
setup: seedSourceProviders,
|
||||
render: () => <ComposerSurfacePreview initialQuery="ORCA" />,
|
||||
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')
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -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 ? (
|
||||
<JiraProjectPicker
|
||||
projects={controller.jiraProjectInventory.projects}
|
||||
value={controller.jiraProject}
|
||||
onChange={controller.setJiraProject}
|
||||
label={t('components.jiraProjectPicker.label', 'Jira project')}
|
||||
emptyLabel={t('components.jiraProjectPicker.all', 'All Jira projects')}
|
||||
disabled={disabled || controller.jiraProjectInventory.loading}
|
||||
/>
|
||||
) : null}
|
||||
{mode === 'linear' && selectedSource === null ? (
|
||||
<LinearWorkspacePicker
|
||||
workspaces={controller.linearStatus.workspaces ?? []}
|
||||
value={controller.linearWorkspaceIdOverride}
|
||||
onChange={controller.setLinearWorkspaceId}
|
||||
disabled={disabled || !controller.linearStatusChecked}
|
||||
/>
|
||||
) : null}
|
||||
<Popover
|
||||
open={!disabled && open && mode !== 'text' && selectedSource === null}
|
||||
onOpenChange={handleSourcePopoverOpenChange}
|
||||
@@ -89,7 +69,7 @@ export function renderSmartWorkspaceNameField(
|
||||
<PopoverAnchor asChild>
|
||||
<div className="relative min-w-0">{renderSmartWorkspaceNameInput(controller, t)}</div>
|
||||
</PopoverAnchor>
|
||||
{renderSmartWorkspaceSourceResults(controller)}
|
||||
{renderSmartWorkspaceSourceResults(controller, t)}
|
||||
</Command>
|
||||
</Popover>
|
||||
{jiraSource.intent ? (
|
||||
|
||||
+44
-4
@@ -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 (
|
||||
<PopoverContent
|
||||
@@ -17,7 +26,7 @@ export function renderSmartWorkspaceSourceResults(
|
||||
avoidCollisions={false}
|
||||
className="popover-scroll-content flex w-[var(--radix-popover-trigger-width)] flex-col p-0"
|
||||
// Why: results must not cover the create-workspace dialog's submit footer.
|
||||
style={{ maxHeight: 'min(var(--radix-popover-content-available-height,7rem),7rem)' }}
|
||||
style={{ maxHeight }}
|
||||
onOpenAutoFocus={(event) => 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' ? (
|
||||
<div
|
||||
className="flex min-w-0 shrink-0 items-center border-b border-border/40 px-2 py-1.5"
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
>
|
||||
<JiraProjectPicker
|
||||
projects={controller.jiraProjectInventory.projects}
|
||||
value={controller.jiraProject}
|
||||
onChange={controller.setJiraProject}
|
||||
label={t('components.jiraProjectPicker.label', 'Jira project')}
|
||||
emptyLabel={t('components.jiraProjectPicker.all', 'All Jira projects')}
|
||||
disabled={disabled || controller.jiraProjectInventory.loading}
|
||||
size="xs"
|
||||
returnFocusRef={localInputRef}
|
||||
/>
|
||||
</div>
|
||||
) : mode === 'linear' ? (
|
||||
<div
|
||||
className="flex min-w-0 shrink-0 items-center border-b border-border/40 px-2 py-1.5"
|
||||
onMouseDown={(event) => event.preventDefault()}
|
||||
>
|
||||
<LinearWorkspacePicker
|
||||
workspaces={controller.linearStatus.workspaces ?? []}
|
||||
value={controller.linearWorkspaceIdOverride}
|
||||
onChange={controller.setLinearWorkspaceId}
|
||||
disabled={disabled || !controller.linearStatusChecked}
|
||||
size="xs"
|
||||
returnFocusRef={localInputRef}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
<SmartWorkspaceSourceResultList model={controller} onSelect={controller.handleSelect} />
|
||||
</PopoverContent>
|
||||
)
|
||||
|
||||
@@ -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<T> = {
|
||||
key: string
|
||||
@@ -21,7 +30,9 @@ export function WorkItemScopePicker<T>({
|
||||
allLabel,
|
||||
searchPlaceholder,
|
||||
emptyLabel,
|
||||
disabled
|
||||
disabled,
|
||||
size = 'default',
|
||||
returnFocusRef
|
||||
}: {
|
||||
options: readonly WorkItemScopeOption<T>[]
|
||||
selectedKey: string | null
|
||||
@@ -32,9 +43,13 @@ export function WorkItemScopePicker<T>({
|
||||
searchPlaceholder: string
|
||||
emptyLabel: string
|
||||
disabled?: boolean
|
||||
size?: 'default' | 'xs'
|
||||
returnFocusRef?: React.RefObject<HTMLElement | null>
|
||||
}): 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<T>({
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
size={size}
|
||||
role="combobox"
|
||||
aria-label={label}
|
||||
aria-expanded={open}
|
||||
disabled={disabled}
|
||||
className="w-full justify-between"
|
||||
onKeyDown={(event) => event.stopPropagation()}
|
||||
className={cn('justify-between', size === 'xs' ? 'min-w-0 max-w-full' : 'w-full')}
|
||||
>
|
||||
<span className="truncate">{selectedLabel ?? allLabel}</span>
|
||||
<ChevronsUpDown className="size-4 shrink-0" />
|
||||
<ChevronsUpDown
|
||||
className={cn('shrink-0', size === 'xs' ? 'size-3 opacity-60' : 'size-4')}
|
||||
/>
|
||||
</Button>
|
||||
</PopoverTrigger>
|
||||
<PopoverContent align="start">
|
||||
<Command>
|
||||
<PopoverContent
|
||||
align="start"
|
||||
className="z-[70] w-64"
|
||||
onKeyDown={(event) => 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 })
|
||||
}}
|
||||
>
|
||||
<Command density={size === 'xs' ? 'menu' : 'default'}>
|
||||
<CommandInput placeholder={searchPlaceholder} />
|
||||
<CommandList>
|
||||
<CommandEmpty>{emptyLabel}</CommandEmpty>
|
||||
<CommandItem value={allLabel} onSelect={() => select(null)}>
|
||||
<span className="flex-1">{allLabel}</span>
|
||||
{selectedKey === null ? <Check className="size-4" /> : null}
|
||||
</CommandItem>
|
||||
{options.map((option) => (
|
||||
<CommandItem
|
||||
key={option.key}
|
||||
value={option.searchText}
|
||||
onSelect={() => select(option.value)}
|
||||
>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate">{option.label}</span>
|
||||
{option.description ? (
|
||||
<span className="block truncate text-xs text-muted-foreground">
|
||||
{option.description}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
{selectedKey === option.key ? <Check className="size-4" /> : null}
|
||||
<CommandGroup>
|
||||
<CommandItem selection="palette" value={allLabel} onSelect={() => select(null)}>
|
||||
<span className="flex-1">{allLabel}</span>
|
||||
{selectedKey === null ? <Check className="size-4" /> : null}
|
||||
</CommandItem>
|
||||
))}
|
||||
{options.map((option) => (
|
||||
<CommandItem
|
||||
key={option.key}
|
||||
selection="palette"
|
||||
value={option.searchText}
|
||||
onSelect={() => select(option.value)}
|
||||
>
|
||||
<span className="min-w-0 flex-1">
|
||||
<span className="block truncate">{option.label}</span>
|
||||
{option.description ? (
|
||||
<span className="block truncate text-xs text-muted-foreground">
|
||||
{option.description}
|
||||
</span>
|
||||
) : null}
|
||||
</span>
|
||||
{selectedKey === option.key ? <Check className="size-4" /> : null}
|
||||
</CommandItem>
|
||||
))}
|
||||
</CommandGroup>
|
||||
</CommandList>
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
|
||||
Reference in New Issue
Block a user