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, 20:45 UTC
refactor(web): the pull request list's grouping helper lives in a logic module (#22727)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 21, 2026 at 01:28 UTC
a003b73aa830ff8e35459d33e675884652552c1c
3 files changed
+129
-117
apps/web/src/components/pullRequest/PullRequestsPage.tsx
+1
-2
@@ -65,13 +65,12 @@ import { INVOLVEMENT_TABS, SORT_OPTIONS, STATE_TABS } from "./pullRequestListOpt
65
import { PullRequestsColumn } from "./PullRequestsColumn";
66
import { PullRequestListGroups } from "./PullRequestListGroups";
67
import {
68
- pullRequestGroups,
69
- pullRequestListEntryId,
68
usePullRequestDisplayGroups,
69
usePullRequestQueryFilters,
70
usePullRequestScope,
71
type PullRequestsSearch,
72
} from "./usePullRequestListView";
73
+import { pullRequestGroups, pullRequestListEntryId } from "./pullRequestListGroups.logic";
74
import { PullRequestListEmptyState } from "./PullRequestListEmptyState";
75
import { PullRequestListGhost } from "./PullRequestGhosts";
76
import { type PullRequestRowTarget } from "./PullRequestRow";
apps/web/src/components/pullRequest/pullRequestListGroups.logic.ts
new
+127
@@ -0,0 +1,127 @@
1
+import type {
2
+ PullRequestInvolvement,
3
+ PullRequestListFilters,
4
+ PullRequestListResult,
5
+} from "@t3tools/contracts";
6
+
7
+import type { PullRequestTabStatusSeed } from "~/components/RightPanelTabs";
8
+import { pullRequestSurfaceId } from "~/rightPanelStore";
9
+import {
10
+ filterPullRequestsByInvolvement,
11
+ groupPullRequestsByInvolvement,
12
+ matchesPullRequestFilters,
13
+ matchesPullRequestQuery,
14
+ partitionPullRequestsWithPriority,
15
+ pullRequestEntryKey,
16
+ pullRequestEntryViewer,
17
+ type EnvironmentPullRequestEntry,
18
+ type PullRequestPartitionsSnapshot,
19
+} from "./pullRequestList.logic";
20
+
21
+export const pullRequestListEntryId = (target: Parameters<typeof pullRequestSurfaceId>[0]) =>
22
+ pullRequestSurfaceId({ ...target, repository: target.repository.toLowerCase() });
23
+
24
+/** The held rows narrowed to what the reader asked for, in the groups the list shows. */
25
+export function pullRequestGroups({
26
+ known,
27
+ providers,
28
+ viewers,
29
+ involvement,
30
+ localFilters,
31
+ hasLocalFilters,
32
+ text,
33
+ answeredLocally,
34
+ baselineEmpty,
35
+ held,
36
+ authored,
37
+ reviewing,
38
+ partitionsWanted,
39
+}: {
40
+ known: ReadonlyArray<EnvironmentPullRequestEntry>;
41
+ providers: PullRequestListResult["providers"];
42
+ viewers: PullRequestListResult["viewers"];
43
+ involvement: PullRequestInvolvement;
44
+ localFilters: PullRequestListFilters;
45
+ hasLocalFilters: boolean;
46
+ text: string;
47
+ answeredLocally: boolean;
48
+ baselineEmpty: boolean;
49
+ held: PullRequestPartitionsSnapshot | undefined;
50
+ authored: ReadonlyArray<EnvironmentPullRequestEntry> | undefined;
51
+ reviewing: ReadonlyArray<EnvironmentPullRequestEntry> | undefined;
52
+ partitionsWanted: boolean;
53
+}) {
54
+ const searchingHosts = new Set(
55
+ providers.flatMap((provider) => (provider.searchesOnHost ? [provider.host] : [])),
56
+ );
57
+
58
+ const entries = (() => {
59
+ const involvementEntries = filterPullRequestsByInvolvement(known, viewers, involvement);
60
+ // The hosts search more than the row shows — a body, a review, a commit message — so once
61
+ // their answer is in, narrowing it again here would throw away matches the reader asked for.
62
+ // The local pass stands in for the answer that has not arrived yet, and for the hosts that
63
+ // answered without searching at all: Azure DevOps has no text filter, so its rows arrive
64
+ // whole and would otherwise sit under a search that never touched them.
65
+ const narrowedEntries = hasLocalFilters
66
+ ? involvementEntries.filter((entry) =>
67
+ matchesPullRequestFilters(entry, localFilters, pullRequestEntryViewer(entry, viewers)),
68
+ )
69
+ : involvementEntries;
70
+ if (text.length === 0) {
71
+ return narrowedEntries.toSorted((left, right) =>
72
+ right.updatedAt.localeCompare(left.updatedAt),
73
+ );
74
+ }
75
+ return narrowedEntries.filter(
76
+ (entry) =>
77
+ (answeredLocally && searchingHosts.has(entry.host)) || matchesPullRequestQuery(entry, text),
78
+ );
79
+ })();
80
+
81
+ const listedPullRequestTabStatuses: Record<string, PullRequestTabStatusSeed> = Object.fromEntries(
82
+ entries.map((entry) => [
83
+ pullRequestSurfaceId(entry),
84
+ {
85
+ state: entry.state,
86
+ isDraft: entry.isDraft,
87
+ },
88
+ ]),
89
+ );
90
+
91
+ const groups = (() => {
92
+ if (involvement !== "all") return [{ key: "others" as const, label: "", entries }];
93
+ if (baselineEmpty) {
94
+ return groupPullRequestsByInvolvement(entries, viewers);
95
+ }
96
+ const narrow = (rows: ReadonlyArray<EnvironmentPullRequestEntry> | undefined) =>
97
+ rows === undefined || !hasLocalFilters
98
+ ? rows
99
+ : rows.filter((entry) =>
100
+ matchesPullRequestFilters(entry, localFilters, pullRequestEntryViewer(entry, viewers)),
101
+ );
102
+ const narrowedAuthored = narrow(partitionsWanted ? (authored ?? held?.authored) : undefined);
103
+ const narrowedReviewing = narrow(partitionsWanted ? (reviewing ?? held?.reviewing) : undefined);
104
+ if (narrowedAuthored === undefined || narrowedReviewing === undefined) {
105
+ return groupPullRequestsByInvolvement(entries, viewers);
106
+ }
107
+ return partitionPullRequestsWithPriority(entries, narrowedAuthored, narrowedReviewing);
108
+ })();
109
+
110
+ const entriesByStatsKey: ReadonlyMap<string, EnvironmentPullRequestEntry> = new Map(
111
+ groups.flatMap((group) =>
112
+ group.entries.map((entry) => [pullRequestEntryKey(entry), entry] as const),
113
+ ),
114
+ );
115
+ const heldPullRequestsBySurface = new Map(
116
+ groups.flatMap((group) =>
117
+ group.entries.map((entry) => [pullRequestListEntryId(entry), entry] as const),
118
+ ),
119
+ );
120
+ return {
121
+ entries,
122
+ listedPullRequestTabStatuses,
123
+ groups,
124
+ entriesByStatsKey,
125
+ heldPullRequestsBySurface,
126
+ };
127
+}
apps/web/src/components/pullRequest/usePullRequestListView.ts
+1
-115
@@ -11,20 +11,14 @@ import {
11
} from "@t3tools/contracts";
12
import { useState } from "react";
13
14
-import type { PullRequestTabStatusSeed } from "~/components/RightPanelTabs";
15
-import { pullRequestSurfaceId } from "~/rightPanelStore";
14
import { useAllEnvironmentShellsBootstrapped, useProjects } from "~/state/entities";
15
import { useEnvironments } from "~/state/environments";
16
import { useDebouncedValue } from "~/state/queries";
17
import {
18
applyPullRequestOverrides,
21
- filterPullRequestsByInvolvement,
19
findProjectForRepository,
20
findScopedProject,
24
- groupPullRequestsByInvolvement,
21
matchesPullRequestFilters,
26
- matchesPullRequestQuery,
27
- partitionPullRequestsWithPriority,
22
pullRequestDiffStatKey,
23
pullRequestEntryKey,
24
pullRequestEntryViewer,
@@ -40,12 +34,12 @@ import {
34
type PullRequestDiffStats,
35
type PullRequestGroup,
36
type PullRequestListOverride,
43
- type PullRequestPartitionsSnapshot,
37
} from "./pullRequestList.logic";
38
import type { PullRequestExpectedHost } from "./PullRequestListFilters";
39
import type { PullRequestListPreferences, PullRequestListSort } from "./pullRequestListPreferences";
40
import { assignProjectsToEnvironments } from "./pullRequestProjectAssignment.logic";
41
import { pullRequestFilterProjects } from "./pullRequestProjectFilter.logic";
42
+import { pullRequestListEntryId } from "./pullRequestListGroups.logic";
43
44
export interface PullRequestsSearch extends PullRequestListPreferences {
45
readonly environmentId?: EnvironmentId;
@@ -60,9 +54,6 @@ export interface PullRequestsSearch extends PullRequestListPreferences {
54
55
const SEARCH_DEBOUNCE_MS = 250;
56
63
-export const pullRequestListEntryId = (target: Parameters<typeof pullRequestSurfaceId>[0]) =>
64
- pullRequestSurfaceId({ ...target, repository: target.repository.toLowerCase() });
65
-
57
/** Which servers and projects the page reads, from the URL and what this client knows. */
58
export function usePullRequestScope(search: PullRequestsSearch) {
59
const { environments } = useEnvironments();
@@ -225,111 +216,6 @@ export function usePullRequestQueryFilters(search: PullRequestsSearch, typedQuer
216
};
217
}
218
228
-/** The held rows narrowed to what the reader asked for, in the groups the list shows. */
229
-export function pullRequestGroups({
230
- known,
231
- providers,
232
- viewers,
233
- involvement,
234
- localFilters,
235
- hasLocalFilters,
236
- text,
237
- answeredLocally,
238
- baselineEmpty,
239
- held,
240
- authored,
241
- reviewing,
242
- partitionsWanted,
243
-}: {
244
- known: ReadonlyArray<EnvironmentPullRequestEntry>;
245
- providers: PullRequestListResult["providers"];
246
- viewers: PullRequestListResult["viewers"];
247
- involvement: PullRequestInvolvement;
248
- localFilters: PullRequestListFilters;
249
- hasLocalFilters: boolean;
250
- text: string;
251
- answeredLocally: boolean;
252
- baselineEmpty: boolean;
253
- held: PullRequestPartitionsSnapshot | undefined;
254
- authored: ReadonlyArray<EnvironmentPullRequestEntry> | undefined;
255
- reviewing: ReadonlyArray<EnvironmentPullRequestEntry> | undefined;
256
- partitionsWanted: boolean;
257
-}) {
258
- const searchingHosts = new Set(
259
- providers.flatMap((provider) => (provider.searchesOnHost ? [provider.host] : [])),
260
- );
261
-
262
- const entries = (() => {
263
- const involvementEntries = filterPullRequestsByInvolvement(known, viewers, involvement);
264
- // The hosts search more than the row shows — a body, a review, a commit message — so once
265
- // their answer is in, narrowing it again here would throw away matches the reader asked for.
266
- // The local pass stands in for the answer that has not arrived yet, and for the hosts that
267
- // answered without searching at all: Azure DevOps has no text filter, so its rows arrive
268
- // whole and would otherwise sit under a search that never touched them.
269
- const narrowedEntries = hasLocalFilters
270
- ? involvementEntries.filter((entry) =>
271
- matchesPullRequestFilters(entry, localFilters, pullRequestEntryViewer(entry, viewers)),
272
- )
273
- : involvementEntries;
274
- if (text.length === 0) {
275
- return narrowedEntries.toSorted((left, right) =>
276
- right.updatedAt.localeCompare(left.updatedAt),
277
- );
278
- }
279
- return narrowedEntries.filter(
280
- (entry) =>
281
- (answeredLocally && searchingHosts.has(entry.host)) || matchesPullRequestQuery(entry, text),
282
- );
283
- })();
284
-
285
- const listedPullRequestTabStatuses: Record<string, PullRequestTabStatusSeed> = Object.fromEntries(
286
- entries.map((entry) => [
287
- pullRequestSurfaceId(entry),
288
- {
289
- state: entry.state,
290
- isDraft: entry.isDraft,
291
- },
292
- ]),
293
- );
294
-
295
- const groups = (() => {
296
- if (involvement !== "all") return [{ key: "others" as const, label: "", entries }];
297
- if (baselineEmpty) {
298
- return groupPullRequestsByInvolvement(entries, viewers);
299
- }
300
- const narrow = (rows: ReadonlyArray<EnvironmentPullRequestEntry> | undefined) =>
301
- rows === undefined || !hasLocalFilters
302
- ? rows
303
- : rows.filter((entry) =>
304
- matchesPullRequestFilters(entry, localFilters, pullRequestEntryViewer(entry, viewers)),
305
- );
306
- const narrowedAuthored = narrow(partitionsWanted ? (authored ?? held?.authored) : undefined);
307
- const narrowedReviewing = narrow(partitionsWanted ? (reviewing ?? held?.reviewing) : undefined);
308
- if (narrowedAuthored === undefined || narrowedReviewing === undefined) {
309
- return groupPullRequestsByInvolvement(entries, viewers);
310
- }
311
- return partitionPullRequestsWithPriority(entries, narrowedAuthored, narrowedReviewing);
312
- })();
313
-
314
- const entriesByStatsKey: ReadonlyMap<string, EnvironmentPullRequestEntry> = new Map(
315
- groups.flatMap((group) =>
316
- group.entries.map((entry) => [pullRequestEntryKey(entry), entry] as const),
317
- ),
318
- );
319
- const heldPullRequestsBySurface = new Map(
320
- groups.flatMap((group) =>
321
- group.entries.map((entry) => [pullRequestListEntryId(entry), entry] as const),
322
- ),
323
- );
324
- return {
325
- entries,
326
- listedPullRequestTabStatuses,
327
- groups,
328
- entriesByStatsKey,
329
- heldPullRequestsBySurface,
330
- };
331
-}
332
-
219
/**
220
* The hosts the list has answered for (kept while a host filter narrows the answer), and the
221
* groups as shown with measured sizes, optimistic actions, and the reader's sort.