@@ -20,6 +20,7 @@ import {
2020 requestPullRequestDiffPaths ,
2121 walkPullRequestDiffPages ,
2222} from "./pullRequestDiffPages" ;
23+ import { isPullRequestTestFile } from "./pullRequestFileFilters" ;
2324
2425export type PullRequestParams = {
2526 readonly environmentId : string ;
@@ -99,12 +100,17 @@ const parseCache = new WeakMap<PullRequestDiffResult, ReviewParsedDiff>();
99100// Reads the cached pages in order and mounts the next one a reader still needs, so paging toward
100101// a wanted file continues as each page lands, without the screen asking again.
101102const diffPagesFamily = Atom . family ( ( key : string ) => {
102- const [ target , count , wanted ] = JSON . parse ( key ) as [
103+ const [ target , count , wanted , until ] = JSON . parse ( key ) as [
103104 PullRequestDiffTarget ,
104105 number ,
105106 readonly string [ ] ,
107+ PullRequestDiffShownFiles | null ,
106108 ] ;
107109 const scope = JSON . stringify ( target ) ;
110+ const shown = until
111+ ? ( path : string ) =>
112+ ! until . hideTestFiles || path === until . includePath || ! isPullRequestTestFile ( path )
113+ : undefined ;
108114 return Atom . make ( ( get ) =>
109115 walkPullRequestDiffPages (
110116 ( cursor ) =>
@@ -117,17 +123,28 @@ const diffPagesFamily = Atom.family((key: string) => {
117123 const parsed = parsePullRequestDiffPage ( page , parseCache , scope ) ;
118124 return parsed . kind === "files" ? parsed . files . map ( ( file ) => file . path ) : [ ] ;
119125 } ,
126+ shown ,
120127 ) ,
121128 ) ;
122129} ) ;
123130
124131const NO_PATHS : readonly string [ ] = [ ] ;
125132
126- /** `wantedPaths` keeps paging until those files have loaded or the diff ends. */
133+ /** The test file filter a screen applies, as `usePullRequestFileFilter` takes it. */
134+ export interface PullRequestDiffShownFiles {
135+ readonly hideTestFiles : boolean ;
136+ readonly includePath ?: string | undefined ;
137+ }
138+
139+ /**
140+ * `wantedPaths` keeps paging until those files have loaded or the diff ends, and `shownFiles`
141+ * until a file that filter keeps has loaded.
142+ */
127143export function usePullRequestDiff (
128144 params : PullRequestDiffParams ,
129145 terminology : ChangeRequestTerminology ,
130146 wantedPaths : readonly string [ ] = NO_PATHS ,
147+ shownFiles ?: PullRequestDiffShownFiles ,
131148) {
132149 const reference = pullRequestTarget ( params ) ;
133150 const target : PullRequestDiffTarget = {
@@ -143,7 +160,9 @@ export function usePullRequestDiff(
143160 const requested = requestPullRequestDiffPaths ( stored , key , wantedPaths ) ;
144161 if ( requested !== stored ) setRequested ( requested ) ;
145162 const { pages, frontier } = useAtomValue (
146- diffPagesFamily ( JSON . stringify ( [ target , requested . count , requested . wanted ] ) ) ,
163+ diffPagesFamily (
164+ JSON . stringify ( [ target , requested . count , requested . wanted , shownFiles ?? null ] ) ,
165+ ) ,
147166 ) ;
148167 const query = useEnvironmentQuery ( composerPullRequests . diff ( pageTarget ( target , frontier ) ) ) ;
149168 const parsed = getCachedPullRequestDiffPages ( pages , key , terminology , parseCache ) ;
0 commit comments