authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-09 14:57:59-07:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-09 22:50:45-07:00
logac3f22c274e5b116b04220b29d1470e9d39bd0f2
treefb684a6ce6adf9b541cd5ca48af9c9936943e442
parentb36888e9cc3692f931081a4d09bd58438d5f06eb

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

3 files changed, 7 insertions(+), 66 deletions(-)

apps/web/src/components/BranchToolbar.logic.test.ts-29
......@@ -1,7 +1,6 @@
11import type { GitBranch } from "@t3tools/contracts";
22import { describe, expect, it } from "vitest";
33import {
4 filterBranchPickerItems,
54 dedupeRemoteBranchesWithLocalMatches,
65 deriveLocalBranchNameFromRemoteRef,
76 resolveBranchSelectionTarget,
......@@ -197,34 +196,6 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
197196 });
198197});
199198
200describe("filterBranchPickerItems", () => {
201 it("shows only the pull request action when the query is a PR reference", () => {
202 expect(
203 filterBranchPickerItems({
204 itemValues: [
205 "__checkout_pull_request__:488",
206 "codething/76f09488",
207 "origin/cursor/rollback-error",
208 ],
209 normalizedQuery: "488",
210 createBranchItemValue: null,
211 checkoutPullRequestItemValue: "__checkout_pull_request__:488",
212 }),
213 ).toEqual(["__checkout_pull_request__:488"]);
214 });
215
216 it("filters branch items normally when the query is not a PR reference", () => {
217 expect(
218 filterBranchPickerItems({
219 itemValues: ["feature/488", "main", "__create_new_branch__:48"],
220 normalizedQuery: "48",
221 createBranchItemValue: "__create_new_branch__:48",
222 checkoutPullRequestItemValue: null,
223 }),
224 ).toEqual(["feature/488", "__create_new_branch__:48"]);
225 });
226});
227
228199describe("resolveBranchSelectionTarget", () => {
229200 it("reuses an existing secondary worktree for the selected branch", () => {
230201 expect(
apps/web/src/components/BranchToolbar.logic.ts-24
......@@ -89,30 +89,6 @@ export function dedupeRemoteBranchesWithLocalMatches(
8989 });
9090}
9191
92export function filterBranchPickerItems(input: {
93 itemValues: ReadonlyArray<string>;
94 normalizedQuery: string;
95 createBranchItemValue: string | null;
96 checkoutPullRequestItemValue: string | null;
97}): ReadonlyArray<string> {
98 const { itemValues, normalizedQuery, createBranchItemValue, checkoutPullRequestItemValue } = input;
99
100 if (checkoutPullRequestItemValue) {
101 return [checkoutPullRequestItemValue];
102 }
103
104 if (normalizedQuery.length === 0) {
105 return itemValues;
106 }
107
108 return itemValues.filter((itemValue) => {
109 if (createBranchItemValue && itemValue === createBranchItemValue) {
110 return true;
111 }
112 return itemValue.toLowerCase().includes(normalizedQuery);
113 });
114}
115
11692export function resolveBranchSelectionTarget(input: {
11793 activeProjectCwd: string;
11894 activeWorktreePath: string | null;
apps/web/src/components/BranchToolbarBranchSelector.tsx+7-13
......@@ -26,7 +26,6 @@ import {
2626 dedupeRemoteBranchesWithLocalMatches,
2727 deriveLocalBranchNameFromRemoteRef,
2828 EnvMode,
29 filterBranchPickerItems,
3029 resolveBranchSelectionTarget,
3130 resolveBranchToolbarValue,
3231} from "./BranchToolbar.logic";
......@@ -137,18 +136,13 @@ export function BranchToolbarBranchSelector({
137136 );
138137 const filteredBranchPickerItems = useMemo(
139138 () =>
140 filterBranchPickerItems({
141 itemValues: branchPickerItems,
142 normalizedQuery: normalizedDeferredBranchQuery,
143 createBranchItemValue,
144 checkoutPullRequestItemValue,
145 }),
146 [
147 branchPickerItems,
148 checkoutPullRequestItemValue,
149 createBranchItemValue,
150 normalizedDeferredBranchQuery,
151 ],
139 normalizedDeferredBranchQuery.length === 0
140 ? branchPickerItems
141 : branchPickerItems.filter((itemValue) => {
142 if (createBranchItemValue && itemValue === createBranchItemValue) return true;
143 return itemValue.toLowerCase().includes(normalizedDeferredBranchQuery);
144 }),
145 [branchPickerItems, createBranchItemValue, normalizedDeferredBranchQuery],
152146 );
153147 const [resolvedActiveBranch, setOptimisticBranch] = useOptimistic(
154148 canonicalActiveBranch,