Skip to content

Commit f93ae9c

Browse files
longtngoclaude
andcommitted
feat(web): fold the Tasks, Background and Lineage sections of the thread details card
Each section's title toggles its rows; the choice is remembered per section on the device, so folding Lineage once keeps it folded on every thread. Header chips and menus stay visible. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
1 parent 1f3c7b6 commit f93ae9c

7 files changed

Lines changed: 109 additions & 19 deletions

‎apps/web/src/components/BackgroundTasksPanel.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const BackgroundTasksPanel = memo(function BackgroundTasksPanel({
4242
return (
4343
<ThreadDetailsSection
4444
headingId="thread-details-background-heading"
45+
collapseKey="background"
4546
title={`Background · ${tasks.length} running`}
4647
data-thread-details-activity
4748
>

‎apps/web/src/components/TaskListPanel.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ export const TaskListPanel = memo(function TaskListPanel({
123123
return (
124124
<ThreadDetailsSection
125125
headingId="thread-details-tasks-heading"
126+
collapseKey="tasks"
126127
title={`Tasks · ${completed}/${primary.steps.length}`}
127128
data-thread-details-activity
128129
actions={
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { beforeEach, describe, expect, it } from "vite-plus/test";
2+
import { renderDom } from "../../testing/renderDom";
3+
import { ThreadDetailsSection } from "./ThreadDetailsSection";
4+
5+
const section = (collapseKey?: "tasks" | "lineage") => (
6+
<ThreadDetailsSection
7+
headingId="h"
8+
title="Tasks · 1/3"
9+
collapseKey={collapseKey}
10+
actions={<span data-action>chip</span>}
11+
>
12+
<div data-body>rows</div>
13+
</ThreadDetailsSection>
14+
);
15+
const toggle = (view: Awaited<ReturnType<typeof renderDom>>) =>
16+
view.findAll("button").find((b) => b.hasAttribute("aria-expanded")) ?? null;
17+
18+
describe("ThreadDetailsSection", () => {
19+
beforeEach(() => {
20+
localStorage.clear();
21+
});
22+
23+
it("folds its rows and keeps the header actions", async () => {
24+
const view = await renderDom(section("tasks"));
25+
expect(view.container.querySelector("[data-body]")).not.toBeNull();
26+
await view.click(toggle(view));
27+
expect(view.container.querySelector("[data-body]")).toBeNull();
28+
expect(view.container.querySelector("[data-action]")).not.toBeNull();
29+
expect(toggle(view)?.getAttribute("aria-expanded")).toBe("false");
30+
await view.click(toggle(view));
31+
expect(view.container.querySelector("[data-body]")).not.toBeNull();
32+
});
33+
34+
it("stays folded for the next thread, per section", async () => {
35+
const first = await renderDom(section("tasks"));
36+
await first.click(toggle(first));
37+
const nextThread = await renderDom(section("tasks"));
38+
expect(nextThread.container.querySelector("[data-body]")).toBeNull();
39+
const lineage = await renderDom(section("lineage"));
40+
expect(lineage.container.querySelector("[data-body]")).not.toBeNull();
41+
});
42+
43+
it("has no toggle without a collapse key", async () => {
44+
const view = await renderDom(section());
45+
expect(toggle(view)).toBeNull();
46+
expect(view.container.querySelector("[data-body]")).not.toBeNull();
47+
});
48+
});
Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
1+
import { ChevronDownIcon } from "lucide-react";
2+
import * as Schema from "effect/Schema";
13
import type { ComponentProps, ReactNode } from "react";
24

5+
import { useLocalStorage } from "~/hooks/useLocalStorage";
36
import { cn } from "../../lib/utils";
47

5-
/** Sections share header and content insets in both the sidebar and popover. */
8+
/**
9+
* Sections share header and content insets in both the sidebar and popover. A `collapseKey`
10+
* makes the title fold the rows; the choice is per section and per device, so folding Lineage
11+
* once keeps it folded on every thread. Header actions stay visible while folded.
12+
*/
613
export function ThreadDetailsSection({
714
headingId,
815
title,
916
actions,
17+
collapseKey,
1018
separated = true,
1119
showHeading = true,
1220
children,
@@ -15,31 +23,54 @@ export function ThreadDetailsSection({
1523
headingId: string;
1624
title: string;
1725
actions?: ReactNode;
26+
collapseKey?: "tasks" | "background" | "lineage" | undefined;
1827
separated?: boolean;
1928
showHeading?: boolean;
2029
}) {
30+
const [collapsed, setCollapsed] = useLocalStorage(
31+
`t3code:thread-details:collapsed:${collapseKey ?? "none"}`,
32+
false,
33+
Schema.Boolean,
34+
);
35+
const folded = collapseKey !== undefined && collapsed;
2136
return (
2237
<section
2338
{...props}
2439
aria-labelledby={showHeading ? headingId : undefined}
2540
aria-label={showHeading ? undefined : title}
26-
className={cn("px-2 pt-2 pb-2.5", separated && "border-t border-border/65")}
41+
className={cn("px-2 pt-2 pb-2.5", separated && "border-t border-border/65", folded && "pb-2")}
2742
>
2843
<div
2944
className={cn(
30-
"mb-1 flex min-h-8 min-w-0 items-center justify-between gap-2 px-1.5",
45+
"flex min-h-8 min-w-0 items-center justify-between gap-2 px-1.5",
46+
!folded && "mb-1",
3147
!showHeading && "hidden",
3248
)}
3349
>
3450
<h3
3551
id={headingId}
3652
className="min-w-0 truncate text-2xs font-medium text-muted-foreground select-none"
3753
>
38-
{title}
54+
{collapseKey === undefined ? (
55+
title
56+
) : (
57+
<button
58+
type="button"
59+
aria-expanded={!folded}
60+
onClick={() => setCollapsed(!folded)}
61+
className="flex max-w-full cursor-pointer items-center gap-1 rounded-sm hover:text-foreground/80 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/70"
62+
>
63+
<span className="truncate">{title}</span>
64+
<ChevronDownIcon
65+
aria-hidden
66+
className={cn("size-3 shrink-0 transition-transform", !folded && "rotate-180")}
67+
/>
68+
</button>
69+
)}
3970
</h3>
4071
{actions ? <div className="flex shrink-0 items-center gap-1">{actions}</div> : null}
4172
</div>
42-
{children}
73+
{folded ? null : children}
4374
</section>
4475
);
4576
}

‎apps/web/src/components/chat/ThreadRelationshipsControl.agents.test.tsx‎

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,21 @@ import { ThreadRelationshipsPanel } from "./ThreadRelationshipsControl";
4242

4343
let renderer: ReactTestRenderer;
4444

45+
// Row-group disclosures, excluding the section's own fold toggle in its heading.
46+
const rowGroupToggles = (root: ReactTestInstance, expanded: boolean) =>
47+
root.findAll((node) => {
48+
if (node.type !== "button" || node.props["aria-expanded"] !== expanded) return false;
49+
for (let parent = node.parent; parent; parent = parent.parent) {
50+
if (parent.type === "h3") return false;
51+
}
52+
return true;
53+
});
54+
const rowGroupToggle = (root: ReactTestInstance, expanded: boolean) => {
55+
const [toggle, ...rest] = rowGroupToggles(root, expanded);
56+
if (!toggle || rest.length > 0) throw new Error(`Expected one row-group toggle (${expanded})`);
57+
return toggle;
58+
};
59+
4560
afterEach(async () => {
4661
await act(async () => renderer?.unmount());
4762
vi.unstubAllGlobals();
@@ -216,7 +231,7 @@ it("shows the matching child agent details and refreshes them when the agent set
216231
expect(text()).not.toContain("tok");
217232
expect(text()).not.toContain("Unlinked agent");
218233
expect(text()).not.toContain("Active agents");
219-
expect(renderer.root.findAllByProps({ type: "button", "aria-expanded": true })).toHaveLength(0);
234+
expect(rowGroupToggles(renderer.root, true)).toHaveLength(0);
220235

221236
state.projection = {
222237
...projection,
@@ -231,27 +246,21 @@ it("shows the matching child agent details and refreshes them when the agent set
231246
],
232247
};
233248
await act(async () => renderer.update(cloneElement(panel)));
234-
expect(renderer.root.findByType("h3").children).toEqual(["Lineage"]);
249+
expect(renderer.root.findByType("h3").findByType("span").children).toEqual(["Lineage"]);
235250
expect(text()).toContain("Previous agents (1)");
236251
expect(text()).not.toContain("Checker");
237-
await act(async () =>
238-
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
239-
);
252+
await act(async () => rowGroupToggle(renderer.root, false).props.onClick());
240253
expect(text()).toContain("Checker");
241254
// A started agent's row shows only its compact time; the icon carries the status.
242255
expect(text()).toContain("Checker 2m");
243256
expect(text()).not.toContain("(1)");
244257
expect(text()).not.toContain("Done");
245258
expect(text()).not.toContain("running");
246259
expect(text()).not.toContain("Worker");
247-
await act(async () =>
248-
renderer.root.findByProps({ type: "button", "aria-expanded": true }).props.onClick(),
249-
);
260+
await act(async () => rowGroupToggle(renderer.root, true).props.onClick());
250261
expect(text()).not.toContain("Checker");
251262
expect(text()).toContain("Previous agents (1)");
252-
await act(async () =>
253-
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
254-
);
263+
await act(async () => rowGroupToggle(renderer.root, false).props.onClick());
255264
expect(text()).toContain("Checker");
256265

257266
state.projection = {
@@ -634,9 +643,7 @@ it("shows readable models and only differing workspace details in agent tooltips
634643
],
635644
};
636645
await act(async () => renderer.update(cloneElement(panel)));
637-
await act(async () =>
638-
renderer.root.findByProps({ type: "button", "aria-expanded": false }).props.onClick(),
639-
);
646+
await act(async () => rowGroupToggle(renderer.root, false).props.onClick());
640647
expect(text()).toContain("Final checks passed.");
641648
expect(text()).not.toContain("Stale progress");
642649
expect(text()).not.toContain("Hidden tail");

‎apps/web/src/components/chat/ThreadRelationshipsControl.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ export function ThreadRelationshipsPanel(props: {
323323
return (
324324
<ThreadDetailsSection
325325
headingId="thread-details-lineage-heading"
326+
collapseKey="lineage"
326327
title={runningCount > 0 ? `Lineage · ${runningCount} running` : "Lineage"}
327328
data-thread-relationships-panel
328329
actions={

‎apps/web/src/hooks/useLocalStorage.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ export function useLocalStorage<T, E>(
113113

114114
const subscribe = useCallback(
115115
(onStoreChange: () => void) => {
116+
if (typeof window === "undefined") return () => {};
116117
const handleStorageChange = (event: StorageEvent) => {
117118
if (event.key === key) {
118119
onStoreChange();

0 commit comments

Comments
 (0)