From 27860224dc812d318dbf38e1ab25b62bdf2091da Mon Sep 17 00:00:00 2001 From: Chris Scott <99081550+chriswritescode-dev@users.noreply.github.com> Date: Sun, 4 Oct 2026 16:34:22 -0400 Subject: [PATCH] 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. --- .../src/components/repo/BaseBranchSelect.tsx | 54 -------------- .../src/components/repo/BranchCombobox.tsx | 74 +++++++++++++++++++ .../components/repo/CreateWorktreeDialog.tsx | 66 +++++------------ .../src/components/repo/MultiRunDialog.tsx | 5 +- .../src/components/schedules/GeneralTab.tsx | 21 +++--- .../schedules/ScheduleJobDialog.tsx | 27 +------ .../src/components/session/FormPrompt.tsx | 2 +- .../session/MinimizedFormIndicator.tsx | 2 +- .../source-control/IntegrateBranchDialog.tsx | 45 +++++------ frontend/src/components/ui/combobox.test.tsx | 11 +++ frontend/src/components/ui/combobox.tsx | 6 ++ frontend/src/hooks/useRepoBranches.ts | 11 +++ 12 files changed, 157 insertions(+), 167 deletions(-) delete mode 100644 frontend/src/components/repo/BaseBranchSelect.tsx create mode 100644 frontend/src/components/repo/BranchCombobox.tsx create mode 100644 frontend/src/hooks/useRepoBranches.ts diff --git a/frontend/src/components/repo/BaseBranchSelect.tsx b/frontend/src/components/repo/BaseBranchSelect.tsx deleted file mode 100644 index 4daa84f3..00000000 --- a/frontend/src/components/repo/BaseBranchSelect.tsx +++ /dev/null @@ -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 ( - - ) -} diff --git a/frontend/src/components/repo/BranchCombobox.tsx b/frontend/src/components/repo/BranchCombobox.tsx new file mode 100644 index 00000000..ea74d13f --- /dev/null +++ b/frontend/src/components/repo/BranchCombobox.tsx @@ -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(() => { + 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 ( + + ) +} diff --git a/frontend/src/components/repo/CreateWorktreeDialog.tsx b/frontend/src/components/repo/CreateWorktreeDialog.tsx index 35df6a93..1e111de1 100644 --- a/frontend/src/components/repo/CreateWorktreeDialog.tsx +++ b/frontend/src/components/repo/CreateWorktreeDialog.tsx @@ -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({
-

The new branch will be created from this branch. @@ -233,36 +227,16 @@ export function CreateWorktreeDialog({ ) : (

- + placeholder="Select a branch to check out" + include={isCheckoutCandidate} + remotes="bare" + ariaLabel="Branch to check out" + />

The worktree will check out the selected branch. Remote branches are limited to origin.

diff --git a/frontend/src/components/repo/MultiRunDialog.tsx b/frontend/src/components/repo/MultiRunDialog.tsx index 4814b797..8c70a8ed 100644 --- a/frontend/src/components/repo/MultiRunDialog.tsx +++ b/frontend/src/components/repo/MultiRunDialog.tsx @@ -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 && (
-

Each isolated workspace starts from this branch.

diff --git a/frontend/src/components/schedules/GeneralTab.tsx b/frontend/src/components/schedules/GeneralTab.tsx index ab545906..2767d68c 100644 --- a/frontend/src/components/schedules/GeneralTab.tsx +++ b/frontend/src/components/schedules/GeneralTab.tsx @@ -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({
-
diff --git a/frontend/src/components/schedules/ScheduleJobDialog.tsx b/frontend/src/components/schedules/ScheduleJobDialog.tsx index b9141057..7ae7ec97 100644 --- a/frontend/src/components/schedules/ScheduleJobDialog.tsx +++ b/frontend/src/components/schedules/ScheduleJobDialog.tsx @@ -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(() => { - const names = new Set() - 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(() => { 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} diff --git a/frontend/src/components/session/FormPrompt.tsx b/frontend/src/components/session/FormPrompt.tsx index 5c4853ca..b6648068 100644 --- a/frontend/src/components/session/FormPrompt.tsx +++ b/frontend/src/components/session/FormPrompt.tsx @@ -303,7 +303,7 @@ export function FormPrompt({ form, onReply, onCancel, onMinimize }: FormPromptPr } return ( -
+