@@ -26,9 +26,11 @@ import {
2626 resolveThreadPullRequestBadge ,
2727 resolveThreadPullRequestChains ,
2828 type ThreadPullRequestBadge ,
29+ threadPullRequestsOpenFirst ,
2930 visibleThreadPullRequests ,
3031} from "@t3tools/client-runtime/thread-pull-requests" ;
3132import { useRender } from "@base-ui/react/use-render" ;
33+ import { InlineButton } from "./ui/button" ;
3234import { type ReactNode , type AnimationEvent , type MouseEvent , type ReactElement } from "react" ;
3335import { cn } from "../lib/utils" ;
3436import { revealThreadTerminal } from "../lib/revealThreadTerminal" ;
@@ -242,6 +244,80 @@ export function ThreadPullRequestBadgeControl({
242244 ) ;
243245}
244246
247+ const SHOWN_PULL_REQUEST_NUMBERS = 2 ;
248+
249+ /** Compact form for threads with several PRs: the first numbers, then a count that opens the list. */
250+ export function ThreadPullRequestNumbers ( {
251+ badge,
252+ pullRequests,
253+ onOpenList,
254+ onOpenPullRequest,
255+ } : {
256+ badge : ThreadPullRequestBadge ;
257+ pullRequests : ReadonlyArray < ThreadPullRequestLink > ;
258+ onOpenList : ( ) => void ;
259+ onOpenPullRequest : ( event : MouseEvent < HTMLElement > , url : string ) => void ;
260+ } ) {
261+ const ordered = threadPullRequestsOpenFirst ( pullRequests ) ;
262+ const shown = ordered . slice ( 0 , SHOWN_PULL_REQUEST_NUMBERS ) ;
263+ const hidden = ordered . length - shown . length ;
264+ const aggregate = PULL_REQUEST_STATE_PRESENTATION [ badge . state ] ;
265+ const Icon = badge . kind === "stack" ? PullRequestGlyph . stack : aggregate . Icon ;
266+ const terminology = changeRequestTerminologyForUrl ( shown [ 0 ] ?. url ) ;
267+ return (
268+ < span className = "flex min-w-0 items-center gap-1 text-xs tabular-nums" >
269+ < Icon aria-hidden className = { cn ( "size-3 shrink-0" , aggregate . toneClassName ) } />
270+ { shown . map ( ( link ) => {
271+ const state =
272+ link . snapshot === null
273+ ? null
274+ : resolvePullRequestState ( {
275+ state : link . snapshot . state ,
276+ isDraft : link . snapshot . isDraft ,
277+ } ) ;
278+ return (
279+ < InlineButton
280+ key = { link . url }
281+ render = { < a href = { link . url } target = "_blank" rel = "noopener noreferrer" /> }
282+ aria-label = { [
283+ `${ terminology . shortLabel } #${ link . number } ` ,
284+ state ?. label ,
285+ link . snapshot ?. title ,
286+ ]
287+ . filter ( Boolean )
288+ . join ( ", " ) }
289+ onPointerDown = { ( event : MouseEvent < HTMLElement > ) => event . stopPropagation ( ) }
290+ onClick = { ( event : MouseEvent < HTMLElement > ) => onOpenPullRequest ( event , link . url ) }
291+ >
292+ < span
293+ className = { cn (
294+ "contents font-normal" ,
295+ state ?. toneClassName ?? "text-muted-foreground" ,
296+ ) }
297+ >
298+ { link . number }
299+ </ span >
300+ </ InlineButton >
301+ ) ;
302+ } ) }
303+ { hidden > 0 ? (
304+ < InlineButton
305+ tone = "muted"
306+ aria-label = { `Show all ${ ordered . length } ${ terminology . plural } ` }
307+ onPointerDown = { ( event : MouseEvent < HTMLElement > ) => event . stopPropagation ( ) }
308+ onClick = { ( event : MouseEvent < HTMLElement > ) => {
309+ event . preventDefault ( ) ;
310+ event . stopPropagation ( ) ;
311+ onOpenList ( ) ;
312+ } }
313+ >
314+ < span className = "contents font-normal" > +{ hidden } </ span >
315+ </ InlineButton >
316+ ) : null }
317+ </ span >
318+ ) ;
319+ }
320+
245321function PullRequestBadge ( {
246322 render,
247323 presentation,
0 commit comments