Skip to content

Commit f70cb5d

Browse files
Refine branch picker behavior and gate /checkout-pr by thread type
- Add shared branch picker filtering logic and tests, including PR-reference-only results - Improve branch selector UX/perf with deferred query filtering, conditional virtualization, and status-based current branch resolution - Only expose and handle `/checkout-pr` for local draft threads in chat and toolbar UI
1 parent 3d35868 commit f70cb5d

4 files changed

Lines changed: 206 additions & 125 deletions

File tree

‎apps/web/src/components/BranchToolbar.logic.test.ts‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { GitBranch } from "@t3tools/contracts";
22
import { describe, expect, it } from "vitest";
33
import {
4+
filterBranchPickerItems,
45
dedupeRemoteBranchesWithLocalMatches,
56
deriveLocalBranchNameFromRemoteRef,
67
resolveDraftEnvModeAfterBranchChange,
@@ -194,3 +195,31 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
194195
]);
195196
});
196197
});
198+
199+
describe("filterBranchPickerItems", () => {
200+
it("shows only the pull request action when the query is a PR reference", () => {
201+
expect(
202+
filterBranchPickerItems({
203+
itemValues: [
204+
"__checkout_pull_request__:488",
205+
"codething/76f09488",
206+
"origin/cursor/rollback-error",
207+
],
208+
normalizedQuery: "488",
209+
createBranchItemValue: null,
210+
checkoutPullRequestItemValue: "__checkout_pull_request__:488",
211+
}),
212+
).toEqual(["__checkout_pull_request__:488"]);
213+
});
214+
215+
it("filters branch items normally when the query is not a PR reference", () => {
216+
expect(
217+
filterBranchPickerItems({
218+
itemValues: ["feature/488", "main", "__create_new_branch__:48"],
219+
normalizedQuery: "48",
220+
createBranchItemValue: "__create_new_branch__:48",
221+
checkoutPullRequestItemValue: null,
222+
}),
223+
).toEqual(["feature/488", "__create_new_branch__:48"]);
224+
});
225+
});

‎apps/web/src/components/BranchToolbar.logic.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,27 @@ export function dedupeRemoteBranchesWithLocalMatches(
8888
return !localBranchCandidates.some((candidate) => localBranchNames.has(candidate));
8989
});
9090
}
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+
}

0 commit comments

Comments
 (0)