@devries-cameron20 / t3code Mirror · read-only / commits / 12bd9d6a61
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 13:15 UTC

fix(mobile): list pull request repositories once per environment (#25219)

Co-authored-by: Tristan Knight <18444302+tris203@users.noreply.github.com>

maria committed Oct 29, 2026 at 18:01 UTC 12bd9d6a618ad0f2eadf34d31f6c428a12a8d150
7 files changed +100 -12
apps/mobile/src/features/pull-requests/PullRequestsScreen.tsx
+9 -4
@@ -44,6 +44,7 @@ import {
44 scopedPullRequestListKey as pullRequestKey,
45 type EnvironmentPullRequestListEntry,
46 withoutScratchProjectScope,
47 + pullRequestProjectChoices,
48 } from "./pullRequestList";
49 import { useDebouncedValue } from "../../state/queries";
50 import { useWorkspaceTabs } from "../workspace/WorkspaceTabsContext";
@@ -221,10 +222,14 @@ export function PullRequestsScreen(
222 }
223 const labelColors =
224 knownFacets.environmentId === environmentId ? knownFacets.labelColors : facets.labelColors;
224 - const projects = allProjects.filter(
225 - (project) =>
226 - !project.isScratch && (environmentId === null || project.environmentId === environmentId),
227 - );
225 + const projects = pullRequestProjectChoices(allProjects, {
226 + environmentId,
227 + controls,
228 + environmentLabels: new Map(
229 + environments.map((item) => [item.environmentId, item.environmentLabel]),
230 + ),
231 + servesPullRequests: (id) => configs.get(id)?.environment.capabilities.pullRequests === true,
232 + });
233 const filters = usePullRequestListFilters({
234 environments: environments.map((item) => ({
235 id: String(item.environmentId),
apps/mobile/src/features/pull-requests/pullRequestList.test.ts
+49
@@ -1,6 +1,7 @@
1 import { describe, expect, it } from "vite-plus/test";
2 import {
3 EnvironmentId,
4 + ProjectId,
5 SourceControlProviderKind,
6 type PullRequestListEntry,
7 type PullRequestListResult,
@@ -26,6 +27,7 @@ import {
27 withListedPullRequests,
28 withShownPullRequestStats,
29 withoutScratchProjectScope,
30 + pullRequestProjectChoices,
31 } from "./pullRequestList";
32
33 function entry(number: number, patch: Partial<PullRequestListEntry> = {}): PullRequestListEntry {
@@ -402,6 +404,53 @@ describe("pullRequestFilterChoices", () => {
404 });
405 });
406
407 +describe("pullRequestProjectChoices", () => {
408 + const laptop = EnvironmentId.make("env-laptop");
409 + const desktop = EnvironmentId.make("env-desktop");
410 + const project = (id: string, environmentId: EnvironmentId) => ({
411 + id: ProjectId.make(id),
412 + environmentId,
413 + title: "t3code",
414 + workspaceRoot: `/work/${id}`,
415 + repositoryIdentity: { canonicalKey: "github.com/pingdotgg/t3code" },
416 + });
417 + const projects = [project("main", laptop), project("worktree", laptop), project("main", desktop)];
418 + const choices = (
419 + servesPullRequests: (environmentId: EnvironmentId) => boolean,
420 + scope: { projectId?: string; projectEnvironmentId?: string } = {},
421 + ) =>
422 + pullRequestProjectChoices(projects, {
423 + environmentId: null,
424 + controls: { ...DEFAULT_PR_LIST_CONTROLS, ...scope },
425 + environmentLabels: new Map([
426 + [laptop, "laptop"],
427 + [desktop, "desktop"],
428 + ]),
429 + servesPullRequests,
430 + }).map(({ id, environmentId, title }) => ({ id, environmentId, title }));
431 +
432 + it("lists each repository once per environment that serves pull requests", () => {
433 + expect(choices(() => true)).toEqual([
434 + { id: "main", environmentId: desktop, title: "t3code · desktop" },
435 + { id: "main", environmentId: laptop, title: "t3code · laptop" },
436 + ]);
437 + expect(choices((environmentId) => environmentId === desktop)).toEqual([
438 + { id: "main", environmentId: desktop, title: "t3code" },
439 + ]);
440 + });
441 +
442 + it("keeps the saved scope when its environment stops serving or has not loaded", () => {
443 + const scope = { projectId: "worktree", projectEnvironmentId: laptop };
444 + expect(choices((environmentId) => environmentId === desktop, scope)).toEqual([
445 + { id: "main", environmentId: desktop, title: "t3code · desktop" },
446 + { id: "worktree", environmentId: laptop, title: "t3code · laptop" },
447 + ]);
448 + expect(choices(() => false, scope)).toEqual([
449 + { id: "worktree", environmentId: laptop, title: "t3code" },
450 + ]);
451 + });
452 +});
453 +
454 describe("shown PR diff stats", () => {
455 const cups = EnvironmentId.make("cups");
456 const stat = (number: number, additions: number, deletions: number) => ({
apps/mobile/src/features/pull-requests/pullRequestList.ts
+29
@@ -1,3 +1,4 @@
1 +import { pullRequestFilterProjects } from "@t3tools/client-runtime/pull-request-project-filter";
2 import { parsePullRequestQuery } from "@t3tools/client-runtime/pull-request-query";
3 import {
4 ProjectId,
@@ -34,6 +35,34 @@ export function withoutScratchProjectScope(
35 : controls;
36 }
37
38 +type FilterProject = Parameters<typeof pullRequestFilterProjects>[0][number];
39 +
40 +export function pullRequestProjectChoices<
41 + Project extends FilterProject & { readonly isScratch?: true },
42 +>(
43 + projects: readonly Project[],
44 + input: {
45 + readonly environmentId: string | null;
46 + readonly controls: PullRequestListControls;
47 + readonly environmentLabels: ReadonlyMap<EnvironmentId, string>;
48 + readonly servesPullRequests: (environmentId: EnvironmentId) => boolean;
49 + },
50 +) {
51 + const isSelected = (project: Project) =>
52 + project.id === input.controls.projectId &&
53 + project.environmentId === input.controls.projectEnvironmentId;
54 + return pullRequestFilterProjects(
55 + projects.filter(
56 + (project) =>
57 + !project.isScratch &&
58 + (input.environmentId === null || project.environmentId === input.environmentId) &&
59 + (input.servesPullRequests(project.environmentId) || isSelected(project)),
60 + ),
61 + input.environmentLabels,
62 + projects.find(isSelected),
63 + );
64 +}
65 +
66 export function pullRequestListKey(
67 item: Pick<PullRequestListEntry, "host" | "repository" | "number">,
68 ) {
apps/web/src/components/pullRequest/pullRequestProjectFilter.logic.test.ts
+1 -1
@@ -2,7 +2,7 @@ import { EnvironmentId, ProjectId } from "@t3tools/contracts";
2 import { describe, expect, it } from "vite-plus/test";
3
4 import { findScopedProject } from "./pullRequestList.logic";
5 -import { pullRequestFilterProjects } from "./pullRequestProjectFilter.logic";
5 +import { pullRequestFilterProjects } from "@t3tools/client-runtime/pull-request-project-filter";
6
7 const cups = EnvironmentId.make("env-cups");
8 const nucbox = EnvironmentId.make("env-nucbox");
apps/web/src/components/pullRequest/usePullRequestListView.ts
+1 -1
@@ -36,7 +36,7 @@ import {
36 import type { PullRequestExpectedHost } from "./PullRequestListFilters";
37 import type { PullRequestListPreferences, PullRequestListSort } from "./pullRequestListPreferences";
38 import { assignProjectsToEnvironments } from "./pullRequestProjectAssignment.logic";
39 -import { pullRequestFilterProjects } from "./pullRequestProjectFilter.logic";
39 +import { pullRequestFilterProjects } from "@t3tools/client-runtime/pull-request-project-filter";
40 import { pullRequestListEntryId } from "./pullRequestListGroups.logic";
41
42 export interface PullRequestsSearch extends PullRequestListPreferences {
packages/client-runtime/package.json
+4
@@ -415,6 +415,10 @@
415 "types": "./src/threadReference.ts",
416 "default": "./src/threadReference.ts"
417 },
418 + "./pull-request-project-filter": {
419 + "types": "./src/pullRequestProjectFilter.ts",
420 + "default": "./src/pullRequestProjectFilter.ts"
421 + },
422 "./thread-pull-request-compatibility": {
423 "types": "./src/threadPullRequestCompatibility.ts",
424 "default": "./src/threadPullRequestCompatibility.ts"
packages/client-runtime/src/pullRequestProjectFilter.ts renamed
+7 -6
@@ -1,8 +1,9 @@
1 -import type { EnvironmentId } from "@t3tools/contracts";
1 +import type { EnvironmentId, ProjectId } from "@t3tools/contracts";
2
3 -import type { AssignableProject } from "./pullRequestProjectAssignment.logic";
4 -
5 -interface FilterProject extends AssignableProject {
3 +interface FilterProject {
4 + readonly id: ProjectId;
5 + readonly environmentId: EnvironmentId;
6 + readonly repositoryIdentity?: { readonly canonicalKey?: string | undefined } | null | undefined;
7 readonly title: string;
8 readonly workspaceRoot: string;
9 }
@@ -25,7 +26,7 @@ function distinguishTitles<Project extends FilterProject>(
26 export function pullRequestFilterProjects<Project extends FilterProject>(
27 projects: ReadonlyArray<Project>,
28 environmentLabels: ReadonlyMap<EnvironmentId, string>,
28 - selectedProject?: Pick<AssignableProject, "id" | "environmentId">,
29 + selectedProject?: Pick<FilterProject, "id" | "environmentId">,
30 ) {
31 const byRepository = new Map<string, Project>();
32 for (const project of projects) {
@@ -45,7 +46,7 @@ export function pullRequestFilterProjects<Project extends FilterProject>(
46 );
47 const byPath = distinguishTitles(byServer, (project) => project.workspaceRoot);
48 const byEnvironment = distinguishTitles(byPath, (project) => project.environmentId);
48 - return distinguishTitles(byEnvironment, (project) => project.id).toSorted((left, right) =>
49 + return distinguishTitles(byEnvironment, (project) => project.id).sort((left, right) =>
50 left.title.localeCompare(right.title),
51 );
52 }