@@ -4,6 +4,7 @@ import type {
44 EnvironmentId ,
55 PullRequestDetailView ,
66 PullRequestDiffSide ,
7+ PullRequestOmittedFileStat ,
78 PullRequestRef ,
89 PullRequestReviewThread ,
910} from "@t3tools/contracts" ;
@@ -95,8 +96,20 @@ interface DiffSlice {
9596 readonly patch : string ;
9697 readonly truncated : boolean ;
9798 readonly nextCursor : string | null ;
99+ readonly omittedFileStats : ReadonlyArray < PullRequestOmittedFileStat > ;
98100}
99101
102+ /**
103+ * The viewer's own per-file counts are hidden and drawn from this side of its shadow root
104+ * instead: its counts are hunk sums, and a file whose hunks the host withheld would read as
105+ * an empty change rather than as the counts the host did report.
106+ */
107+ const REPLACE_FILE_COUNTS_CSS = `
108+ [data-diffs-header] [data-additions-count],
109+ [data-diffs-header] [data-deletions-count] {
110+ display: none !important;
111+ }` ;
112+
100113/** Nothing loaded yet, as one identity, so the memos below do not see a new array every render. */
101114const NO_SLICES : ReadonlyArray < DiffSlice > = [ ] ;
102115
@@ -246,6 +259,7 @@ export function PullRequestCodeTab({
246259 patch : data . patch ,
247260 truncated : data . truncated ,
248261 nextCursor : data . nextCursor ,
262+ omittedFileStats : data . omittedFileStats ?? [ ] ,
249263 } ;
250264 const index = slices . findIndex ( ( slice ) => slice . cursor === cursor ) ;
251265 if ( index === - 1 ) {
@@ -471,6 +485,15 @@ export function PullRequestCodeTab({
471485 ] ,
472486 ) ;
473487 const lineStat = useMemo ( ( ) => getDiffLineStat ( files ) , [ files ] ) ;
488+ const omittedFileStats = useMemo (
489+ ( ) =>
490+ new Map (
491+ loadedSlices . flatMap ( ( slice ) =>
492+ slice . omittedFileStats . map ( ( file ) => [ file . path , file ] as const ) ,
493+ ) ,
494+ ) ,
495+ [ loadedSlices ] ,
496+ ) ;
474497 const fileKeys = useMemo ( ( ) => items . map ( ( item ) => item . id ) , [ items ] ) ;
475498 const collapsedFileKeys = useMemo (
476499 ( ) => new Set ( items . filter ( ( item ) => item . collapsed === true ) . map ( ( item ) => item . id ) ) ,
@@ -649,6 +672,30 @@ export function PullRequestCodeTab({
649672 [ toggleFile ] ,
650673 ) ;
651674
675+ const renderHeaderMetadata = useCallback (
676+ ( item : CodeViewItem < ReviewAnnotationGroup > ) => {
677+ if ( item . type !== "diff" ) return null ;
678+ let additions = 0 ;
679+ let deletions = 0 ;
680+ for ( const hunk of item . fileDiff . hunks ) {
681+ additions += hunk . additionLines ;
682+ deletions += hunk . deletionLines ;
683+ }
684+ if ( additions === 0 && deletions === 0 ) {
685+ const withheld = omittedFileStats . get ( resolveFileDiffPath ( item . fileDiff ) ) ;
686+ if ( withheld ) ( { additions, deletions } = withheld ) ;
687+ }
688+ return (
689+ < PullRequestDiffStat
690+ additions = { additions }
691+ deletions = { deletions }
692+ className = "font-mono text-[11px]"
693+ />
694+ ) ;
695+ } ,
696+ [ omittedFileStats ] ,
697+ ) ;
698+
652699 const diffViewOptions = useMemo (
653700 ( ) => ( {
654701 diffStyle : diffRenderMode === "split" ? ( "split" as const ) : ( "unified" as const ) ,
@@ -1222,7 +1269,9 @@ export function PullRequestCodeTab({
12221269 // is running out of diff.
12231270 renderCodeViewFooter = { renderCodeViewFooter }
12241271 renderHeaderPrefix = { renderHeaderPrefix }
1272+ renderHeaderMetadata = { renderHeaderMetadata }
12251273 renderAnnotation = { renderAnnotation }
1274+ unsafeCSSExtra = { REPLACE_FILE_COUNTS_CSS }
12261275 />
12271276 { reviewOverlay }
12281277 </ div >
0 commit comments