diff --git a/ui/src/components/app-sidebar-session-list.ts b/ui/src/components/app-sidebar-session-list.ts index 4ad1a52552a0..e3b2919c8a71 100644 --- a/ui/src/components/app-sidebar-session-list.ts +++ b/ui/src/components/app-sidebar-session-list.ts @@ -27,6 +27,8 @@ import { icons } from "./icons.ts"; import { renderSessionRowBadges } from "./session-row-badges.ts"; import "./elapsed-time.ts"; +const SIDEBAR_VISIBLE_CHILD_SESSION_LIMIT = 4; + /** Session-list presentation and catalog renderer wiring. */ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElement { @state() protected catalogProjectGrouping = loadStoredSidebarCatalogGrouping(); @@ -242,6 +244,22 @@ export abstract class AppSidebarSessionListElement extends AppSidebarMenusElemen private renderSessionTree(session: SidebarRecentSession): TemplateResult { const expanded = this.isSessionChildrenExpanded(session); + const showAllChildren = this.fullyShownChildSessionKeys.has(session.key); + // The cap hides quiet children only: the active branch and any branch with + // live runs (runningChildCount is transitive) must stay visible, or an + // auto-expanded parent would omit its own selection or a running session. + const visibleChildren = showAllChildren + ? session.children + : session.children.filter( + (child, index) => + index < SIDEBAR_VISIBLE_CHILD_SESSION_LIMIT || + child.visuallyActive || + child.containsActiveDescendant || + child.hasActiveRun || + child.status === "running" || + child.runningChildCount > 0, + ); + const hiddenChildCount = session.children.length - visibleChildren.length; return html`