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 21, 08:30 UTC
fix(web): show the change breakdown on the floating Changes button (#26566)
Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Jake Leventhal committed
Nov 17, 2026 at 01:17 UTC
d848e4b2b20b4fa380883f4705955a7e85b49b3e
7 files changed
+187
-118
apps/server/src/pullRequest/pullRequestChangeBreakdown.ts
+2
-15
@@ -1,21 +1,8 @@
1
import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
2
-import { classifyChangedFile } from "@t3tools/shared/changedFileKind";
2
+import { summarizeChangedFiles } from "@t3tools/shared/changedFileKind";
3
import type { ProviderFileStats } from "@t3tools/source-control-core/server/PullRequestProvider";
4
5
export function toChangeBreakdown(stats: ProviderFileStats): PullRequestChangeBreakdown {
6
if (stats.truncated) return null;
7
- const empty = () => ({ additions: 0, deletions: 0 });
8
- const breakdown = {
9
- code: empty(),
10
- tests: empty(),
11
- mocks: empty(),
12
- generated: empty(),
13
- docs: empty(),
14
- };
15
- for (const file of stats.files) {
16
- const bucket = breakdown[classifyChangedFile(file.path)];
17
- bucket.additions += file.additions;
18
- bucket.deletions += file.deletions;
19
- }
20
- return breakdown;
7
+ return summarizeChangedFiles(stats.files);
8
}
apps/web/src/components/GitActionsControl.logic.test.ts
+30
-5
@@ -305,13 +305,26 @@ describe("resolveChangesTotals", () => {
305
hasWorkingTreeChanges: true,
306
branchChanges: { baseRef: "main", insertions: 0, deletions: 0 },
307
workingTree: {
308
- files: [{ path: "a.ts", insertions: 5, deletions: 1 }],
308
+ files: [
309
+ { path: "a.ts", insertions: 4, deletions: 1 },
310
+ { path: "README.md", insertions: 1, deletions: 0 },
311
+ ],
312
insertions: 5,
313
deletions: 1,
314
},
315
}),
316
),
314
- { insertions: 5, deletions: 1 },
317
+ {
318
+ insertions: 5,
319
+ deletions: 1,
320
+ breakdown: {
321
+ code: { additions: 4, deletions: 1 },
322
+ tests: { additions: 0, deletions: 0 },
323
+ mocks: { additions: 0, deletions: 0 },
324
+ generated: { additions: 0, deletions: 0 },
325
+ docs: { additions: 1, deletions: 0 },
326
+ },
327
+ },
328
);
329
});
330
@@ -327,7 +340,7 @@ describe("resolveChangesTotals", () => {
340
},
341
}),
342
),
330
- { insertions: 20, deletions: 3, baseRef: "origin/master" },
343
+ { insertions: 20, deletions: 3, baseRef: "origin/master", breakdown: null },
344
);
345
});
346
@@ -350,15 +363,27 @@ describe("resolveChangesTotals", () => {
363
...source,
364
files: [
365
{ path: "a.ts", previousPath: null, additions: 4, deletions: 1 },
353
- { path: "b.ts", previousPath: null, additions: 2, deletions: 0 },
366
+ { path: "a.test.ts", previousPath: null, additions: 2, deletions: 0 },
367
],
368
}),
356
- { insertions: 6, deletions: 1, baseRef: "release" },
369
+ {
370
+ insertions: 6,
371
+ deletions: 1,
372
+ baseRef: "release",
373
+ breakdown: {
374
+ code: { additions: 4, deletions: 1 },
375
+ tests: { additions: 2, deletions: 0 },
376
+ mocks: { additions: 0, deletions: 0 },
377
+ generated: { additions: 0, deletions: 0 },
378
+ docs: { additions: 0, deletions: 0 },
379
+ },
380
+ },
381
);
382
assert.deepEqual(resolveChangesTotals(dirty, source), {
383
insertions: 20,
384
deletions: 3,
385
baseRef: "main",
386
+ breakdown: null,
387
});
388
});
389
apps/web/src/components/GitActionsControl.logic.ts
+20
-1
@@ -1,9 +1,11 @@
1
import type {
2
GitRunStackedActionResult,
3
GitStackedAction,
4
+ PullRequestChangeBreakdown,
5
ReviewDiffPreviewSource,
6
VcsStatusResult,
7
} from "@t3tools/contracts";
8
+import { summarizeChangedFiles } from "@t3tools/shared/changedFileKind";
9
import { isTemporaryWorktreeBranch } from "@t3tools/shared/git";
10
import type { ChangeRequestTerminology } from "@t3tools/client-runtime/source-control-clients";
11
import {
@@ -510,6 +512,8 @@ export type ChangesLineTotals = {
512
readonly deletions: number;
513
/** Ref the counts compare against; `null` means they are uncommitted changes against HEAD. */
514
readonly baseRef: string | null;
515
+ /** `null` when the selected totals carry no per-file stats. */
516
+ readonly breakdown: PullRequestChangeBreakdown;
517
};
518
519
// `branchChanges ?? workingTree` treats `{0,0}` as present, so a zero branch total hid a dirty
@@ -527,7 +531,12 @@ export function resolveChangesTotals(
531
insertions += file.additions;
532
deletions += file.deletions;
533
}
530
- return { insertions, deletions, baseRef: branchPreview.baseRef };
534
+ return {
535
+ insertions,
536
+ deletions,
537
+ baseRef: branchPreview.baseRef,
538
+ breakdown: summarizeChangedFiles(branchPreview.files),
539
+ };
540
}
541
if (!status) return null;
542
const branch = status.branchChanges;
@@ -542,5 +551,15 @@ export function resolveChangesTotals(
551
insertions: selected.insertions,
552
deletions: selected.deletions,
553
baseRef: selected.baseRef,
554
+ breakdown:
555
+ selected === tree
556
+ ? summarizeChangedFiles(
557
+ tree.files.map((file) => ({
558
+ path: file.path,
559
+ additions: file.insertions,
560
+ deletions: file.deletions,
561
+ })),
562
+ )
563
+ : null,
564
};
565
}
apps/web/src/components/GitActionsControl.tsx
+60
-43
@@ -128,6 +128,7 @@ import {
128
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
129
import { scopeProjectRef } from "@t3tools/client-runtime/environment";
130
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
131
+import { ChangeBreakdownGrid } from "./pullRequest/ChangeBreakdownGrid";
132
import { useOpenLink } from "~/browser/useOpenLink";
133
134
interface GitActionsControlProps {
@@ -1088,6 +1089,7 @@ export default function GitActionsControl({
1089
changesPreview.data?.sources.find((source) => source.kind === "branch-range"),
1090
);
1091
const changesTotals = resolvedChangesTotals ?? { insertions: 0, deletions: 0 };
1092
+ const changesBreakdown = resolvedChangesTotals?.breakdown ?? null;
1093
const changesBaseLabel = resolvedChangesTotals
1094
? resolvedChangesTotals.baseRef === null
1095
? "Uncommitted"
@@ -1706,53 +1708,68 @@ export default function GitActionsControl({
1708
)}
1709
1710
{showChanges && isRepo && !quietEmptyDraft ? (
1709
- <ThreadDetailsControl
1710
- type="button"
1711
- variant="ghost"
1712
- size="sm"
1713
- part="row"
1714
- disabled={!onOpenChanges}
1715
- onClick={onOpenChanges}
1716
- >
1717
- <FileDiffIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />
1718
- <span className="flex min-w-0 flex-1 items-baseline gap-1.5">
1719
- <span className="shrink-0">Changes</span>
1720
- {changesBaseLabel ? (
1721
- <Tooltip>
1722
- <TooltipTrigger
1723
- render={
1724
- <span className="pointer-events-auto min-w-0 truncate font-normal text-muted-foreground" />
1711
+ <Tooltip>
1712
+ <TooltipTrigger
1713
+ render={
1714
+ <ThreadDetailsControl
1715
+ type="button"
1716
+ variant="ghost"
1717
+ size="sm"
1718
+ part="row"
1719
+ disabled={!onOpenChanges}
1720
+ onClick={onOpenChanges}
1721
+ />
1722
+ }
1723
+ >
1724
+ <FileDiffIcon className={THREAD_DETAILS_PANEL_ICON_CLASS} aria-hidden />
1725
+ <span className="flex min-w-0 flex-1 items-baseline gap-1.5">
1726
+ <span className="shrink-0">Changes</span>
1727
+ {changesBaseLabel ? (
1728
+ <Tooltip>
1729
+ <TooltipTrigger
1730
+ render={
1731
+ <span className="pointer-events-auto min-w-0 truncate font-normal text-muted-foreground" />
1732
+ }
1733
+ >
1734
+ {changesBaseLabel}
1735
+ </TooltipTrigger>
1736
+ <TooltipPopup side="top" className="max-w-96 break-words">
1737
+ {changesBaseLabel}
1738
+ </TooltipPopup>
1739
+ </Tooltip>
1740
+ ) : null}
1741
+ <span className="ml-auto flex shrink-0 items-baseline gap-2 ps-2 font-mono tabular-nums">
1742
+ <span
1743
+ className={
1744
+ changesTotals.insertions
1745
+ ? "text-diff-addition-foreground"
1746
+ : "text-muted-foreground"
1747
}
1748
>
1727
- {changesBaseLabel}
1728
- </TooltipTrigger>
1729
- <TooltipPopup side="top" className="max-w-96 break-words">
1730
- {changesBaseLabel}
1731
- </TooltipPopup>
1732
- </Tooltip>
1733
- ) : null}
1734
- <span className="ml-auto flex shrink-0 items-baseline gap-2 ps-2 font-mono tabular-nums">
1735
- <span
1736
- className={
1737
- changesTotals.insertions
1738
- ? "text-diff-addition-foreground"
1739
- : "text-muted-foreground"
1740
- }
1741
- >
1742
- +{formatDiffCount(changesTotals.insertions)}
1743
- </span>
1744
- <span
1745
- className={
1746
- changesTotals.deletions
1747
- ? "text-diff-deletion-foreground"
1748
- : "text-muted-foreground"
1749
- }
1750
- >
1751
- -{formatDiffCount(changesTotals.deletions)}
1749
+ +{formatDiffCount(changesTotals.insertions)}
1750
+ </span>
1751
+ <span
1752
+ className={
1753
+ changesTotals.deletions
1754
+ ? "text-diff-deletion-foreground"
1755
+ : "text-muted-foreground"
1756
+ }
1757
+ >
1758
+ -{formatDiffCount(changesTotals.deletions)}
1759
+ </span>
1760
</span>
1761
</span>
1754
- </span>
1755
- </ThreadDetailsControl>
1762
+ </TooltipTrigger>
1763
+ {changesBreakdown && (changesTotals.insertions > 0 || changesTotals.deletions > 0) ? (
1764
+ // Base UI fixes the popup width on open; remeasure when the breakdown changes.
1765
+ <TooltipPopup key={JSON.stringify(changesBreakdown)} side="bottom">
1766
+ <ChangeBreakdownGrid
1767
+ breakdown={changesBreakdown}
1768
+ total={{ additions: changesTotals.insertions, deletions: changesTotals.deletions }}
1769
+ />
1770
+ </TooltipPopup>
1771
+ ) : null}
1772
+ </Tooltip>
1773
) : null}
1774
1775
<Dialog
apps/web/src/components/pullRequest/ChangeBreakdownGrid.tsx
new
+54
@@ -0,0 +1,54 @@
1
+import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
2
+import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
3
+
4
+const KIND_LABELS = {
5
+ code: "Code",
6
+ tests: "Tests",
7
+ mocks: "Mocks",
8
+ generated: "Generated",
9
+ docs: "Docs",
10
+} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
11
+
12
+type DiffTotals = { additions: number; deletions: number };
13
+
14
+export function ChangeBreakdownGrid({
15
+ breakdown,
16
+ total,
17
+}: {
18
+ breakdown: NonNullable<PullRequestChangeBreakdown>;
19
+ total?: DiffTotals;
20
+}) {
21
+ return (
22
+ <div className="grid grid-cols-[auto_auto_auto] justify-start gap-x-4 gap-y-1 py-0.5 font-mono tabular-nums">
23
+ {(Object.keys(KIND_LABELS) as Array<keyof typeof KIND_LABELS>).map((kind) => {
24
+ const { additions, deletions } = breakdown[kind];
25
+ return additions === 0 && deletions === 0 ? null : (
26
+ <BreakdownRow
27
+ key={kind}
28
+ label={KIND_LABELS[kind]}
29
+ additions={additions}
30
+ deletions={deletions}
31
+ />
32
+ );
33
+ })}
34
+ {total ? (
35
+ <>
36
+ <div className="col-span-3 border-t border-border" />
37
+ <BreakdownRow label="Total" additions={total.additions} deletions={total.deletions} />
38
+ </>
39
+ ) : null}
40
+ </div>
41
+ );
42
+}
43
+
44
+function BreakdownRow({ label, additions, deletions }: DiffTotals & { label: string }) {
45
+ return (
46
+ <>
47
+ <span className="font-sans">{label}</span>
48
+ <span className="text-right text-diff-addition-foreground">
49
+ +{formatDiffCount(additions)}
50
+ </span>
51
+ <span className="text-right text-diff-deletion">-{formatDiffCount(deletions)}</span>
52
+ </>
53
+ );
54
+}
apps/web/src/components/pullRequest/PullRequestChangeBreakdownStat.tsx
+2
-54
@@ -1,23 +1,13 @@
1
-import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
2
-import type { EnvironmentId, PullRequestChangeBreakdown, PullRequestRef } from "@t3tools/contracts";
1
+import type { EnvironmentId, PullRequestRef } from "@t3tools/contracts";
2
import { useState } from "react";
3
4
import { pullRequestEnvironment } from "~/state/pullRequests";
5
import { useEnvironmentQuery } from "~/state/query";
6
7
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
8
+import { ChangeBreakdownGrid } from "./ChangeBreakdownGrid";
9
import { PullRequestDiffStat } from "./pullRequestPresentation";
10
11
-const KIND_LABELS = {
12
- code: "Code",
13
- tests: "Tests",
14
- mocks: "Mocks",
15
- generated: "Generated",
16
- docs: "Docs",
17
-} satisfies Record<keyof NonNullable<PullRequestChangeBreakdown>, string>;
18
-
19
-type DiffTotals = { additions: number; deletions: number };
20
-
11
/**
12
* The pull request's diff stat, with a hover split into code, tests, mocks, and generated files.
13
* In lists the split is read on first pointer or focus intent, so rows nobody hovers cost the
@@ -93,45 +83,3 @@ export function PullRequestChangeBreakdownRows({
83
</div>
84
);
85
}
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 }) {
128
- return (
129
- <>
130
- <span className="font-sans">{label}</span>
131
- <span className="text-right text-diff-addition-foreground">
132
- +{formatDiffCount(additions)}
133
- </span>
134
- <span className="text-right text-diff-deletion">-{formatDiffCount(deletions)}</span>
135
- </>
136
- );
137
-}
packages/shared/src/changedFileKind.ts
+19
@@ -2,6 +2,25 @@ import type { PullRequestChangeBreakdown } from "@t3tools/contracts";
2
3
export type ChangedFileKind = keyof NonNullable<PullRequestChangeBreakdown>;
4
5
+export function summarizeChangedFiles(
6
+ files: ReadonlyArray<{ path: string; additions: number; deletions: number }>,
7
+): NonNullable<PullRequestChangeBreakdown> {
8
+ const empty = () => ({ additions: 0, deletions: 0 });
9
+ const breakdown = {
10
+ code: empty(),
11
+ tests: empty(),
12
+ mocks: empty(),
13
+ generated: empty(),
14
+ docs: empty(),
15
+ };
16
+ for (const file of files) {
17
+ const bucket = breakdown[classifyChangedFile(file.path)];
18
+ bucket.additions += file.additions;
19
+ bucket.deletions += file.deletions;
20
+ }
21
+ return breakdown;
22
+}
23
+
24
const GENERATED_FILES = new Set([
25
"bun.lock",
26
"bun.lockb",