Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {ContextHelp} from "./context-help";
import {ArrowRight, ChevronDown, Circle, CircleAlert, CircleCheck, CircleHelp, Clock, Hand, Info, List, Play, Plus, Search} from "lucide-react";
import {useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode} from "react";
import {Component, createRef, useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode} from "react";
import type {GoalWorkDisplayClass, GoalWorkspaceDigest} from "../../../../../../loopx/control_plane/presentation/goal_workspace_digest.js";
import type {WorkspaceActionPreview, WorkspaceActionPreviewRequest, WorkspaceDrawerSelection, WorkspaceGoal, WorkspaceModel, WorkspaceTimelineItem} from "./personal-workspace-model";
import {localizedSessionStatus, useWorkspaceI18n} from "./i18n";
Expand Down Expand Up @@ -223,7 +223,7 @@ export function GoalWorkspaceWork({goal, digest, items, userTodos, selectedTodoI
</div> : null}
{!readOnly ? <AddTask goal={goal} proposals={proposals} onPreview={onPreview} onSelect={select}/> : null}
</header>
<div className="goal-owner-groups" hidden={lens !== "owner"}>{digest.work.groups.map(group => <section className="goal-owner-group" key={group.ownerId ?? ""} data-owner-id={group.ownerId ?? ""}>
<OwnerWorkGroups hidden={lens !== "owner"}>{digest.work.groups.map(group => <section className="goal-owner-group" key={group.ownerId ?? ""} data-owner-id={group.ownerId ?? ""}>
<header><h3>{ownerName(group.ownerId)}</h3><span>{group.todoIds.length} {zh ? "项任务" : "tasks"} · {group.todoIds.filter(id => rows.get(id)?.displayClass === group.displayClass).length} {goalWorkClassLabel(group.displayClass, zh)}</span>
{!readOnly && group.ownerId && onOpenAgentConversation ? <button type="button" className="goal-owner-conversation" data-agent-id={group.ownerId} aria-label={zh ? `与 ${ownerName(group.ownerId)} 对话` : `Talk to ${ownerName(group.ownerId)}`} onClick={() => onOpenAgentConversation(group.ownerId!)}>{zh ? "工作记录" : "Work conversation"}</button> : null}
</header>
Expand All @@ -233,7 +233,7 @@ export function GoalWorkspaceWork({goal, digest, items, userTodos, selectedTodoI
{group.todoIds.slice(3).map(id => task(id))}
</RemainingWork> : null}
</section>)}
</div>
</OwnerWorkGroups>
{visited.has("board") || lens === "board" ? <div hidden={lens !== "board"}>{board}</div> : null}
{visited.has("map") || lens === "map" ? <div hidden={lens !== "map"}>{map}</div> : null}
</section>
Expand All @@ -254,6 +254,35 @@ export function GoalWorkspaceWork({goal, digest, items, userTodos, selectedTodoI
</div>;
}

type OwnerWorkGroupsProps = {hidden: boolean; children: ReactNode};

class OwnerWorkGroups extends Component<OwnerWorkGroupsProps, object, string | null> {
private readonly groups = createRef<HTMLDivElement>();

getSnapshotBeforeUpdate(): string | null {
const groups = this.groups.current;
const focused = groups?.ownerDocument.activeElement;
return focused instanceof HTMLButtonElement && groups?.contains(focused)
? focused.dataset.todoId ?? null : null;
}

componentDidUpdate(_previousProps: OwnerWorkGroupsProps, _previousState: object, todoId: string | null) {
// Crossing the summary boundary replaces the button. Restore its focus if
// the browser dropped it during this commit and the same task is still here.
const groups = this.groups.current;
if (!todoId || !groups || groups.closest("[hidden]") || groups.ownerDocument.activeElement !== groups.ownerDocument.body) return;
const row = groups.querySelector<HTMLButtonElement>(`button[data-todo-id="${CSS.escape(todoId)}"]`);
if (!row) return;
const disclosure = row.closest<HTMLDetailsElement>("details.goal-work-more");
if (disclosure) disclosure.open = true;
row.focus();
}

render() {
return <div className="goal-owner-groups" hidden={this.props.hidden} ref={this.groups}>{this.props.children}</div>;
}
}

function RemainingWork({selectedTodoId, label, children}: {selectedTodoId: string | null; label: string; children: ReactNode}) {
const disclosure = useRef<HTMLDetailsElement>(null);
useEffect(() => {if (selectedTodoId && disclosure.current) disclosure.current.open = true;}, [selectedTodoId]);
Expand Down
35 changes: 35 additions & 0 deletions examples/personal-workspace-browser/goal-workspace-m2.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ async function runM2Pass({browser, collectCoverage, url}) {
const renderBudget = {coverageEnabled:collectCoverage,initialMs,expandMs,switchMs,switchSamplesMs,...lensBudget,
longTaskSupported,switchLongTasks,nodeCount:200};
console.log(JSON.stringify({m2RenderBudget:renderBudget}));
await verifyFocusAfterReprioritization(page, now, many[4]);
assert.equal(writes.length,0,`Rendering created effects: ${writes}`);
assert.equal(session.errors.length,0,session.errors.join('\n'));
if (!collectCoverage) assert.ok(lensBudget.withinBudget, `Loaded lens switches exceeded repeated 1s target or 2s ceiling: ${JSON.stringify({switchSamplesMs,...lensBudget})}`);
Expand All @@ -295,6 +296,40 @@ async function runM2Pass({browser, collectCoverage, url}) {
finally {await session.close();}
}

async function verifyFocusAfterReprioritization(page, now, todo) {
const byOwner = now.getByRole("button", {name:"按负责人", exact:true});
await byOwner.click();
const owner = now.locator('.goal-owner-group[data-owner-id="worker-0"]');
const remaining = owner.locator(".goal-work-more");
await remaining.locator(":scope > summary").press("Enter");
assert.equal(await remaining.evaluate(node => node.open), false);

const row = `[data-todo-id="${todo.todo_id}"]`;
const leading = owner.locator(`:scope > ${row}`);
const moved = remaining.locator(`${row}[data-work-class="blocked"]`);
const refresh = page.getByRole("button", {name:"刷新状态", exact:true});
// Simulate a status refresh while the keyboard user remains on the page.
const refreshWithoutMovingFocus = () => refresh.evaluate(button => button.click());

await byOwner.focus();
todo.status = "blocked";
await refreshWithoutMovingFocus();
await moved.waitFor({state:"attached"});
assert.equal(await moved.isVisible(), false, "An unfocused task does not open its disclosure on refresh");
assert.equal(await byOwner.evaluate(node => document.activeElement === node), true, "Refresh leaves focus outside the task list alone");

todo.status = "open";
await refreshWithoutMovingFocus();
await leading.focus();
todo.status = "blocked";
await refreshWithoutMovingFocus();
await moved.waitFor({state:"attached"});
assert.equal(await moved.evaluate(node => document.activeElement === node), true, "The same task keeps keyboard focus after it moves");
await page.keyboard.press("Enter");
await page.waitForURL(value => value.searchParams.get("todo") === todo.todo_id);
await page.locator(".personal-context-drawer").waitFor();
}


async function verifyRemoteSelection(browser, url) {
const snapshot = JSON.parse(await readFile(resolve(repoRoot,"examples/status.example.json"),"utf8"));
Expand Down
Loading