@@ -11,20 +11,14 @@ import {
1111} from "@t3tools/contracts" ;
1212import { useState } from "react" ;
1313
14- import type { PullRequestTabStatusSeed } from "~/components/RightPanelTabs" ;
15- import { pullRequestSurfaceId } from "~/rightPanelStore" ;
1614import { useAllEnvironmentShellsBootstrapped , useProjects } from "~/state/entities" ;
1715import { useEnvironments } from "~/state/environments" ;
1816import { useDebouncedValue } from "~/state/queries" ;
1917import {
2018 applyPullRequestOverrides ,
21- filterPullRequestsByInvolvement ,
2219 findProjectForRepository ,
2320 findScopedProject ,
24- groupPullRequestsByInvolvement ,
2521 matchesPullRequestFilters ,
26- matchesPullRequestQuery ,
27- partitionPullRequestsWithPriority ,
2822 pullRequestDiffStatKey ,
2923 pullRequestEntryKey ,
3024 pullRequestEntryViewer ,
@@ -40,12 +34,12 @@ import {
4034 type PullRequestDiffStats ,
4135 type PullRequestGroup ,
4236 type PullRequestListOverride ,
43- type PullRequestPartitionsSnapshot ,
4437} from "./pullRequestList.logic" ;
4538import type { PullRequestExpectedHost } from "./PullRequestListFilters" ;
4639import type { PullRequestListPreferences , PullRequestListSort } from "./pullRequestListPreferences" ;
4740import { assignProjectsToEnvironments } from "./pullRequestProjectAssignment.logic" ;
4841import { pullRequestFilterProjects } from "./pullRequestProjectFilter.logic" ;
42+ import { pullRequestListEntryId } from "./pullRequestListGroups.logic" ;
4943
5044export interface PullRequestsSearch extends PullRequestListPreferences {
5145 readonly environmentId ?: EnvironmentId ;
@@ -60,9 +54,6 @@ export interface PullRequestsSearch extends PullRequestListPreferences {
6054
6155const SEARCH_DEBOUNCE_MS = 250 ;
6256
63- export const pullRequestListEntryId = ( target : Parameters < typeof pullRequestSurfaceId > [ 0 ] ) =>
64- pullRequestSurfaceId ( { ...target , repository : target . repository . toLowerCase ( ) } ) ;
65-
6657/** Which servers and projects the page reads, from the URL and what this client knows. */
6758export function usePullRequestScope ( search : PullRequestsSearch ) {
6859 const { environments } = useEnvironments ( ) ;
@@ -225,111 +216,6 @@ export function usePullRequestQueryFilters(search: PullRequestsSearch, typedQuer
225216 } ;
226217}
227218
228- /** The held rows narrowed to what the reader asked for, in the groups the list shows. */
229- export function pullRequestGroups ( {
230- known,
231- providers,
232- viewers,
233- involvement,
234- localFilters,
235- hasLocalFilters,
236- text,
237- answeredLocally,
238- baselineEmpty,
239- held,
240- authored,
241- reviewing,
242- partitionsWanted,
243- } : {
244- known : ReadonlyArray < EnvironmentPullRequestEntry > ;
245- providers : PullRequestListResult [ "providers" ] ;
246- viewers : PullRequestListResult [ "viewers" ] ;
247- involvement : PullRequestInvolvement ;
248- localFilters : PullRequestListFilters ;
249- hasLocalFilters : boolean ;
250- text : string ;
251- answeredLocally : boolean ;
252- baselineEmpty : boolean ;
253- held : PullRequestPartitionsSnapshot | undefined ;
254- authored : ReadonlyArray < EnvironmentPullRequestEntry > | undefined ;
255- reviewing : ReadonlyArray < EnvironmentPullRequestEntry > | undefined ;
256- partitionsWanted : boolean ;
257- } ) {
258- const searchingHosts = new Set (
259- providers . flatMap ( ( provider ) => ( provider . searchesOnHost ? [ provider . host ] : [ ] ) ) ,
260- ) ;
261-
262- const entries = ( ( ) => {
263- const involvementEntries = filterPullRequestsByInvolvement ( known , viewers , involvement ) ;
264- // The hosts search more than the row shows — a body, a review, a commit message — so once
265- // their answer is in, narrowing it again here would throw away matches the reader asked for.
266- // The local pass stands in for the answer that has not arrived yet, and for the hosts that
267- // answered without searching at all: Azure DevOps has no text filter, so its rows arrive
268- // whole and would otherwise sit under a search that never touched them.
269- const narrowedEntries = hasLocalFilters
270- ? involvementEntries . filter ( ( entry ) =>
271- matchesPullRequestFilters ( entry , localFilters , pullRequestEntryViewer ( entry , viewers ) ) ,
272- )
273- : involvementEntries ;
274- if ( text . length === 0 ) {
275- return narrowedEntries . toSorted ( ( left , right ) =>
276- right . updatedAt . localeCompare ( left . updatedAt ) ,
277- ) ;
278- }
279- return narrowedEntries . filter (
280- ( entry ) =>
281- ( answeredLocally && searchingHosts . has ( entry . host ) ) || matchesPullRequestQuery ( entry , text ) ,
282- ) ;
283- } ) ( ) ;
284-
285- const listedPullRequestTabStatuses : Record < string , PullRequestTabStatusSeed > = Object . fromEntries (
286- entries . map ( ( entry ) => [
287- pullRequestSurfaceId ( entry ) ,
288- {
289- state : entry . state ,
290- isDraft : entry . isDraft ,
291- } ,
292- ] ) ,
293- ) ;
294-
295- const groups = ( ( ) => {
296- if ( involvement !== "all" ) return [ { key : "others" as const , label : "" , entries } ] ;
297- if ( baselineEmpty ) {
298- return groupPullRequestsByInvolvement ( entries , viewers ) ;
299- }
300- const narrow = ( rows : ReadonlyArray < EnvironmentPullRequestEntry > | undefined ) =>
301- rows === undefined || ! hasLocalFilters
302- ? rows
303- : rows . filter ( ( entry ) =>
304- matchesPullRequestFilters ( entry , localFilters , pullRequestEntryViewer ( entry , viewers ) ) ,
305- ) ;
306- const narrowedAuthored = narrow ( partitionsWanted ? ( authored ?? held ?. authored ) : undefined ) ;
307- const narrowedReviewing = narrow ( partitionsWanted ? ( reviewing ?? held ?. reviewing ) : undefined ) ;
308- if ( narrowedAuthored === undefined || narrowedReviewing === undefined ) {
309- return groupPullRequestsByInvolvement ( entries , viewers ) ;
310- }
311- return partitionPullRequestsWithPriority ( entries , narrowedAuthored , narrowedReviewing ) ;
312- } ) ( ) ;
313-
314- const entriesByStatsKey : ReadonlyMap < string , EnvironmentPullRequestEntry > = new Map (
315- groups . flatMap ( ( group ) =>
316- group . entries . map ( ( entry ) => [ pullRequestEntryKey ( entry ) , entry ] as const ) ,
317- ) ,
318- ) ;
319- const heldPullRequestsBySurface = new Map (
320- groups . flatMap ( ( group ) =>
321- group . entries . map ( ( entry ) => [ pullRequestListEntryId ( entry ) , entry ] as const ) ,
322- ) ,
323- ) ;
324- return {
325- entries,
326- listedPullRequestTabStatuses,
327- groups,
328- entriesByStatsKey,
329- heldPullRequestsBySurface,
330- } ;
331- }
332-
333219/**
334220 * The hosts the list has answered for (kept while a host filter narrows the answer), and the
335221 * groups as shown with measured sizes, optimistic actions, and the reader's sort.
0 commit comments