fix: Fix exposing explicit search button in gh branch dropdown (#435)

* fix: Fix exposing explicit search button in gh branch dropdown

* cr
This commit is contained in:
Brace Sproul 2025-07-16 17:49:17 -07:00 • committed by GitHub
parent b128e4ae45
commit 0953468b5c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -20,6 +20,7 @@ import { GitBranch, Shield } from "lucide-react";
import { TargetRepository } from "@open-swe/shared/open-swe/types";
import { Branch } from "@/utils/github";
import { toast } from "sonner";
import { defaultFilter } from "cmdk";
interface BranchSelectorProps {
disabled?: boolean;
@ -123,6 +124,14 @@ export function BranchSelector({
}
};
// Whether or not to allow explicitly searching for a branch, even when there are results.
const allowExplicitSearchReqWithResults = !!(
searchQuery.trim() &&
branches.some(
(branch) => defaultFilter(branch.name, searchQuery.trim()) > 0,
)
);
if (!selectedRepository) {
return (
<Button
@ -300,25 +309,22 @@ export function BranchSelector({
</CommandGroup>
{/* Show this search button if there is a search query, and there are some results. this is for
cases when some results do show, just not the exact result the user is looking for */}
{searchQuery.trim() &&
branches.some((branch) =>
branch.name.toLowerCase().includes(searchQuery.toLowerCase()),
) && (
<div className="px-2 py-1">
<Button
variant="outline"
size="sm"
onClick={handleSearchForBranch}
disabled={isSearching}
className="w-full text-xs"
>
{isSearching
? "Searching..."
: `Search for "${searchQuery.trim()}"`}
</Button>
</div>
)}
{branchesHasMore && (
{allowExplicitSearchReqWithResults && (
<div className="px-2 py-1">
<Button
variant="outline"
size="sm"
onClick={handleSearchForBranch}
disabled={isSearching}
className="w-full text-xs"
>
{isSearching
? "Searching..."
: `Search for "${searchQuery.trim()}"`}
</Button>
</div>
)}
{branchesHasMore && !allowExplicitSearchReqWithResults && (
<CommandGroup>
<CommandItem
onSelect={() => {