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
14 changes: 13 additions & 1 deletion plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1520,6 +1520,16 @@ one (omitted for ops), and the status phrase. A row that needs you adds its
prompt and one-click actions under line two, in the same row, with no tinted
callout box.

A **Recently ended** row is that same row (BB-88): `sidebar.ts`'s
`endedEffort` builds the ended binding as a quiet effort with no children, the
entity's final phase, and the end reason in the status-phrase slot (`terminal`,
`deleted`, `label removed` for a removed label, `no longer listed` when the
entity is gone, `no longer configured` when the project stopped stewarding
it), and the row keeps the `ended N ago` stamp
at the right, which is what distinguishes the section. The steward thread is
usually archived by then, so the title comes from the RPC and the row renders
without the thread actions menu when the thread is no longer in the live view.

The glyph is one of four shapes, in precedence order `you › blocked › running ›
quiet`: a solid yellow dot when it waits on you, an empty red ring when
blocked (`blockedOn`, a hold or `stuck`), a blue ring that pulses slowly while
Expand Down Expand Up @@ -1553,7 +1563,9 @@ covers every rule and the precedence.
whether stewarded or `ops`; a needs-you, blockedOn, held or stuck `ops`
binding leaves Monitors for Blocked. In flight holds the rest of the stewarded,
non-ops efforts, running before quiet, then by recency. Pinned rows stay first within their section.
`buildSidebar` returns `blocked`, `efforts`, `threads` and `monitors`
Recently ended holds the ended bindings, newest first, each built by
`endedEffort` as a quiet effort with no children (BB-88).
`buildSidebar` returns `blocked`, `efforts`, `threads`, `monitors` and `ended`
separately, and the split is unit tested in `sidebar.test.ts`.

**Rows, highlighting and auto-expand (BB-85).** A stewarded effort row in
Expand Down
9 changes: 8 additions & 1 deletion plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,14 @@ ring when quiet. One-off threads use the same four glyphs — yellow when unread
blue animated while their agent runs, grey otherwise — except a draft, which
keeps bb's own glyph. A worker or reviewer child row under an effort, and a
one-off thread's children, share those glyphs and carry no role tag. An `ops`
binding that needs you or is blocked moves from Monitors into Blocked.
binding that needs you or is blocked moves from Monitors into Blocked. A
**Recently ended** row is the same two-line effort row (BB-88): the grey quiet
ring, the kind, the entity's final phase and the end reason (`terminal`,
`deleted`, `label removed` for a removed label, `no longer listed` when the
entity is gone, `no longer configured` when the project stopped stewarding it)
in place of the status phrase, no children, and the
`ended N ago` stamp on the right. Its steward thread is usually archived, so the
title comes from the server and the row still renders when the thread is gone.

**Rows, highlighting and auto-expand (BB-85).** An effort row in Blocked, In
flight or Monitors and a Recently ended row are real links to the effort's
Expand Down
145 changes: 67 additions & 78 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import {
} from "@get-bb/plugin-sdk/app";
import type { rpcContract } from "./server";
import { NEEDS_YOU_CHANGED } from "./channels.js";
import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, isBusy, type EffortStatus, type SidebarChild, type SidebarChildRole, type SidebarEffort, type SidebarEffortState, type SidebarEnded, type SidebarSection, type SidebarTab } from "./sidebar.js";
import { buildSidebar, compareBlocked, compareEfforts, compareInflight, deploymentPhrase, effortPhrase, effortSection, effortState, effortTitle, isBusy, type EffortStatus, type SidebarChild, type SidebarChildRole, type SidebarEffort, type SidebarEffortState, type SidebarSection, type SidebarTab } from "./sidebar.js";
import { AUTOMATIC_THREAD_LIST_PROVIDER, BUILTIN_THREAD_LIST_ID, THREAD_LIST_PROVIDER_KEY, stewardsThreadListId } from "./sidebar-provider.js";

type Client = ReturnType<typeof useRpc<typeof rpcContract>>;
Expand Down Expand Up @@ -1401,6 +1401,7 @@ function SidebarEffortRow({
openThreads,
onNavigate,
onChanged,
trailing,
}: {
effort: SidebarEffort;
needs: readonly SidebarNeedItem[];
Expand All @@ -1414,15 +1415,20 @@ function SidebarEffortRow({
openThreads: ReadonlySet<string>;
onNavigate: () => void;
onChanged: () => void;
/** A right-aligned stamp after the title, for a Recently ended row's `ended N ago` (BB-88). */
trailing?: ReactNode;
}) {
const root = byId.get(effort.rootThreadId);
const navigate = useBbNavigate();
const pluginId = experimental_usePluginId();
const [open, setOpen] = useState(false);
const key = effort.bindingKey;
if (root === undefined || key === null) return null;
if (key === null) return null;
const displayKey = shortBindingKey(key);
const title = effortTitle(root.displayTitle, key);
// A Recently ended binding's steward thread is usually archived and so absent
// from the live view; its title comes from the RPC and the row renders without
// the thread actions context menu (BB-88).
const title = effortTitle(root?.displayTitle ?? effort.title, key);
const count = countThreads(effort.children);
const mine = needs.filter((item) => item.bindingKey !== null && item.bindingKey === key);
const selected = activeKey !== null && activeKey === key;
Expand All @@ -1431,50 +1437,52 @@ function SidebarEffortRow({
if (revealed) setOpen(true);
}, [revealed]);
const href = boardHref(pluginId, projectId, key);
const body = (
<div className={`flex flex-col rounded-md py-0.5 pr-1 hover:bg-state-hover ${selected ? "bg-state-active" : ""}`} style={{ paddingLeft: "4px" }} title={key ?? undefined}>
<div className="flex items-center gap-1">
{count > 0 ? (
<button
type="button"
aria-label={`${open ? "Collapse" : "Expand"} ${root?.displayTitle ?? effort.title}`}
aria-expanded={open}
className="flex size-4 shrink-0 items-center justify-center text-muted-foreground"
onClick={() => setOpen((v) => !v)}
>
<Icon name={open ? "ChevronDown" : "ChevronRight"} className="size-3.5" />
</button>
) : (
<span className="flex size-4 shrink-0 items-center justify-center" />
)}
<span data-sidebar-status-slot="" className="flex size-4 shrink-0 items-center justify-center">
<StewardGlyph kind={effort.state} />
</span>
<a
href={href}
aria-current={selected ? "page" : undefined}
className="flex min-w-0 flex-1 items-baseline gap-1 text-sm"
title={root?.displayTitle ?? effort.title}
onClick={(e) => {
e.preventDefault();
navigate.toPluginPanel(BOARD_PATH, { subPath: boardSubPath(projectId, key) });
onNavigate();
}}
>
<span className="shrink-0 font-semibold">{displayKey}</span>
<span className="min-w-0 truncate">{title}</span>
</a>
{trailing}
</div>
<p className="text-[11px] text-muted-foreground" style={{ paddingLeft: "36px" }} data-sidebar-line-two="">
{kindLabel(effort.kind)}
{effort.phase !== null ? ` · ${effort.phase}` : ""}
{" · "}
<span className={phraseClass(effort.state)}>{effort.phrase}</span>
</p>
</div>
);
return (
<li className="flex flex-col">
<ThreadActionsContextMenu thread={actionTarget(root)}>
<div className={`flex flex-col rounded-md py-0.5 pr-1 hover:bg-state-hover ${selected ? "bg-state-active" : ""}`} style={{ paddingLeft: "4px" }} title={key ?? undefined}>
<div className="flex items-center gap-1">
{count > 0 ? (
<button
type="button"
aria-label={`${open ? "Collapse" : "Expand"} ${root.displayTitle}`}
aria-expanded={open}
className="flex size-4 shrink-0 items-center justify-center text-muted-foreground"
onClick={() => setOpen((v) => !v)}
>
<Icon name={open ? "ChevronDown" : "ChevronRight"} className="size-3.5" />
</button>
) : (
<span className="flex size-4 shrink-0 items-center justify-center" />
)}
<span data-sidebar-status-slot="" className="flex size-4 shrink-0 items-center justify-center">
<StewardGlyph kind={effort.state} />
</span>
<a
href={href}
aria-current={selected ? "page" : undefined}
className="flex min-w-0 flex-1 items-baseline gap-1 text-sm"
title={root.displayTitle}
onClick={(e) => {
e.preventDefault();
navigate.toPluginPanel(BOARD_PATH, { subPath: boardSubPath(projectId, key) });
onNavigate();
}}
>
<span className="shrink-0 font-semibold">{displayKey}</span>
<span className="min-w-0 truncate">{title}</span>
</a>
</div>
<p className="text-[11px] text-muted-foreground" style={{ paddingLeft: "36px" }} data-sidebar-line-two="">
{kindLabel(effort.kind)}
{effort.phase !== null ? ` · ${effort.phase}` : ""}
{" · "}
<span className={phraseClass(effort.state)}>{effort.phrase}</span>
</p>
</div>
</ThreadActionsContextMenu>
{root === undefined ? body : <ThreadActionsContextMenu thread={actionTarget(root)}>{body}</ThreadActionsContextMenu>}
{mine.length > 0 ? (
<div className="flex flex-col gap-1 pb-1" style={{ paddingLeft: "40px" }}>
{mine.map((item) => (
Expand Down Expand Up @@ -1614,7 +1622,7 @@ function revealThreads(tabs: readonly SidebarTab[], activeThreadId: string | nul
function revealSections(tabs: readonly SidebarTab[], activeThreadId: string | null, activeKey: string | null): ReadonlySet<string> {
const open = new Set<string>();
for (const tab of tabs) {
if ((activeThreadId !== null && tab.ended.some((e) => e.threadId === activeThreadId)) || (activeKey !== null && tab.ended.some((e) => e.key === activeKey))) open.add("Recently ended");
if ((activeThreadId !== null && tab.ended.some((e) => e.rootThreadId === activeThreadId)) || (activeKey !== null && tab.ended.some((e) => e.key === activeKey))) open.add("Recently ended");
if (activeThreadId !== null && tab.threads.some((e) => e.rootThreadId === activeThreadId || subtreeHas(e.children, activeThreadId))) open.add("Threads");
if (tab.monitors.some((e) => (activeKey !== null && e.bindingKey === activeKey) || (activeThreadId !== null && (e.rootThreadId === activeThreadId || subtreeHas(e.children, activeThreadId))))) open.add("Monitors");
}
Expand Down Expand Up @@ -1742,7 +1750,19 @@ function StewardsSidebarCore({
<SidebarCollapsible title="Recently ended" count={active.ended.length} revealed={openSections.has("Recently ended")}>
<ul className="flex flex-col">
{active.ended.map((e) => (
<SidebarEndedRow key={`${e.key}-${e.endedAt}`} ended={e} projectId={active.projectId} activeKey={activeKey} now={now} onNavigate={onNavigate} />
<SidebarEffortRow
key={`${e.key}-${e.endedAt}`}
effort={e}
needs={needItems}
byId={byId}
projectId={active.projectId}
activeKey={activeKey}
activeThreadId={activeThreadId}
openThreads={openThreads}
onNavigate={onNavigate}
onChanged={refetch}
trailing={<span className="shrink-0 text-[11px] text-muted-foreground">{ago(e.endedAt, now)}</span>}
/>
))}
</ul>
</SidebarCollapsible>
Expand Down Expand Up @@ -1770,37 +1790,6 @@ function StewardsSidebarCore({
);
}

/** A Recently ended row: a real link to the effort's detail view (BB-85). */
function SidebarEndedRow({ ended, projectId, activeKey, now, onNavigate }: { ended: SidebarEnded; projectId: string; activeKey: string | null; now: number; onNavigate: () => void }) {
const navigate = useBbNavigate();
const pluginId = experimental_usePluginId();
const selected = activeKey !== null && activeKey === ended.key;
return (
<li className="flex flex-col">
<a
href={boardHref(pluginId, projectId, ended.key)}
aria-current={selected ? "page" : undefined}
className={`flex items-center gap-1 rounded-md py-0.5 pr-1 hover:bg-state-hover ${selected ? "bg-state-active" : ""}`}
style={{ paddingLeft: "4px" }}
title={ended.key}
onClick={(e) => {
e.preventDefault();
navigate.toPluginPanel(BOARD_PATH, { subPath: boardSubPath(projectId, ended.key) });
onNavigate();
}}
>
<span className="flex size-4 shrink-0 items-center justify-center" />
<span data-sidebar-status-slot="" className="flex size-4 shrink-0 items-center justify-center">
<StewardGlyph kind="quiet" />
</span>
<span className="shrink-0 font-semibold">{shortBindingKey(ended.key)}</span>
<span className="min-w-0 flex-1 truncate text-muted-foreground">{ended.title ?? ""}</span>
<span className="shrink-0 text-[11px] text-muted-foreground">{ago(ended.endedAt, now)}</span>
</a>
</li>
);
}

/** The opt-in sidebar thread list (BB-44): the shared list with the route's active thread. */
function StewardsSidebar({ activeProjectId, activeThreadId, onNavigate }: PluginThreadListProps) {
const navigate = useBbNavigate();
Expand Down
4 changes: 2 additions & 2 deletions plugins/stewards/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ export const rpcContract = defineRpcContract({
reviewers: z.array(z.object({ threadId: z.string(), workerThreadId: z.string() })),
}),
),
ended: z.array(z.object({ key: z.string(), kind: z.string(), threadId: z.string().nullable(), title: z.string().nullable(), endedAt: z.number() })),
ended: z.array(z.object({ key: z.string(), kind: z.string(), threadId: z.string().nullable(), title: z.string().nullable(), phase: z.string().nullable(), endReason: z.string().nullable(), endedAt: z.number() })),
}),
),
}),
Expand Down Expand Up @@ -4796,7 +4796,7 @@ export function createStewardsPlugin(deps: StewardsDeps): (bb: BbPluginApi) => P
reviewers: workers.flatMap((w) => (reviewersByWorker.get(w.threadId) ?? []).map((threadId) => ({ threadId, workerThreadId: w.threadId }))),
};
}),
ended: ended.map((b) => ({ key: b.entityKey, kind: b.kind, threadId: b.threadId, title: b.title, endedAt: b.endedAt! })),
ended: ended.map((b) => ({ key: b.entityKey, kind: b.kind, threadId: b.threadId, title: b.title, phase: b.phase, endReason: b.endReason, endedAt: b.endedAt! })),
};
}),
};
Expand Down
33 changes: 29 additions & 4 deletions plugins/stewards/sidebar-app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ describe("the stewards sidebar list (BB-44)", () => {
stewardsSidebar: () =>
sidebarData({
bindings: [binding(), binding({ key: "acme/web", kind: "ops", stage: null, threadId: "thr_ops" })],
ended: [{ key: "ENG-0", kind: "ticket", threadId: null, title: "Old work", endedAt: 1_000 }],
ended: [{ key: "ENG-0", kind: "ticket", threadId: null, title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }],
}),
} as never,
});
Expand All @@ -344,7 +344,32 @@ describe("the stewards sidebar list (BB-44)", () => {
fireEvent.click(slot.getByRole("button", { name: /Monitors/u }));
await waitFor(() => expect(slot.getByText("acme/web")).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: /Recently ended/u }));
await waitFor(() => expect(slot.getByText("Old work")).toBeTruthy());
const old = await waitFor(() => slot.getByText("Old work"));
// BB-88: the same two-line effort row as a live binding, the end reason in
// the phrase slot, the grey quiet ring, and the ended stamp on the right.
expect(lineTwo(slot, "Old work")).toBe("ticket · Done · terminal");
expect(glyphOf(slot, "Old work")).toBe("quiet");
expect(old.closest("li")!.textContent).toMatch(/ago/u);
expect(old.closest("a")!.getAttribute("href")).toContain("/board/p1/ENG-0");
slot.lifecycle.unmount();
});

// BB-88 criterion 1: an ended binding whose steward thread is still in the
// live view renders through SidebarEffortRow, title stripped of the key.
it("renders a Recently ended binding with a live thread as the two-line effort row", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_old", displayTitle: "ENG-0: Old work" })] },
rpc: {
stewardsSidebar: () =>
sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: Date.now() - 2 * 86_400_000 }] }),
} as never,
});
fireEvent.click(await waitFor(() => slot.getByRole("button", { name: /Recently ended/u })));
const old = await waitFor(() => slot.getByText("Old work"));
expect(lineTwo(slot, "Old work")).toBe("ticket · Done · terminal");
expect(glyphOf(slot, "Old work")).toBe("quiet");
expect(old.closest("li")!.textContent).toMatch(/2d ago/u);
expect(old.closest("a")!.getAttribute("href")).toContain("/board/p1/ENG-0");
slot.lifecycle.unmount();
});

Expand Down Expand Up @@ -928,7 +953,7 @@ describe("the sidebar's highlighting and auto-expand (BB-85)", () => {
const ended = await renderSidebar(
{
sidebarThreads: { projects, threads: [] },
rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", endedAt: 1_000 }] }) } as never,
rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }] }) } as never,
},
{ activeThreadId: "thr_old" },
);
Expand All @@ -942,7 +967,7 @@ describe("the sidebar's highlighting and auto-expand (BB-85)", () => {
const panel = captured.navPanels[0]!;
const slot = renderSlot({ component: panel.experimental_sidebar! }, { subPath: "p1/ENG-0" }, {
sidebarThreads: { projects, threads: [] },
rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", endedAt: 1_000 }] }) } as never,
rpc: { stewardsSidebar: () => sidebarData({ ended: [{ key: "ENG-0", kind: "ticket", threadId: "thr_old", title: "Old work", phase: "Done", endReason: "terminal", endedAt: 1_000 }] }) } as never,
});
const old = await waitFor(() => slot.getByText("Old work"));
expect(old.closest("a")!.getAttribute("aria-current")).toBe("page");
Expand Down
Loading
Loading