@@ -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" ;
@@ -238,6 +240,73 @@ export function ThreadPullRequestBadgeControl({
238240 ) ;
239241}
240242
243+ const SHOWN_PULL_REQUEST_NUMBERS = 2 ;
244+
245+ /** Compact form for threads with several PRs: the first numbers, then a count that opens the list. */
246+ export function ThreadPullRequestNumbers ( {
247+ badge,
248+ pullRequests,
249+ onOpenList,
250+ onOpenPullRequest,
251+ } : {
252+ badge : ThreadPullRequestBadge ;
253+ pullRequests : ReadonlyArray < ThreadPullRequestLink > ;
254+ onOpenList : ( ) => void ;
255+ onOpenPullRequest : ( event : MouseEvent < HTMLElement > , url : string ) => void ;
256+ } ) {
257+ const ordered = threadPullRequestsOpenFirst ( pullRequests ) ;
258+ const shown = ordered . slice ( 0 , SHOWN_PULL_REQUEST_NUMBERS ) ;
259+ const hidden = ordered . length - shown . length ;
260+ const aggregate = PULL_REQUEST_STATE_PRESENTATION [ badge . state ] ;
261+ const Icon = badge . kind === "stack" ? PullRequestGlyph . stack : aggregate . Icon ;
262+ const terminology = changeRequestTerminologyForUrl ( shown [ 0 ] ?. url ) ;
263+ return (
264+ < span className = "flex min-w-0 items-center gap-1 text-xs tabular-nums" >
265+ < Icon aria-hidden className = { cn ( "size-3 shrink-0" , aggregate . toneClassName ) } />
266+ { shown . map ( ( link ) => {
267+ const state =
268+ link . snapshot === null
269+ ? null
270+ : resolvePullRequestState ( {
271+ state : link . snapshot . state ,
272+ isDraft : link . snapshot . isDraft ,
273+ } ) ;
274+ return (
275+ < InlineButton
276+ key = { link . url }
277+ render = { < a href = { link . url } target = "_blank" rel = "noopener noreferrer" /> }
278+ aria-label = { [
279+ `${ terminology . shortLabel } #${ link . number } ` ,
280+ state ?. label ,
281+ link . snapshot ?. title ,
282+ ]
283+ . filter ( Boolean )
284+ . join ( ", " ) }
285+ onPointerDown = { ( event : MouseEvent < HTMLElement > ) => event . stopPropagation ( ) }
286+ onClick = { ( event : MouseEvent < HTMLElement > ) => onOpenPullRequest ( event , link . url ) }
287+ >
288+ < span className = "contents font-normal text-secondary-label" > { link . number } </ span >
289+ </ InlineButton >
290+ ) ;
291+ } ) }
292+ { hidden > 0 ? (
293+ < InlineButton
294+ tone = "muted"
295+ aria-label = { `Show all ${ ordered . length } ${ terminology . plural } ` }
296+ onPointerDown = { ( event : MouseEvent < HTMLElement > ) => event . stopPropagation ( ) }
297+ onClick = { ( event : MouseEvent < HTMLElement > ) => {
298+ event . preventDefault ( ) ;
299+ event . stopPropagation ( ) ;
300+ onOpenList ( ) ;
301+ } }
302+ >
303+ < span className = "contents font-normal" > +{ hidden } </ span >
304+ </ InlineButton >
305+ ) : null }
306+ </ span >
307+ ) ;
308+ }
309+
241310function PullRequestBadge ( {
242311 render,
243312 presentation,
0 commit comments