| author | |
| committer | |
| log | ac3f22c274e5b116b04220b29d1470e9d39bd0f2 |
| tree | fb684a6ce6adf9b541cd5ca48af9c9936943e442 |
| parent | b36888e9cc3692f931081a4d09bd58438d5f06eb |
- move branch filtering logic into `BranchToolbarBranchSelector`
- remove unused `filterBranchPickerItems` helper and related tests
- keep create-branch option pinned while filtering by query3 files changed, 7 insertions(+), 66 deletions(-)
apps/web/src/components/BranchToolbar.logic.test.ts-29| ... | ... | @@ -1,7 +1,6 @@ |
| 1 | 1 | import type { GitBranch } from "@t3tools/contracts"; |
| 2 | 2 | import { describe, expect, it } from "vitest"; |
| 3 | 3 | import { |
| 4 | filterBranchPickerItems, | |
| 5 | 4 | dedupeRemoteBranchesWithLocalMatches, |
| 6 | 5 | deriveLocalBranchNameFromRemoteRef, |
| 7 | 6 | resolveBranchSelectionTarget, |
| ... | ... | @@ -197,34 +196,6 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => { |
| 197 | 196 | }); |
| 198 | 197 | }); |
| 199 | 198 | |
| 200 | describe("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 | ||
| 228 | 199 | describe("resolveBranchSelectionTarget", () => { |
| 229 | 200 | it("reuses an existing secondary worktree for the selected branch", () => { |
| 230 | 201 | expect( |
apps/web/src/components/BranchToolbar.logic.ts-24| ... | ... | @@ -89,30 +89,6 @@ export function dedupeRemoteBranchesWithLocalMatches( |
| 89 | 89 | }); |
| 90 | 90 | } |
| 91 | 91 | |
| 92 | export 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 | ||
| 116 | 92 | export function resolveBranchSelectionTarget(input: { |
| 117 | 93 | activeProjectCwd: string; |
| 118 | 94 | activeWorktreePath: string | null; |
apps/web/src/components/BranchToolbarBranchSelector.tsx+7-13| ... | ... | @@ -26,7 +26,6 @@ import { |
| 26 | 26 | dedupeRemoteBranchesWithLocalMatches, |
| 27 | 27 | deriveLocalBranchNameFromRemoteRef, |
| 28 | 28 | EnvMode, |
| 29 | filterBranchPickerItems, | |
| 30 | 29 | resolveBranchSelectionTarget, |
| 31 | 30 | resolveBranchToolbarValue, |
| 32 | 31 | } from "./BranchToolbar.logic"; |
| ... | ... | @@ -137,18 +136,13 @@ export function BranchToolbarBranchSelector({ |
| 137 | 136 | ); |
| 138 | 137 | const filteredBranchPickerItems = useMemo( |
| 139 | 138 | () => |
| 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], | |
| 152 | 146 | ); |
| 153 | 147 | const [resolvedActiveBranch, setOptimisticBranch] = useOptimistic( |
| 154 | 148 | canonicalActiveBranch, |