Skip to content

Commit 962428d

Browse files
t3dotggclaude
andauthored
feat(clients): every PR +/- shows its code, tests, and docs split, without the hover wait (pingdotgg#22255)
Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent 54346a6 commit 962428d

13 files changed

Lines changed: 195 additions & 39 deletions

‎apps/mobile/src/features/pull-requests/PullRequestFiles.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ const BREAKDOWN_LABELS = {
2929
tests: "Tests",
3030
mocks: "Mocks",
3131
generated: "Generated",
32+
docs: "Docs",
3233
} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
3334

3435
function PullRequestChangeBreakdownLine(props: {

‎apps/server/src/pullRequest/pullRequestChangeBreakdown.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ describe("toChangeBreakdown", () => {
1212
{ path: "src/b.ts", additions: 5, deletions: 1 },
1313
{ path: "src/a.test.ts", additions: 40, deletions: 0 },
1414
{ path: "pnpm-lock.yaml", additions: 300, deletions: 120 },
15+
{ path: "README.md", additions: 7, deletions: 3 },
1516
],
1617
}),
1718
).toEqual({
1819
code: { additions: 15, deletions: 3 },
1920
tests: { additions: 40, deletions: 0 },
2021
mocks: { additions: 0, deletions: 0 },
2122
generated: { additions: 300, deletions: 120 },
23+
docs: { additions: 7, deletions: 3 },
2224
});
2325
});
2426

‎apps/server/src/pullRequest/pullRequestChangeBreakdown.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@ import type { ProviderFileStats } from "@t3tools/source-control-core/server/Pull
55
export function toChangeBreakdown(stats: ProviderFileStats): PullRequestChangeBreakdown {
66
if (stats.truncated) return null;
77
const empty = () => ({ additions: 0, deletions: 0 });
8-
const breakdown = { code: empty(), tests: empty(), mocks: empty(), generated: empty() };
8+
const breakdown = {
9+
code: empty(),
10+
tests: empty(),
11+
mocks: empty(),
12+
generated: empty(),
13+
docs: empty(),
14+
};
915
for (const file of stats.files) {
1016
const bucket = breakdown[classifyChangedFile(file.path)];
1117
bucket.additions += file.additions;

‎apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { AsyncResult } from "effect/reactivity";
1212
import { act } from "react";
1313
import { createRoot, type Root } from "react-dom/client";
1414
import { afterEach, beforeEach, expect, it, vi } from "vite-plus/test";
15+
import { userEvent } from "vite-plus/test/browser";
1516

1617
const state = vi.hoisted(() => ({
1718
status: "success" as PullRequestCheck["status"],
@@ -26,7 +27,14 @@ const state = vi.hoisted(() => ({
2627

2728
vi.mock(import("~/state/entities"), async (importOriginal) => ({
2829
...(await importOriginal()),
29-
useServerConfigs: (() => new Map()) as never,
30+
// Rows render a pull request only with a project, so this does not reach tests that pass none.
31+
useServerConfigs: (() =>
32+
new Map([
33+
[
34+
EnvironmentId.make("environment"),
35+
{ environment: { capabilities: { pullRequests: true } } },
36+
],
37+
])) as never,
3038
}));
3139
const queryData = () => ({
3240
projectId: ProjectId.make("project"),
@@ -58,6 +66,16 @@ vi.mock(import("~/state/query"), async (importOriginal) => ({
5866
select(AsyncResult.success(queryData()))) as never,
5967
useEnvironmentQueryIsNewer: () => true,
6068
useEnvironmentQueryRefresh: () => ({ refresh: vi.fn(), isPending: () => false }),
69+
useEnvironmentQuery: (() => ({
70+
data: {
71+
code: { additions: 1, deletions: 0 },
72+
tests: { additions: 0, deletions: 0 },
73+
mocks: { additions: 0, deletions: 0 },
74+
generated: { additions: 0, deletions: 0 },
75+
docs: { additions: 7, deletions: 3 },
76+
},
77+
isPending: false,
78+
})) as never,
6179
}));
6280
vi.mock(import("../pullRequest/usePullRequestActions"), async (importOriginal) => ({
6381
...(await importOriginal()),
@@ -231,3 +249,25 @@ it("shows the current checkout recovery detail when fixing checks fails and is r
231249
second.detail,
232250
]);
233251
});
252+
253+
it("splits the change by file kind in the hover card", async () => {
254+
act(() =>
255+
root.render(
256+
<ThreadDetailsPrRow
257+
environmentId={EnvironmentId.make("environment")}
258+
pr={null}
259+
number={1}
260+
reference={{ repository: "owner/repo", number: 1 }}
261+
status={null}
262+
project={{ id: ProjectId.make("project"), repositoryIdentity: null } as never}
263+
label="Test PR"
264+
openAriaLabel="Open PR"
265+
onOpen={vi.fn()}
266+
/>,
267+
),
268+
);
269+
await act(() => userEvent.hover(container.querySelector('button[aria-label="Open PR"]')!));
270+
await expect
271+
.poll(() => document.querySelector('[data-slot="tooltip-popup"][data-open]')?.textContent)
272+
.toMatch(/Docs\+7-3/);
273+
});

‎apps/web/src/components/chat/ThreadDetailsPrRow.tsx‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { PullRequestChangeBreakdownRows } from "../pullRequest/PullRequestChangeBreakdownStat";
12
import { ThreadDetailsControl } from "./ThreadDetailsControl";
23
import { PullRequestGlyph } from "../pullRequest/pullRequestIcons";
34
import { selectEnvironmentQueryData } from "@t3tools/client-runtime/state/runtime";
@@ -292,6 +293,13 @@ export function ThreadDetailsPrRow({
292293
<PullRequestDiffStat additions={detail.additions} deletions={detail.deletions} />
293294
</div>
294295
</div>
296+
{reference !== null && (detail.additions > 0 || detail.deletions > 0) ? (
297+
<PullRequestChangeBreakdownRows
298+
environmentId={environmentId}
299+
reference={reference}
300+
className="pl-5 text-foreground/75"
301+
/>
302+
) : null}
295303
</div>
296304
</div>
297305
</TooltipPopup>

‎apps/web/src/components/pullRequest/PullRequestChangeBreakdownStat.tsx‎

Lines changed: 62 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,32 @@ const KIND_LABELS = {
1313
tests: "Tests",
1414
mocks: "Mocks",
1515
generated: "Generated",
16+
docs: "Docs",
1617
} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
1718

19+
type DiffTotals = { additions: number; deletions: number };
20+
1821
/**
1922
* The pull request's diff stat, with a hover split into code, tests, mocks, and generated files.
20-
* The split is read on first pointer or focus intent, so a page nobody hovers costs the host
21-
* nothing.
23+
* In lists the split is read on first pointer or focus intent, so rows nobody hovers cost the
24+
* host nothing. A view of one pull request passes `eager` so the split is ready before the hover.
2225
*/
2326
export function PullRequestChangeBreakdownStat({
2427
environmentId,
2528
reference,
2629
additions,
2730
deletions,
2831
className,
32+
eager = false,
2933
}: {
3034
environmentId: EnvironmentId;
3135
reference: PullRequestRef;
3236
additions: number;
3337
deletions: number;
3438
className: string;
39+
eager?: boolean;
3540
}) {
36-
const [requested, setRequested] = useState(false);
41+
const [requested, setRequested] = useState(eager);
3742
const query = useEnvironmentQuery(
3843
requested ? pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }) : null,
3944
);
@@ -56,21 +61,7 @@ export function PullRequestChangeBreakdownStat({
5661
/>
5762
{breakdown ? (
5863
<TooltipPopup side="bottom">
59-
<div className="grid grid-cols-[auto_auto_auto] gap-x-4 gap-y-1 py-0.5 font-mono tabular-nums">
60-
{(Object.keys(KIND_LABELS) as Array<keyof typeof KIND_LABELS>).map((kind) => {
61-
const { additions, deletions } = breakdown[kind];
62-
return additions === 0 && deletions === 0 ? null : (
63-
<BreakdownRow
64-
key={kind}
65-
label={KIND_LABELS[kind]}
66-
additions={additions}
67-
deletions={deletions}
68-
/>
69-
);
70-
})}
71-
<div className="col-span-3 border-t border-border" />
72-
<BreakdownRow label="Total" additions={additions} deletions={deletions} />
73-
</div>
64+
<ChangeBreakdownGrid breakdown={breakdown} total={{ additions, deletions }} />
7465
</TooltipPopup>
7566
) : query.isPending ? (
7667
<TooltipPopup side="bottom">Loading breakdown</TooltipPopup>
@@ -79,15 +70,61 @@ export function PullRequestChangeBreakdownStat({
7970
);
8071
}
8172

82-
function BreakdownRow({
83-
label,
84-
additions,
85-
deletions,
73+
/**
74+
* The split shown inline, for surfaces that already sit behind a hover, such as the thread
75+
* details card. It reads on mount, so it costs the host a request only once the card opens.
76+
*/
77+
export function PullRequestChangeBreakdownRows({
78+
environmentId,
79+
reference,
80+
className,
8681
}: {
87-
label: string;
88-
additions: number;
89-
deletions: number;
82+
environmentId: EnvironmentId;
83+
reference: PullRequestRef;
84+
className: string;
9085
}) {
86+
const query = useEnvironmentQuery(
87+
pullRequestEnvironment.changeBreakdown({ environmentId, input: reference }),
88+
);
89+
if (!query.data) return null;
90+
return (
91+
<div className={className}>
92+
<ChangeBreakdownGrid breakdown={query.data} />
93+
</div>
94+
);
95+
}
96+
97+
function ChangeBreakdownGrid({
98+
breakdown,
99+
total,
100+
}: {
101+
breakdown: NonNullable<PullRequestChangeBreakdown>;
102+
total?: DiffTotals;
103+
}) {
104+
return (
105+
<div className="grid grid-cols-[auto_auto_auto] justify-start gap-x-4 gap-y-1 py-0.5 font-mono tabular-nums">
106+
{(Object.keys(KIND_LABELS) as Array<keyof typeof KIND_LABELS>).map((kind) => {
107+
const { additions, deletions } = breakdown[kind];
108+
return additions === 0 && deletions === 0 ? null : (
109+
<BreakdownRow
110+
key={kind}
111+
label={KIND_LABELS[kind]}
112+
additions={additions}
113+
deletions={deletions}
114+
/>
115+
);
116+
})}
117+
{total ? (
118+
<>
119+
<div className="col-span-3 border-t border-border" />
120+
<BreakdownRow label="Total" additions={total.additions} deletions={total.deletions} />
121+
</>
122+
) : null}
123+
</div>
124+
);
125+
}
126+
127+
function BreakdownRow({ label, additions, deletions }: DiffTotals & { label: string }) {
91128
return (
92129
<>
93130
<span className="font-sans">{label}</span>

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2436,6 +2436,7 @@ export function PullRequestDetailPanel({
24362436
additions={detail.additions}
24372437
deletions={detail.deletions}
24382438
className="shrink-0 font-mono text-2xs"
2439+
eager
24392440
/>
24402441
</span>
24412442
</div>
@@ -2612,6 +2613,7 @@ export function PullRequestDetailPanel({
26122613
additions={detail.additions}
26132614
deletions={detail.deletions}
26142615
className="shrink-0 font-mono text-xs"
2616+
eager
26152617
/>
26162618
}
26172619
/>

‎apps/web/src/components/pullRequest/PullRequestRow.tsx‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type { PullRequestAction } from "@t3tools/contracts";
22
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
33
import { SearchIcon } from "lucide-react";
4+
import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
45
import { PullRequestStackPopover } from "./PullRequestStackPopover";
56
import {
67
PullRequestSpeedActions,
@@ -22,11 +23,7 @@ import {
2223
PullRequestRowGlyph,
2324
PullRequestRowLines,
2425
} from "./PullRequestListRow";
25-
import {
26-
PullRequestDiffStat,
27-
PullRequestLabelChip,
28-
PullRequestReviewDecisionGlyph,
29-
} from "./pullRequestPresentation";
26+
import { PullRequestLabelChip, PullRequestReviewDecisionGlyph } from "./pullRequestPresentation";
3027

3128
const LABEL_SLOTS = [
3229
{ overflow: "@xl/pr-row-meta:hidden" },
@@ -186,7 +183,14 @@ function PullRequestRowImpl({
186183
}
187184
/>
188185
) : null}
189-
<PullRequestDiffStat
186+
<PullRequestChangeBreakdownStat
187+
environmentId={entry.environmentId}
188+
reference={{
189+
projectId: entry.projectId,
190+
host: entry.host,
191+
repository: entry.repository,
192+
number: entry.number,
193+
}}
190194
additions={entry.additions}
191195
deletions={entry.deletions}
192196
className="font-mono"

‎apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import { findProjectForChangeRequest, useOpenPrLink } from "~/lib/openPullReques
2929
import { cn } from "~/lib/utils";
3030
import { useShortcutModifierState } from "~/shortcutModifierState";
3131
import { useProjects, useServerConfigs, useThreadShell } from "~/state/entities";
32+
import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
3233
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
3334
import { threadEnvironment } from "~/state/threads";
3435
import { useAtomCommand } from "~/state/use-atom-command";
@@ -209,11 +210,26 @@ function LinkRowImpl({
209210
) : null
210211
}
211212
status={
212-
<PullRequestDiffStat
213-
additions={snapshot?.additions ?? 0}
214-
deletions={snapshot?.deletions ?? 0}
215-
className="font-mono"
216-
/>
213+
projectId === null ? (
214+
<PullRequestDiffStat
215+
additions={snapshot?.additions ?? 0}
216+
deletions={snapshot?.deletions ?? 0}
217+
className="font-mono"
218+
/>
219+
) : (
220+
<PullRequestChangeBreakdownStat
221+
environmentId={threadRef.environmentId}
222+
reference={{
223+
projectId,
224+
host: link.host,
225+
repository: link.repository,
226+
number: link.number,
227+
}}
228+
additions={snapshot?.additions ?? 0}
229+
deletions={snapshot?.deletions ?? 0}
230+
className="font-mono"
231+
/>
232+
)
217233
}
218234
meta={
219235
<>

‎packages/contracts/src/pullRequest.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { describe, expect, it } from "vite-plus/test";
55
import {
66
PullRequestActionInput,
77
PullRequestCapabilities,
8+
PullRequestChangeBreakdown,
89
PullRequestDetail,
910
PullRequestFilesViewedResult,
1011
PullRequestListInput,
@@ -18,6 +19,9 @@ import {
1819

1920
const decodeListResult = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestListResult));
2021
const decodeDetail = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestDetail));
22+
const decodeChangeBreakdown = Schema.decodeUnknownSync(
23+
Schema.toCodecJson(PullRequestChangeBreakdown),
24+
);
2125
const decodeListInput = Schema.decodeUnknownSync(PullRequestListInput);
2226
const decodeReviewerRequest = Schema.decodeUnknownSync(PullRequestReviewerRequestInput);
2327
const decodeAction = Schema.decodeUnknownSync(Schema.toCodecJson(PullRequestActionInput));
@@ -423,3 +427,23 @@ describe("naming the file a tick belongs to", () => {
423427
).toThrow();
424428
});
425429
});
430+
431+
describe("PullRequestChangeBreakdown", () => {
432+
it("reads a breakdown from a server that predates the docs kind", () => {
433+
const line = { additions: 1, deletions: 0 };
434+
expect(
435+
decodeChangeBreakdown({
436+
code: line,
437+
tests: line,
438+
mocks: line,
439+
generated: line,
440+
}),
441+
).toEqual({
442+
code: line,
443+
tests: line,
444+
mocks: line,
445+
generated: line,
446+
docs: { additions: 0, deletions: 0 },
447+
});
448+
});
449+
});

0 commit comments

Comments
 (0)