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