@@ -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 */
2326export 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 >
0 commit comments