mirror of
https://github.com/chriswritescode-dev/opencode-manager.git
synced 2026-12-05 20:34:18 +01:00
refactor(ui): unify branch pickers into searchable BranchCombobox
Rename BaseBranchSelect to BranchCombobox and rebuild it on the shared Combobox with an include filter, configurable remote prefixing, and clearing. Add a useRepoBranches hook and migrate the worktree, integrate, multi-run, and schedule dialogs onto it. Expose id and ARIA listbox/option roles from Combobox, and add bg-background to the form prompt panels.
This commit is contained in:
1 parent
092add1eb1
commit
27860224dc
12 files changed
+157
-167
No files matched your search
@@ -1,54 +0,0 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { GitBranch } from 'lucide-react'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { listBranches } from '@/api/repos'
|
||||
import { getOriginOnlyBranchNames } from '@/lib/utils'
|
||||
|
||||
interface BaseBranchSelectProps {
|
||||
repoId: number
|
||||
value: string
|
||||
onValueChange: (value: string) => void
|
||||
id?: string
|
||||
placeholder: string
|
||||
}
|
||||
|
||||
export function BaseBranchSelect({ repoId, value, onValueChange, id, placeholder }: BaseBranchSelectProps) {
|
||||
const { data: branchesData, isLoading } = useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const localBranches = (branchesData?.branches ?? []).filter((b) => b.type === 'local')
|
||||
const remoteBranchNames = getOriginOnlyBranchNames(branchesData?.branches ?? [])
|
||||
|
||||
return (
|
||||
<Select value={value} onValueChange={onValueChange} disabled={isLoading}>
|
||||
<SelectTrigger id={id} className="bg-background border-border text-foreground">
|
||||
<SelectValue placeholder={isLoading ? 'Loading branches...' : placeholder} />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="bg-popover border-border">
|
||||
{localBranches.map((branch) => (
|
||||
<SelectItem key={`local-${branch.name}`} value={branch.name}>
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="w-3.5 h-3.5" />
|
||||
<span>{branch.name}</span>
|
||||
{branch.current && (
|
||||
<span className="text-xs text-muted-foreground">(current)</span>
|
||||
)}
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
{remoteBranchNames.map((name) => (
|
||||
<SelectItem key={`remote-${name}`} value={`origin/${name}`}>
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className="w-3.5 h-3.5 text-info" />
|
||||
<span>{name}</span>
|
||||
<span className="text-xs text-muted-foreground">(remote)</span>
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useMemo } from 'react'
|
||||
import { Combobox, type ComboboxOption } from '@/components/ui/combobox'
|
||||
import type { GitBranch } from '@/api/repos'
|
||||
import { useRepoBranches } from '@/hooks/useRepoBranches'
|
||||
import { getOriginOnlyBranchNames } from '@/lib/utils'
|
||||
|
||||
type RemoteBranchValue = 'none' | 'origin-prefixed' | 'bare'
|
||||
|
||||
interface BranchComboboxProps {
|
||||
repoId: number | undefined
|
||||
value: string
|
||||
onValueChange: (value: string) => void
|
||||
placeholder: string
|
||||
enabled?: boolean
|
||||
include?: (branch: GitBranch) => boolean
|
||||
remotes?: RemoteBranchValue
|
||||
clearable?: boolean
|
||||
id?: string
|
||||
ariaLabel?: string
|
||||
}
|
||||
|
||||
/**
|
||||
* Searchable branch picker listing local branches plus origin-only remote branches,
|
||||
* which are the only refs the backend can resolve.
|
||||
*/
|
||||
export function BranchCombobox({
|
||||
repoId,
|
||||
value,
|
||||
onValueChange,
|
||||
placeholder,
|
||||
enabled = true,
|
||||
include,
|
||||
remotes = 'origin-prefixed',
|
||||
clearable = false,
|
||||
id,
|
||||
ariaLabel,
|
||||
}: BranchComboboxProps) {
|
||||
const { data: branchesData, isLoading } = useRepoBranches(repoId, enabled)
|
||||
|
||||
const options = useMemo<ComboboxOption[]>(() => {
|
||||
const branches = branchesData?.branches ?? []
|
||||
const localOptions = branches
|
||||
.filter((branch) => branch.type === 'local' && (include?.(branch) ?? true))
|
||||
.map((branch) => ({
|
||||
value: branch.name,
|
||||
label: branch.name,
|
||||
description: branch.current ? 'current' : undefined,
|
||||
group: 'Local',
|
||||
}))
|
||||
if (remotes === 'none') return localOptions
|
||||
return [
|
||||
...localOptions,
|
||||
...getOriginOnlyBranchNames(branches).map((name) => ({
|
||||
value: remotes === 'origin-prefixed' ? `origin/${name}` : name,
|
||||
label: name,
|
||||
group: 'Remote',
|
||||
})),
|
||||
]
|
||||
}, [branchesData, include, remotes])
|
||||
|
||||
return (
|
||||
<Combobox
|
||||
id={id}
|
||||
value={value}
|
||||
onChange={onValueChange}
|
||||
options={options}
|
||||
placeholder={isLoading ? 'Loading branches...' : placeholder}
|
||||
disabled={isLoading}
|
||||
allowCustomValue={false}
|
||||
showClear={clearable}
|
||||
ariaLabel={ariaLabel}
|
||||
/>
|
||||
)
|
||||
}
|
||||
@@ -1,18 +1,22 @@
|
||||
import { useState, useEffect } from 'react'
|
||||
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { AlertCircle, GitBranch, Loader2 } from 'lucide-react'
|
||||
import { createRepo, listBranches, type CreateRepoOptions } from '@/api/repos'
|
||||
import { createRepo, type CreateRepoOptions, type GitBranch as RepoBranch } from '@/api/repos'
|
||||
import { dialogSearch } from '@/hooks/useDialogParam'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { notifyWorktreeSetup } from '@/lib/worktreeSetup'
|
||||
import { invalidateRepoGitCaches } from '@/lib/queryInvalidation'
|
||||
import { getOriginOnlyBranchNames } from '@/lib/utils'
|
||||
import { BaseBranchSelect } from './BaseBranchSelect'
|
||||
import { useRepoBranches } from '@/hooks/useRepoBranches'
|
||||
import { BranchCombobox } from './BranchCombobox'
|
||||
|
||||
function isCheckoutCandidate(branch: RepoBranch): boolean {
|
||||
return !branch.current && !branch.isWorktree
|
||||
}
|
||||
|
||||
interface CreateWorktreeDialogProps {
|
||||
open: boolean
|
||||
@@ -48,24 +52,12 @@ export function CreateWorktreeDialog({
|
||||
|
||||
const canCreate = Boolean(repoUrl)
|
||||
|
||||
const { data: branchesData, isLoading: branchesLoading } = useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
enabled: open && canCreate,
|
||||
staleTime: 30000,
|
||||
})
|
||||
const { data: branchesData } = useRepoBranches(repoId, open && canCreate)
|
||||
|
||||
const localBranches = (branchesData?.branches ?? []).filter((b) => b.type === 'local')
|
||||
|
||||
const remoteBranchNames = getOriginOnlyBranchNames(branchesData?.branches ?? [])
|
||||
|
||||
const checkoutCandidates = [
|
||||
...localBranches
|
||||
.filter((b) => !b.current && !b.isWorktree)
|
||||
.map((b) => ({ name: b.name, remote: false })),
|
||||
...remoteBranchNames.map((name) => ({ name, remote: true })),
|
||||
]
|
||||
|
||||
const existingBranchNames = new Set([
|
||||
...localBranches.map((b) => b.name),
|
||||
...remoteBranchNames,
|
||||
@@ -219,11 +211,13 @@ export function CreateWorktreeDialog({
|
||||
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium">Base branch</label>
|
||||
<BaseBranchSelect
|
||||
<BranchCombobox
|
||||
repoId={repoId}
|
||||
enabled={open && canCreate}
|
||||
value={baseBranch}
|
||||
onValueChange={setBaseBranch}
|
||||
placeholder="Select a base branch"
|
||||
ariaLabel="Base branch"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
The new branch will be created from this branch.
|
||||
@@ -233,36 +227,16 @@ export function CreateWorktreeDialog({
|
||||
) : (
|
||||
<div className="space-y-1.5">
|
||||
<label className="text-sm font-medium">Branch to check out</label>
|
||||
<Select
|
||||
<BranchCombobox
|
||||
repoId={repoId}
|
||||
enabled={open && canCreate}
|
||||
value={existingBranch}
|
||||
onValueChange={setExistingBranch}
|
||||
disabled={branchesLoading}
|
||||
>
|
||||
<SelectTrigger
|
||||
aria-label="Branch to check out"
|
||||
className="bg-background border-border text-foreground"
|
||||
>
|
||||
<SelectValue
|
||||
placeholder={branchesLoading ? 'Loading branches...' : 'Select a branch to check out'}
|
||||
/>
|
||||
</SelectTrigger>
|
||||
<SelectContent className="bg-popover border-border">
|
||||
{checkoutCandidates.map((branch) => (
|
||||
<SelectItem
|
||||
key={`${branch.remote ? 'remote' : 'local'}-${branch.name}`}
|
||||
value={branch.name}
|
||||
>
|
||||
<div className="flex items-center gap-2">
|
||||
<GitBranch className={`w-3.5 h-3.5${branch.remote ? ' text-info' : ''}`} />
|
||||
<span>{branch.name}</span>
|
||||
{branch.remote && (
|
||||
<span className="text-xs text-muted-foreground">(remote)</span>
|
||||
)}
|
||||
</div>
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
placeholder="Select a branch to check out"
|
||||
include={isCheckoutCandidate}
|
||||
remotes="bare"
|
||||
ariaLabel="Branch to check out"
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
The worktree will check out the selected branch. Remote branches are limited to origin.
|
||||
</p>
|
||||
|
||||
@@ -12,7 +12,7 @@ import { Badge } from '@/components/ui/badge'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { ConfirmDestructiveDialog } from '@/components/ui/confirm-destructive-dialog'
|
||||
import { SessionStatusIndicator } from '@/components/ui/session-status-indicator'
|
||||
import { BaseBranchSelect } from '@/components/repo/BaseBranchSelect'
|
||||
import { BranchCombobox } from '@/components/repo/BranchCombobox'
|
||||
import { useProvidersWithModels } from '@/hooks/useProvidersWithModels'
|
||||
import { useOpenCodeModelState } from '@/hooks/useModelSelection'
|
||||
import { useDiscardMultiRunEntry, useLaunchMultiRun, useMultiRuns } from '@/hooks/useMultiRuns'
|
||||
@@ -279,12 +279,13 @@ export function MultiRunDialog({
|
||||
{isolate && (
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="multi-run-base-ref">Start from</Label>
|
||||
<BaseBranchSelect
|
||||
<BranchCombobox
|
||||
id="multi-run-base-ref"
|
||||
repoId={repoId}
|
||||
value={baseRef}
|
||||
onValueChange={setBaseRef}
|
||||
placeholder="Current HEAD"
|
||||
clearable
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">Each isolated workspace starts from this branch.</p>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Combobox, type ComboboxOption } from '@/components/ui/combobox'
|
||||
import { BranchCombobox } from '@/components/repo/BranchCombobox'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
@@ -21,8 +22,7 @@ type GeneralTabProps = {
|
||||
onEnabledChange: (value: boolean) => void
|
||||
branch: string
|
||||
onBranchChange: (value: string) => void
|
||||
branchOptions: ComboboxOption[]
|
||||
branchesLoading: boolean
|
||||
branchRepoId: number | undefined
|
||||
showRepoSelector?: boolean
|
||||
isEditing: boolean
|
||||
repoId?: number
|
||||
@@ -63,8 +63,7 @@ export function GeneralTab({
|
||||
onEnabledChange,
|
||||
branch,
|
||||
onBranchChange,
|
||||
branchOptions,
|
||||
branchesLoading,
|
||||
branchRepoId,
|
||||
showRepoSelector,
|
||||
isEditing,
|
||||
repoId,
|
||||
@@ -159,14 +158,14 @@ export function GeneralTab({
|
||||
<Label htmlFor="schedule-branch">Base branch</Label>
|
||||
<InfoHint text="Scheduled runs execute in an isolated worktree branched off this base branch. Leave empty to use the repository's default branch." />
|
||||
</div>
|
||||
<Combobox
|
||||
<BranchCombobox
|
||||
id="schedule-branch"
|
||||
repoId={branchRepoId}
|
||||
value={branch}
|
||||
onChange={onBranchChange}
|
||||
options={branchOptions}
|
||||
placeholder={branchesLoading ? 'Loading branches…' : 'Defaults to default branch'}
|
||||
disabled={branchesLoading}
|
||||
allowCustomValue={false}
|
||||
showClear
|
||||
onValueChange={onBranchChange}
|
||||
placeholder="Defaults to default branch"
|
||||
remotes="bare"
|
||||
clearable
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,7 @@ import { useAgents } from '@/hooks/useOpenCode'
|
||||
import { useScheduleTarget } from '@/hooks/useScheduleTarget'
|
||||
import { settingsApi } from '@/api/settings'
|
||||
import { mcpApi } from '@/api/mcp'
|
||||
import { listRepos, listBranches } from '@/api/repos'
|
||||
import { listRepos } from '@/api/repos'
|
||||
import type { Repo } from '@/api/types'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import type { ComboboxOption } from '@/components/ui/combobox'
|
||||
@@ -113,28 +113,6 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
staleTime: 5 * 60 * 1000,
|
||||
})
|
||||
|
||||
const branchesEnabled = open && effectiveRepoId !== undefined && effectiveRepoId !== ASSISTANT_REPO_ID
|
||||
|
||||
const { data: branchData, isLoading: branchesLoading } = useQuery({
|
||||
queryKey: ['branches', effectiveRepoId],
|
||||
queryFn: () => listBranches(effectiveRepoId!),
|
||||
enabled: branchesEnabled,
|
||||
staleTime: 60 * 1000,
|
||||
})
|
||||
|
||||
const branchOptions = useMemo<ComboboxOption[]>(() => {
|
||||
const names = new Set<string>()
|
||||
for (const gitBranch of branchData?.branches ?? []) {
|
||||
const name = gitBranch.name.replace(/^remotes\/[^/]+\//, '')
|
||||
if (name && name !== 'HEAD') {
|
||||
names.add(name)
|
||||
}
|
||||
}
|
||||
return Array.from(names)
|
||||
.sort((a, b) => a.localeCompare(b))
|
||||
.map((name) => ({ value: name, label: name }))
|
||||
}, [branchData])
|
||||
|
||||
const repoOptions = useMemo<ComboboxOption[]>(() => {
|
||||
const assistantOption: ComboboxOption = {
|
||||
value: ASSISTANT_REPO_ID.toString(),
|
||||
@@ -352,8 +330,7 @@ export function ScheduleJobDialog({ open, onOpenChange, job, isSaving, onSubmit,
|
||||
onEnabledChange={setEnabled}
|
||||
branch={branch}
|
||||
onBranchChange={setBranch}
|
||||
branchOptions={branchOptions}
|
||||
branchesLoading={branchesEnabled && branchesLoading}
|
||||
branchRepoId={open && effectiveRepoId !== ASSISTANT_REPO_ID ? effectiveRepoId : undefined}
|
||||
showRepoSelector={showRepoSelector}
|
||||
isEditing={!!job}
|
||||
repoId={selectedRepoId}
|
||||
|
||||
@@ -303,7 +303,7 @@ export function FormPrompt({ form, onReply, onCancel, onMinimize }: FormPromptPr
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="w-full bg-gradient-to-br from-primary/10 to-primary/20 border-2 border-primary/40 rounded-xl shadow-lg shadow-primary/20 mb-1 overflow-hidden">
|
||||
<div className="w-full bg-background bg-gradient-to-br from-primary/10 to-primary/20 border-2 border-primary/40 rounded-xl shadow-lg shadow-primary/20 mb-1 overflow-hidden">
|
||||
<div className="flex items-center px-3 py-2 sm:px-4 sm:py-2.5 border-b border-primary/20 bg-primary/5">
|
||||
<button
|
||||
onClick={() => (isMinimized ? setIsMinimized(false) : handleMinimize())}
|
||||
|
||||
@@ -10,7 +10,7 @@ interface MinimizedFormIndicatorProps {
|
||||
|
||||
export function MinimizedFormIndicator({ form, onRestore, onDismiss }: MinimizedFormIndicatorProps) {
|
||||
return (
|
||||
<div className="w-full bg-gradient-to-br from-highlight/10 to-highlight/20 border-2 border-highlight/40 rounded-lg shadow-lg mb-2 overflow-hidden">
|
||||
<div className="w-full bg-background bg-gradient-to-br from-highlight/10 to-highlight/20 border-2 border-highlight/40 rounded-lg shadow-lg mb-2 overflow-hidden">
|
||||
<div className="flex items-center px-3 py-2 sm:px-4 sm:py-2.5 border-b border-highlight/20 bg-highlight/5">
|
||||
<button
|
||||
onClick={onRestore}
|
||||
|
||||
@@ -1,15 +1,16 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useState } from 'react'
|
||||
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { RadioOptionGroup, type RadioOption } from '@/components/ui/radio-option-group'
|
||||
import { GitMerge, Loader2 } from 'lucide-react'
|
||||
import { getRepo, listBranches } from '@/api/repos'
|
||||
import { getRepo, type GitBranch } from '@/api/repos'
|
||||
import { getApiErrorMessage, useGitStatus } from '@/api/git'
|
||||
import { FetchError } from '@/api/fetchWrapper'
|
||||
import { showToast } from '@/lib/toast'
|
||||
import { useGit } from '@/hooks/useGit'
|
||||
import { useRepoBranches } from '@/hooks/useRepoBranches'
|
||||
import { BranchCombobox } from '@/components/repo/BranchCombobox'
|
||||
import { setRepoGitStatusCaches } from '@/lib/queryInvalidation'
|
||||
import { GitOperationBanner } from './GitOperationBanner'
|
||||
import type { GitOperationState } from '@opencode-manager/shared'
|
||||
@@ -46,12 +47,7 @@ export function IntegrateBranchDialog({ repoId, sourceBranch, open, onOpenChange
|
||||
staleTime: 30000,
|
||||
})
|
||||
|
||||
const { data: branchesData, isLoading: branchesLoading } = useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId),
|
||||
enabled: open,
|
||||
staleTime: 30000,
|
||||
})
|
||||
const { data: branchesData, isLoading: branchesLoading } = useRepoBranches(repoId, open)
|
||||
|
||||
const { data: targetStatus, dataUpdatedAt: targetStatusUpdatedAt } = useGitStatus(
|
||||
conflictTargetRepoId ?? undefined,
|
||||
@@ -61,9 +57,10 @@ export function IntegrateBranchDialog({ repoId, sourceBranch, open, onOpenChange
|
||||
const hasFreshTargetStatus = conflictTargetRepoId !== null && targetStatusUpdatedAt >= conflictStartedAt
|
||||
const activeOperation = hasFreshTargetStatus ? (targetStatus?.operation ?? null) : conflictSnapshot
|
||||
|
||||
const isTargetCandidate = useCallback((branch: GitBranch) => branch.name !== sourceBranch, [sourceBranch])
|
||||
const candidates = useMemo(
|
||||
() => (branchesData?.branches ?? []).filter((branch) => branch.type === 'local' && branch.name !== sourceBranch),
|
||||
[branchesData, sourceBranch]
|
||||
() => (branchesData?.branches ?? []).filter((branch) => branch.type === 'local' && isTargetCandidate(branch)),
|
||||
[branchesData, isTargetCandidate]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
@@ -140,22 +137,16 @@ export function IntegrateBranchDialog({ repoId, sourceBranch, open, onOpenChange
|
||||
<label className="text-sm font-medium" htmlFor="integrate-target-branch">
|
||||
Target branch
|
||||
</label>
|
||||
<Select value={targetBranch} onValueChange={setTargetBranch} disabled={branchesLoading}>
|
||||
<SelectTrigger
|
||||
id="integrate-target-branch"
|
||||
aria-label="Target branch"
|
||||
className="bg-background border-border text-foreground"
|
||||
>
|
||||
<SelectValue placeholder={branchesLoading ? 'Loading branches...' : 'Select a target branch'} />
|
||||
</SelectTrigger>
|
||||
<SelectContent className="bg-popover border-border">
|
||||
{candidates.map((branch) => (
|
||||
<SelectItem key={branch.name} value={branch.name}>
|
||||
{branch.name}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<BranchCombobox
|
||||
id="integrate-target-branch"
|
||||
repoId={repoId}
|
||||
enabled={open}
|
||||
value={targetBranch}
|
||||
onValueChange={setTargetBranch}
|
||||
placeholder="Select a target branch"
|
||||
include={isTargetCandidate}
|
||||
remotes="none"
|
||||
/>
|
||||
{!branchesLoading && candidates.length === 0 && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
No other local branches are available to integrate into.
|
||||
|
||||
@@ -41,6 +41,17 @@ describe('Combobox', () => {
|
||||
expect(input).toHaveValue('Built-in Browser')
|
||||
})
|
||||
|
||||
it('filters options as the user types', async () => {
|
||||
const user = userEvent.setup()
|
||||
const input = renderCombobox()
|
||||
|
||||
await user.clear(input)
|
||||
await user.type(input, 'ext')
|
||||
|
||||
expect(screen.getByRole('option', { name: 'External API' })).toBeInTheDocument()
|
||||
expect(screen.queryByRole('option', { name: 'Built-in Browser' })).not.toBeInTheDocument()
|
||||
})
|
||||
|
||||
it('calls onOpen each time the options open', async () => {
|
||||
const user = userEvent.setup()
|
||||
const onOpen = vi.fn()
|
||||
|
||||
@@ -20,6 +20,7 @@ interface ComboboxProps {
|
||||
showClear?: boolean
|
||||
ariaLabel?: string
|
||||
onOpen?: () => void
|
||||
id?: string
|
||||
}
|
||||
|
||||
function getOptionLabel(options: ComboboxOption[], value: string): string {
|
||||
@@ -37,6 +38,7 @@ export function Combobox({
|
||||
showClear = false,
|
||||
ariaLabel,
|
||||
onOpen,
|
||||
id,
|
||||
}: ComboboxProps) {
|
||||
const [isOpen, setIsOpen] = useState(false)
|
||||
const [inputValue, setInputValue] = useState(() => getOptionLabel(options, value))
|
||||
@@ -185,6 +187,7 @@ export function Combobox({
|
||||
<div className="relative">
|
||||
<input
|
||||
ref={inputRef}
|
||||
id={id}
|
||||
type="text"
|
||||
value={inputValue}
|
||||
onChange={handleInputChange}
|
||||
@@ -244,6 +247,7 @@ export function Combobox({
|
||||
{isOpen && flatFilteredOptions.length > 0 && (
|
||||
<div
|
||||
ref={listRef}
|
||||
role="listbox"
|
||||
className="absolute z-[150] mt-1 w-full bg-popover border border-border rounded-md shadow-lg max-h-60 overflow-y-auto"
|
||||
>
|
||||
{Object.entries(groupedOptions).map(([group, groupOptions]) => (
|
||||
@@ -263,6 +267,8 @@ export function Combobox({
|
||||
key={option.value}
|
||||
data-option
|
||||
type="button"
|
||||
role="option"
|
||||
aria-selected={option.value === value}
|
||||
onClick={() => handleSelect(option.value)}
|
||||
className={cn(
|
||||
'w-full scroll-mt-7 px-3 py-2 text-left text-sm transition-colors',
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { listBranches } from '@/api/repos'
|
||||
|
||||
export function useRepoBranches(repoId: number | undefined, enabled = true) {
|
||||
return useQuery({
|
||||
queryKey: ['branches', repoId],
|
||||
queryFn: () => listBranches(repoId!),
|
||||
enabled: enabled && repoId !== undefined,
|
||||
staleTime: 30000,
|
||||
})
|
||||
}
|
||||
Reference in new issue
Block a user