From ac3f22c274e5b116b04220b29d1470e9d39bd0f2 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 9 Mar 2026 14:57:59 -0700 Subject: [PATCH] Inline branch picker filtering and drop PR-only shortcut - move branch filtering logic into `BranchToolbarBranchSelector` - remove unused `filterBranchPickerItems` helper and related tests - keep create-branch option pinned while filtering by query --- .../components/BranchToolbar.logic.test.ts | 29 ------------------- .../web/src/components/BranchToolbar.logic.ts | 24 --------------- .../BranchToolbarBranchSelector.tsx | 20 +++++-------- 3 files changed, 7 insertions(+), 66 deletions(-) diff --git a/apps/web/src/components/BranchToolbar.logic.test.ts b/apps/web/src/components/BranchToolbar.logic.test.ts index e940fe2c3c597f8d490e64d422e0c4335a7bf3ac..b61e11c73f08985664a10dee57abaa990824b150 100644 --- a/apps/web/src/components/BranchToolbar.logic.test.ts +++ b/apps/web/src/components/BranchToolbar.logic.test.ts @@ -1,7 +1,6 @@ import type { GitBranch } from "@t3tools/contracts"; import { describe, expect, it } from "vitest"; import { - filterBranchPickerItems, dedupeRemoteBranchesWithLocalMatches, deriveLocalBranchNameFromRemoteRef, resolveBranchSelectionTarget, @@ -197,34 +196,6 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => { }); }); -describe("filterBranchPickerItems", () => { - it("shows only the pull request action when the query is a PR reference", () => { - expect( - filterBranchPickerItems({ - itemValues: [ - "__checkout_pull_request__:488", - "codething/76f09488", - "origin/cursor/rollback-error", - ], - normalizedQuery: "488", - createBranchItemValue: null, - checkoutPullRequestItemValue: "__checkout_pull_request__:488", - }), - ).toEqual(["__checkout_pull_request__:488"]); - }); - - it("filters branch items normally when the query is not a PR reference", () => { - expect( - filterBranchPickerItems({ - itemValues: ["feature/488", "main", "__create_new_branch__:48"], - normalizedQuery: "48", - createBranchItemValue: "__create_new_branch__:48", - checkoutPullRequestItemValue: null, - }), - ).toEqual(["feature/488", "__create_new_branch__:48"]); - }); -}); - describe("resolveBranchSelectionTarget", () => { it("reuses an existing secondary worktree for the selected branch", () => { expect( diff --git a/apps/web/src/components/BranchToolbar.logic.ts b/apps/web/src/components/BranchToolbar.logic.ts index 79acb487c27517d680e34d84d332fbfa3a7cad1d..64ec2956c6da42e7a2255e896099338323ca18df 100644 --- a/apps/web/src/components/BranchToolbar.logic.ts +++ b/apps/web/src/components/BranchToolbar.logic.ts @@ -89,30 +89,6 @@ export function dedupeRemoteBranchesWithLocalMatches( }); } -export function filterBranchPickerItems(input: { - itemValues: ReadonlyArray; - normalizedQuery: string; - createBranchItemValue: string | null; - checkoutPullRequestItemValue: string | null; -}): ReadonlyArray { - const { itemValues, normalizedQuery, createBranchItemValue, checkoutPullRequestItemValue } = input; - - if (checkoutPullRequestItemValue) { - return [checkoutPullRequestItemValue]; - } - - if (normalizedQuery.length === 0) { - return itemValues; - } - - return itemValues.filter((itemValue) => { - if (createBranchItemValue && itemValue === createBranchItemValue) { - return true; - } - return itemValue.toLowerCase().includes(normalizedQuery); - }); -} - export function resolveBranchSelectionTarget(input: { activeProjectCwd: string; activeWorktreePath: string | null; diff --git a/apps/web/src/components/BranchToolbarBranchSelector.tsx b/apps/web/src/components/BranchToolbarBranchSelector.tsx index 766b284816df429dc0c46c47fd584af6f38bb206..1817e29077cdf4bc98a5fd2058c6401deb39d6a1 100644 --- a/apps/web/src/components/BranchToolbarBranchSelector.tsx +++ b/apps/web/src/components/BranchToolbarBranchSelector.tsx @@ -26,7 +26,6 @@ import { dedupeRemoteBranchesWithLocalMatches, deriveLocalBranchNameFromRemoteRef, EnvMode, - filterBranchPickerItems, resolveBranchSelectionTarget, resolveBranchToolbarValue, } from "./BranchToolbar.logic"; @@ -137,18 +136,13 @@ export function BranchToolbarBranchSelector({ ); const filteredBranchPickerItems = useMemo( () => - filterBranchPickerItems({ - itemValues: branchPickerItems, - normalizedQuery: normalizedDeferredBranchQuery, - createBranchItemValue, - checkoutPullRequestItemValue, - }), - [ - branchPickerItems, - checkoutPullRequestItemValue, - createBranchItemValue, - normalizedDeferredBranchQuery, - ], + normalizedDeferredBranchQuery.length === 0 + ? branchPickerItems + : branchPickerItems.filter((itemValue) => { + if (createBranchItemValue && itemValue === createBranchItemValue) return true; + return itemValue.toLowerCase().includes(normalizedDeferredBranchQuery); + }), + [branchPickerItems, createBranchItemValue, normalizedDeferredBranchQuery], ); const [resolvedActiveBranch, setOptimisticBranch] = useOptimistic( canonicalActiveBranch, -- 2.54.0