@@ -2,7 +2,7 @@ import { useDndContext, useDndMonitor } from "@dnd-kit/core";
22import { scopeThreadRef , scopedThreadKey } from "@t3tools/client-runtime/environment" ;
33import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/models" ;
44import {
5- ChevronRightIcon ,
5+ ChevronDownIcon ,
66 MoreHorizontalIcon ,
77 RefreshCwIcon ,
88 SquarePenIcon ,
@@ -36,15 +36,17 @@ import {
3636} from "./SidebarThreadGroup.projection" ;
3737import { sidebarProjectedLayoutFork } from "./SidebarThreadGroup.span" ;
3838
39- // Mirrors upstream's shelf section header (Snoozed / Settled): label with the
40- // count, a hairline, and a chevron, reading at full strength during a drag. It
41- // renders inside the group's sortable header marker, so it moves with the rows
42- // during a drag; the drop layer draws the outline when a row would join it .
39+ // A parentless group mirrors upstream's shelf section header (label, count, hairline,
40+ // chevron). A group with a parent wears its title as a tab on the parent card, whose surface
41+ // hook pulls up 1px to close the gap under the tab. Either renders inside the group's sortable
42+ // header marker so it moves with the rows during a drag .
4343export function SidebarThreadGroupHeader ( props : {
4444 readonly group : SidebarThreadGroup ;
4545 /** False where this client cannot edit the group: actions hide, collapse still works. */
4646 readonly canEdit : boolean ;
4747 readonly memberCount : number ;
48+ /** The parent's children, in list order; null for a parentless group. */
49+ readonly childThreads : readonly EnvironmentThreadShell [ ] | null ;
4850 readonly isGenerating : boolean ;
4951 readonly isDissolving ?: boolean ;
5052 readonly onCollapsedChange : ( collapsed : boolean ) => void ;
@@ -77,18 +79,26 @@ export function SidebarThreadGroupHeader(props: {
7779 setIsEditing ( false ) ;
7880 } ;
7981 const expanded = ! props . group . collapsed ;
82+ const children = props . childThreads ;
83+ const statusDots = useChildStatusDots ( expanded ? null : children ) ;
84+ const toggle = {
85+ "aria-busy" : props . isGenerating || undefined ,
86+ onClick : ( ) => props . onCollapsedChange ( expanded ) ,
87+ onDoubleClick : ( ) => props . canEdit && setIsEditing ( true ) ,
88+ } ;
8089
8190 return (
8291 < div
8392 data-testid = { `sidebar-thread-group-${ props . group . id } ` }
8493 className = { cn (
85- "group/thread-group relative h-8 transition-opacity duration-150 ease-out" ,
94+ "group/thread-group relative transition-opacity duration-150 ease-out" ,
95+ children ? "flex h-7 items-end gap-1" : "h-8" ,
8696 // Keeps its height: the sortable preview measured it at pickup.
8797 props . isDissolving && "pointer-events-none opacity-30" ,
8898 ) }
8999 >
90100 { isEditing ? (
91- < div className = "flex h-full items-center px-1" >
101+ < div className = "flex h-full w-full items-center px-1" >
92102 < SidebarRenameInput
93103 ariaLabel = "Thread group title"
94104 value = { title }
@@ -98,13 +108,46 @@ export function SidebarThreadGroupHeader(props: {
98108 className = "h-6 text-xs"
99109 />
100110 </ div >
111+ ) : children ? (
112+ // Disabled rather than unmounted while expanded, so a keyboard toggle keeps focus.
113+ < Tooltip disabled = { expanded } >
114+ < TooltipTrigger
115+ render = {
116+ < button
117+ type = "button"
118+ { ...toggle }
119+ aria-expanded = { expanded }
120+ aria-label = { `${ props . group . title } , ${ children . length } child ${ children . length === 1 ? "thread" : "threads" } ` }
121+ className = { cn (
122+ "flex h-full min-w-0 max-w-[calc(100%-1.75rem)] cursor-pointer items-center gap-1.5 rounded-t-lg bg-sidebar-row-hover/60 px-2.5 text-left text-xs font-medium focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70" ,
123+ dragging ? "text-sidebar-foreground/80" : "text-sidebar-muted-foreground" ,
124+ ) }
125+ />
126+ }
127+ >
128+ < span className = "truncate" > { props . group . title } </ span >
129+ < span className = "shrink-0 tabular-nums opacity-70" > { children . length } </ span >
130+ { statusDots . length > 0 ? < SidebarThreadGroupStatusDots dots = { statusDots } /> : null }
131+ < ChevronDownIcon
132+ aria-hidden
133+ className = { cn ( "size-3 shrink-0 transition-transform" , ! expanded && "rotate-180" ) }
134+ />
135+ </ TooltipTrigger >
136+ < TooltipPopup side = "right" >
137+ { statusDots . map ( ( dot ) => (
138+ < div key = { dot . key } className = "flex items-center gap-1.5" >
139+ < span className = { cn ( "size-2 shrink-0 rounded-full" , dot . className ) } />
140+ < span className = "truncate" > { dot . title } </ span >
141+ < span className = "text-muted-foreground" > { dot . label } </ span >
142+ </ div >
143+ ) ) }
144+ </ TooltipPopup >
145+ </ Tooltip >
101146 ) : (
102147 < CollapsibleSectionHeader
103148 expanded = { expanded }
104149 tone = { dragging ? "emphasized" : "muted" }
105- aria-busy = { props . isGenerating || undefined }
106- onClick = { ( ) => props . onCollapsedChange ( expanded ) }
107- onDoubleClick = { ( ) => props . canEdit && setIsEditing ( true ) }
150+ { ...toggle }
108151 // Room for the hover menu, so it never covers the label.
109152 accessory = { < span aria-hidden className = "w-5 shrink-0" /> }
110153 >
@@ -115,7 +158,12 @@ export function SidebarThreadGroupHeader(props: {
115158 </ CollapsibleSectionHeader >
116159 ) }
117160 { isEditing || ! props . canEdit ? null : (
118- < div className = "absolute inset-y-0 right-6 flex items-center opacity-0 transition-opacity group-hover/thread-group:opacity-100 group-focus-within/thread-group:opacity-100 has-[[data-popup-open]]:opacity-100" >
161+ < div
162+ className = { cn (
163+ "flex items-center opacity-0 transition-opacity group-hover/thread-group:opacity-100 group-focus-within/thread-group:opacity-100 has-[[data-popup-open]]:opacity-100" ,
164+ children ? "h-full" : "absolute inset-y-0 right-6" ,
165+ ) }
166+ >
119167 < Menu >
120168 < MenuTrigger
121169 render = {
@@ -145,66 +193,51 @@ export function SidebarThreadGroupHeader(props: {
145193 ) ;
146194}
147195
148- const FOLD_DOT : Record < SidebarThreadStatus | "done" , { label : string ; className : string } > = {
196+ // Key order is urgency: a collapsed tab shows the first MAX_STATUS_DOTS, so a
197+ // child that needs attention never hides behind the overflow count.
198+ const STATUS_DOT : Record < SidebarThreadStatus | "done" , { label : string ; className : string } > = {
149199 approval : { label : "Approval" , className : "bg-warning" } ,
150200 input : { label : "Input" , className : "bg-indigo-500" } ,
151- working : { label : "Working" , className : "bg-info" } ,
152- waiting : { label : "Waiting" , className : "bg-muted-foreground/60" } ,
201+ request : { label : "Request" , className : "bg-guest" } ,
153202 failed : { label : "Failed" , className : "bg-error" } ,
154203 limited : { label : "Limited" , className : "bg-warning" } ,
155204 done : { label : "Done" , className : "bg-success" } ,
205+ working : { label : "Working" , className : "bg-info" } ,
206+ waiting : { label : "Waiting" , className : "bg-muted-foreground/60" } ,
156207 ready : { label : "Read" , className : "border border-muted-foreground/50" } ,
157208} ;
209+ const URGENCY = Object . keys ( STATUS_DOT ) ;
210+ const MAX_STATUS_DOTS = 6 ;
158211
159- // A collapsed group keeps its parent row; the children fold into this strip
160- // under it, one dot per child in the row's own status colours, so a finished
161- // or blocked child still shows without opening the group.
162- export function SidebarThreadGroupFoldFork ( props : {
163- readonly threads : readonly EnvironmentThreadShell [ ] ;
164- readonly onExpand : ( ) => void ;
165- } ) {
212+ // A collapsed parent group keeps its parent row; its tab carries status dots
213+ // for the hidden children in the rows' own colours, so a finished or blocked child
214+ // still shows without opening the group. The tab's tooltip lists every child.
215+ function useChildStatusDots ( threads : readonly EnvironmentThreadShell [ ] | null ) {
166216 const localVisits = useUiStateStore ( ( state ) => state . threadLastVisitedAtById ) ;
167- const dots = props . threads . map ( ( thread ) => {
168- const key = scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) ;
169- const lastVisitedAt = resolveThreadLastVisitedAt ( thread . lastVisitedAt , localVisits [ key ] ) ;
170- const status = resolveSidebarThreadStatus ( thread ) ;
171- const kind =
172- status === "ready" && hasUnseenCompletion ( { ...thread , lastVisitedAt } ) ? "done" : status ;
173- return { key, title : thread . title , ...FOLD_DOT [ kind ] } ;
174- } ) ;
217+ if ( threads === null ) return [ ] ;
218+ return threads
219+ . map ( ( thread ) => {
220+ const key = scopedThreadKey ( scopeThreadRef ( thread . environmentId , thread . id ) ) ;
221+ const lastVisitedAt = resolveThreadLastVisitedAt ( thread . lastVisitedAt , localVisits [ key ] ) ;
222+ const status = resolveSidebarThreadStatus ( thread ) ;
223+ const kind =
224+ status === "ready" && hasUnseenCompletion ( { ...thread , lastVisitedAt } ) ? "done" : status ;
225+ return { key, kind, title : thread . title , ...STATUS_DOT [ kind ] } ;
226+ } )
227+ . toSorted ( ( a , b ) => URGENCY . indexOf ( a . kind ) - URGENCY . indexOf ( b . kind ) ) ;
228+ }
229+
230+ function SidebarThreadGroupStatusDots ( props : {
231+ readonly dots : ReturnType < typeof useChildStatusDots > ;
232+ } ) {
233+ const overflow = props . dots . length - MAX_STATUS_DOTS ;
175234 return (
176- < Tooltip >
177- < TooltipTrigger
178- render = {
179- < button
180- type = "button"
181- data-testid = "sidebar-thread-group-fold"
182- aria-label = { `Show ${ dots . length } child threads` }
183- onClick = { props . onExpand }
184- className = "mt-0.5 ml-2 flex h-6 w-[calc(100%-0.5rem)] cursor-pointer items-center gap-1.5 rounded-r-md border-l border-sidebar-border/70 pl-2.5 text-secondary-label text-xs hover:bg-sidebar-row-hover"
185- />
186- }
187- >
188- < ChevronRightIcon aria-hidden className = "size-3 shrink-0" />
189- < span className = "shrink-0 tabular-nums" >
190- { dots . length } { dots . length === 1 ? "thread" : "threads" }
191- </ span >
192- < span className = "flex min-w-0 items-center gap-1 overflow-hidden" >
193- { dots . map ( ( dot ) => (
194- < span key = { dot . key } className = { cn ( "size-2 shrink-0 rounded-full" , dot . className ) } />
195- ) ) }
196- </ span >
197- </ TooltipTrigger >
198- < TooltipPopup side = "right" >
199- { dots . map ( ( dot ) => (
200- < div key = { dot . key } className = "flex items-center gap-1.5" >
201- < span className = { cn ( "size-2 shrink-0 rounded-full" , dot . className ) } />
202- < span className = "truncate" > { dot . title } </ span >
203- < span className = "text-muted-foreground" > { dot . label } </ span >
204- </ div >
205- ) ) }
206- </ TooltipPopup >
207- </ Tooltip >
235+ < span data-testid = "sidebar-thread-group-dots" className = "flex shrink-0 items-center gap-0.5" >
236+ { props . dots . slice ( 0 , MAX_STATUS_DOTS ) . map ( ( dot ) => (
237+ < span key = { dot . key } className = { cn ( "size-2 shrink-0 rounded-full" , dot . className ) } />
238+ ) ) }
239+ { overflow > 0 ? < span className = "ms-0.5 tabular-nums" > +{ overflow } </ span > : null }
240+ </ span >
208241 ) ;
209242}
210243
0 commit comments