fix(webui): open subtask details from task content

Handle tool activity, errors and result-body clicks at the task item while preserving selection, nested controls, image portals and detail focus. Remove the sticky-title workaround.

Refs NAN-369
This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-27 13:22:34 +08:00
1 parent 40ee25f885
commit 0978ccd50f
3 files changed
+75 -25

No files matched your search

@@ -210,8 +210,16 @@ function TaskTree({ tasks, maxHeight }: { tasks: ObservedSubagentTask[]; maxHeig
return <div data-testid="subagent-task-tree" style={{ maxHeight }} className="min-h-0 overflow-y-auto overscroll-contain p-1.5 pt-0 scrollbar-thin">
<ol className="space-y-0.5">
{tasks.map(task => <li key={task.task_id} data-task-state={task.state}
className="rounded-lg transition-colors duration-150 hover:bg-muted/50 focus-within:bg-muted/50 motion-reduce:transition-none">
<div className="sticky top-0 z-20 flex min-w-0 items-center gap-0.5 bg-card">
onClick={event => {
const target = event.target;
if (event.defaultPrevented || !(target instanceof Element) || !event.currentTarget.contains(target)
|| target.closest("button, a[href], input, textarea, select, summary, [role=button], [role=link], [contenteditable=true]")) return;
const selection = window.getSelection();
if (selection && !selection.isCollapsed && selection.containsNode(event.currentTarget, true)) return;
context.open(task, event.currentTarget.querySelector<HTMLButtonElement>("[data-subagent-id]")!);
}}
className="cursor-pointer rounded-lg transition-colors duration-150 hover:bg-muted/50 focus-within:bg-muted/50 motion-reduce:transition-none">
<div className="flex min-w-0 items-center gap-0.5">
<SubagentTaskButton task={task} surface="activity" />
{task.state === "queued" || task.state === "running" ? <HoverHint content={t("thread.subagents.stopTask", { label: task.label })}>
<Button type="button" variant="ghost" size="icon"
+23 -3
View File
@@ -432,10 +432,30 @@ describe("session-owned task UI", () => {
expect(evidence).toHaveAttribute("rel", "noreferrer noopener");
expect(within(tree).queryByRole("link", { name: "Unsafe link" })).not.toBeInTheDocument();
expect(tree.querySelector("pre")?.textContent).toContain("const verified = true;");
await user.click(within(tree).getByRole("button", { name: /Config check Completed/ }));
await user.click(within(tree).getByText("Final finding after the long result."));
expect(await within(screen.getByRole("dialog", { name: "Config check" })).findByRole("link", { name: /Full evidence/ })).toHaveAttribute("href", "https://example.com/evidence");
});
it("opens the owning task from tool activity and error content", async () => {
vi.mocked(fetch).mockImplementation(async () => response([
task({ tool_events: [{ name: "read_file", status: "running" }] }),
task({ task_id: "sibling", label: "Sibling check", created_at: 101, tool_events: [{ name: "exec", status: "running" }] }),
]));
const user = userEvent.setup();
render(layout());
const tree = await openTaskList(user);
await user.click(within(tree).getByText("exec"));
expect(screen.getByRole("dialog", { name: "Sibling check" })).toBeVisible();
await user.keyboard("{Escape}");
await user.click(within(tree).getByText("read_file"));
expect(screen.getByRole("dialog", { name: "Config check" })).toBeVisible();
await user.keyboard("{Escape}");
emitTask(task({ revision: 2, state: "error", error: "Cannot read configuration", completed_at: 102 }));
await user.click(within(tree).getByText("Cannot read configuration"));
expect(screen.getByRole("dialog", { name: "Config check" })).toBeVisible();
expect(requestMutation).not.toHaveBeenCalled();
});
it("keeps result-owned image portals inside the drawer interaction boundary", async () => {
await preloadMarkdownText();
const user = userEvent.setup();
@@ -444,8 +464,8 @@ describe("session-owned task UI", () => {
emitTask(task({ revision: 2, state: "done", completed_at: 102, result: "![Result image](https://example.com/result.png)" }));
await user.click(await within(tree).findByRole("button", { name: "View image: Result image" }));
const viewer = screen.getByRole("dialog", { name: "Result image" });
fireEvent.pointerDown(within(viewer).getByRole("img", { name: "Result image" }));
expect(viewer).toBeInTheDocument();
await user.click(within(viewer).getByRole("img", { name: "Result image" }));
expect(screen.getAllByRole("dialog")).toEqual([viewer]);
expect(screen.getByTestId("subagent-task-dock-trigger")).toHaveAttribute("aria-expanded", "true");
await user.keyboard("{Escape}");
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();