diff --git a/frontend/src/components/source-control/BranchesTab.tsx b/frontend/src/components/source-control/BranchesTab.tsx index 5d91d953..5623a302 100644 --- a/frontend/src/components/source-control/BranchesTab.tsx +++ b/frontend/src/components/source-control/BranchesTab.tsx @@ -1,4 +1,4 @@ -import { useState } from 'react' +import { useMemo, useState } from 'react' import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query' import { listBranches, switchBranch, GitAuthError, getRepo } from '@/api/repos' import { fetchGitStatus, useGitStatus } from '@/api/git' @@ -20,6 +20,7 @@ interface BranchesTabProps { export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) { const queryClient = useQueryClient() const [newBranchName, setNewBranchName] = useState('') + const [searchQuery, setSearchQuery] = useState('') const [isCreating, setIsCreating] = useState(false) const [worktreeDialogOpen, setWorktreeDialogOpen] = useState(false) const git = useGit(repoId) @@ -41,6 +42,13 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) { const repoUrl = repo?.repoUrl ?? null const isRepoWorktree = repo?.isWorktree ?? false + const filteredBranches = useMemo(() => { + const allBranches = branches?.branches ?? [] + if (!searchQuery.trim()) return allBranches + const query = searchQuery.toLowerCase() + return allBranches.filter((branch) => branch.name.toLowerCase().includes(query)) + }, [branches, searchQuery]) + const switchBranchMutation = useMutation({ mutationFn: async (branch: string) => { const updatedRepo = await switchBranch(repoId, branch) @@ -183,6 +191,16 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) { )} )} + {branches?.branches && branches.branches.length > 0 && ( +
+ setSearchQuery(e.target.value)} + className="h-8 md:text-sm" + /> +
+ )}
@@ -191,9 +209,9 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) {
)} - {branches?.branches && branches.branches.length > 0 ? ( + {filteredBranches.length > 0 ? (
- {branches.branches.map((branch) => { + {filteredBranches.map((branch) => { const isCurrent = branch.name === activeBranch || branch.name === `remotes/${activeBranch}` const isRemote = branch.type === 'remote' const checkoutName = isRemote ? branch.name.replace(/^remotes\/[^/]+\//, '') : branch.name @@ -237,7 +255,11 @@ export function BranchesTab({ repoId, currentBranch }: BranchesTabProps) { ) : (
-

No branches found

+ {searchQuery.trim() ? ( +

No branches match "{searchQuery.trim()}"

+ ) : ( +

No branches found

+ )}
)}