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: 14 additions & 0 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,20 @@ bindings; a collapsed Recently ended row; and the project steward demoted to
one small row at the bottom. Every row carries bb's own thread actions
context menu, so archive, pin, rename, split and delete still work.

**Title-first rows (BB-48).** A row is the status glyph, the title, and — for
a stewarded effort — the binding key only when the title does not already name
it, plus the held and blocked badges. The title wins: it takes the available
width and truncates last, while the meta shrinks and truncates first. A key
shown is shortened (a pull request `acme/web#612` as `#612`, a ticket as its
own key) and the full key stays on the row's `title` attribute. The stage
leaves the row — the board still groups by stage, but a row no longer repeats
it — and the chevron no longer carries a child count, so only the chevron
signals children. A child row's worker/reviewer label is a small muted `W`/`R`
tag. One-off threads no longer share In flight: they sit in a collapsed
**Threads** row below it, so In flight counts stewarded efforts only.
`buildSidebar` returns `efforts`, `threads` and `watches` separately, and the
split is unit tested in `sidebar.test.ts`.

**Grouping is the steward relationship, not the thread tree.** A worker
belongs to its binding through the plugin's `workers` table and a reviewer
through the worker the RPC names, so BB-23's removal of the parent link cannot
Expand Down
53 changes: 43 additions & 10 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,19 @@ function countThreads(children: readonly SidebarChild[]): number {
return children.reduce((n, c) => n + 1 + countThreads(c.children), 0);
}

/** A pull-request key like `acme/web#612` shortens to `#612`; a ticket key stays its key. */
function shortBindingKey(key: string): string {
const pull = /#(\d+)$/.exec(key);
return pull === null ? key : `#${pull[1]}`;
}

const escapeRegExp = (text: string): string => text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");

/** Whether the title names the key as a whole token, so `#612` is not swallowed by `#6123`. */
function titleNamesKey(title: string, key: string): boolean {
return new RegExp(`${escapeRegExp(key)}(?!\\d)`).test(title);
}

/** One thread row: bb's glyph, title and context menu, expanding into its children. */
function SidebarThreadRow({
thread,
Expand All @@ -856,6 +869,7 @@ function SidebarThreadRow({
byId,
onNavigate,
meta,
titleAttr,
}: {
thread: PluginSidebarThread;
role: SidebarChildRole;
Expand All @@ -864,6 +878,8 @@ function SidebarThreadRow({
byId: ReadonlyMap<string, PluginSidebarThread>;
onNavigate: () => void;
meta?: ReactNode;
/** The full binding key, kept on the row's `title` attribute when the row is an effort. */
titleAttr?: string;
}) {
const navigate = useBbNavigate();
const rowStatus = useSidebarThreadRowStatus(thread.id);
Expand All @@ -876,17 +892,16 @@ function SidebarThreadRow({
return (
<li className="flex flex-col">
<ThreadActionsContextMenu thread={actionTarget(thread)}>
<div className="flex items-center gap-1 rounded-md py-0.5 pr-1 hover:bg-state-hover" style={{ paddingLeft: `${4 + depth * 14}px` }}>
<div className="flex items-center gap-1 rounded-md py-0.5 pr-1 hover:bg-state-hover" style={{ paddingLeft: `${4 + depth * 14}px` }} title={titleAttr}>
{count > 0 ? (
<button
type="button"
aria-label={`${open ? "Collapse" : "Expand"} ${thread.displayTitle}`}
aria-expanded={open}
className="flex shrink-0 items-center gap-0.5 text-muted-foreground"
className="flex shrink-0 items-center text-muted-foreground"
onClick={() => setOpen((v) => !v)}
>
<Icon name={open ? "ChevronDown" : "ChevronRight"} className="size-3.5" />
<span className="text-[10px] tabular-nums">{count}</span>
</button>
) : (
<span className="size-4 shrink-0" />
Expand All @@ -903,7 +918,11 @@ function SidebarThreadRow({
>
<ThreadTitle threadId={thread.id} />
</a>
{role === "worker" || role === "reviewer" ? <span className="shrink-0 text-[10px] uppercase text-muted-foreground">{role}</span> : null}
{role === "worker" || role === "reviewer" ? (
<span className="shrink-0 rounded bg-state-hover px-1 text-[9px] font-semibold uppercase leading-4 text-muted-foreground" title={role}>
{role === "worker" ? "W" : "R"}
</span>
) : null}
{meta}
</div>
</ThreadActionsContextMenu>
Expand All @@ -921,20 +940,25 @@ function SidebarThreadRow({
);
}

/** One effort's root row, with the binding's key, stage and held/blocked badges. */
/** One effort's root row, title-first: the shortened key only when the title omits it, and the held/blocked badges. */
function SidebarEffortRow({ effort, byId, onNavigate }: { effort: SidebarEffort; byId: ReadonlyMap<string, PluginSidebarThread>; onNavigate: () => void }) {
const root = byId.get(effort.rootThreadId);
if (root === undefined) return null;
const key = effort.bindingKey;
const displayKey = key === null ? null : shortBindingKey(key);
// The title wins: a steward is titled after its binding, so showing the key again is noise.
const keyInTitle = key !== null && displayKey !== null && (titleNamesKey(root.displayTitle, key) || titleNamesKey(root.displayTitle, displayKey));
const showKey = displayKey !== null && !keyInTitle;
const badges = effort.hold !== null || effort.blockedOn !== null;
const meta =
effort.bindingKey === null ? null : (
<span className="flex shrink-0 items-center gap-1 text-[11px] text-muted-foreground">
<span className="font-medium">{effort.bindingKey}</span>
{effort.stage !== null ? <span>{effort.stage}</span> : null}
!showKey && !badges ? null : (
<span className="flex min-w-0 shrink items-center gap-1 text-[11px] text-muted-foreground">
{showKey ? <span className="min-w-0 truncate font-medium">{displayKey}</span> : null}
{effort.hold !== null ? <Badge tone="warn">held</Badge> : null}
{effort.blockedOn !== null ? <Badge tone="bad">blocked</Badge> : null}
</span>
);
return <SidebarThreadRow thread={root} role="thread" children={effort.children} depth={0} byId={byId} onNavigate={onNavigate} meta={meta} />;
return <SidebarThreadRow thread={root} role="thread" children={effort.children} depth={0} byId={byId} onNavigate={onNavigate} meta={meta} titleAttr={key ?? undefined} />;
}

function SidebarSection({ title, count, children }: { title: string; count: number; children: ReactNode }) {
Expand Down Expand Up @@ -1138,6 +1162,15 @@ function StewardsSidebar({ activeProjectId, isCompactViewport, onNavigate }: Plu
</ul>
)}
</SidebarSection>
{active.threads.length > 0 ? (
<SidebarCollapsible title="Threads" count={active.threads.length}>
<ul className="flex flex-col">
{active.threads.map((e) => (
<SidebarEffortRow key={e.key} effort={e} byId={byId} onNavigate={onNavigate} />
))}
</ul>
</SidebarCollapsible>
) : null}
{active.watches.length > 0 ? (
<SidebarCollapsible title="Watches" count={active.watches.length}>
<ul className="flex flex-col">
Expand Down
96 changes: 88 additions & 8 deletions plugins/stewards/sidebar-app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,20 +97,99 @@ describe("the stewards sidebar list (BB-44)", () => {
expect(captured.threadLists[0]).toMatchObject({ id: "sidebar", title: "Stewards" });
});

it("shows a tab per live project and the active project's effort with its key, stage and badges", async () => {
it("shows a tab per live project and a title-first row with the shortened key and badges", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Fix login" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ hold: "billing freeze" })] }) } as never,
});
await waitFor(() => expect(slot.getByRole("tab", { name: "Acme" })).toBeTruthy());
expect(slot.getByRole("tab", { name: "Personal" })).toBeTruthy();
await waitFor(() => expect(slot.getByText("ENG-1")).toBeTruthy());
expect(slot.getByText("build")).toBeTruthy();
await waitFor(() => expect(slot.getByText("Fix login")).toBeTruthy());
// The title does not name the key, so the key shows; the stage does not.
expect(slot.getByText("ENG-1")).toBeTruthy();
expect(slot.queryByText("build")).toBeNull();
expect(slot.getByText("held")).toBeTruthy();
// The full key stays on the row's title attribute.
expect(slot.container.querySelector('[title="ENG-1"]')).not.toBeNull();
slot.lifecycle.unmount();
});

it("drops the key when the title already names it, and keeps no stage text", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Review acme/web#612: Read dashboard metrics" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ key: "acme/web#612", stage: "review" })] }) } as never,
});
await waitFor(() => expect(slot.getByText("Review acme/web#612: Read dashboard metrics")).toBeTruthy());
expect(slot.queryByText("#612", { exact: true })).toBeNull();
expect(slot.queryByText("review", { exact: true })).toBeNull();
expect(slot.container.querySelector('[title="acme/web#612"]')).not.toBeNull();
slot.lifecycle.unmount();
});

it("shortens a pull-request key to #N when the title omits it", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Fix login" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ key: "acme/web#612" })] }) } as never,
});
await waitFor(() => expect(slot.getByText("#612")).toBeTruthy());
expect(slot.queryByText("acme/web#612", { exact: true })).toBeNull();
expect(slot.container.querySelector('[title="acme/web#612"]')).not.toBeNull();
slot.lifecycle.unmount();
});

it("does not swallow a key into a longer number in the title", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Fix login #6123" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ key: "acme/web#612" })] }) } as never,
});
await waitFor(() => expect(slot.getByText("#612", { exact: true })).toBeTruthy());
slot.lifecycle.unmount();
});

it("renders held and blocked badges without a stage", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Fix login" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ hold: "waiting", blockedOn: "a review" })] }) } as never,
});
await waitFor(() => expect(slot.getByText("held")).toBeTruthy());
expect(slot.getByText("blocked")).toBeTruthy();
slot.lifecycle.unmount();
});

it("shows workers and reviewers only when the effort is expanded", async () => {
it("drops the child count beside the chevron but keeps the expand aria-label", async () => {
const slot = await renderSidebar({
sidebarThreads: {
projects,
threads: [thread({ id: "thr_steward", displayTitle: "Fix login" }), thread({ id: "thr_worker", displayTitle: "Implement retry" })],
},
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding({ workers: [{ threadId: "thr_worker", title: "Implement retry" }] })] }) } as never,
});
const expand = await waitFor(() => slot.getByRole("button", { name: "Expand Fix login" }));
expect(expand.textContent).toBe("");
fireEvent.click(expand);
await waitFor(() => expect(slot.getByText("Implement retry")).toBeTruthy());
expect(slot.getByRole("button", { name: "Collapse Fix login" })).toBeTruthy();
slot.lifecycle.unmount();
});

it("keeps one-off threads out of In flight, in a collapsed Threads section", async () => {
const slot = await renderSidebar({
sidebarThreads: { projects, threads: [thread({ id: "thr_steward", displayTitle: "Fix login" }), thread({ id: "thr_oneoff", displayTitle: "My notes" })] },
rpc: { stewardsSidebar: () => sidebarData({ bindings: [binding()] }) } as never,
});
await waitFor(() => expect(slot.getByText("Fix login")).toBeTruthy());
const inFlight = slot.getByRole("heading", { name: /In flight/u });
expect(inFlight.textContent).toContain("1");
const threads = slot.getByRole("button", { name: /Threads/u });
expect(threads.textContent).toContain("1");
// Collapsed by default: the one-off's title is not rendered until it is opened.
expect(slot.queryByText("My notes")).toBeNull();
fireEvent.click(threads);
await waitFor(() => expect(slot.getByText("My notes")).toBeTruthy());
slot.lifecycle.unmount();
});

it("shows workers and reviewers only when the effort is expanded, as muted glyph tags", async () => {
const slot = await renderSidebar({
sidebarThreads: {
projects,
Expand All @@ -123,14 +202,14 @@ describe("the stewards sidebar list (BB-44)", () => {
}),
} as never,
});
await waitFor(() => expect(slot.getByText("ENG-1")).toBeTruthy());
await waitFor(() => expect(slot.getByText("Fix login")).toBeTruthy());
expect(slot.queryByText("Implement retry")).toBeNull();
fireEvent.click(slot.getByRole("button", { name: /Expand Fix login/u }));
await waitFor(() => expect(slot.getByText("Implement retry")).toBeTruthy());
expect(slot.getByText("worker")).toBeTruthy();
expect(slot.getByTitle("worker").textContent).toBe("W");
fireEvent.click(slot.getByRole("button", { name: /Expand Implement retry/u }));
await waitFor(() => expect(slot.getByText("Review the PR")).toBeTruthy());
expect(slot.getByText("reviewer")).toBeTruthy();
expect(slot.getByTitle("reviewer").textContent).toBe("R");
slot.lifecycle.unmount();
});

Expand Down Expand Up @@ -192,7 +271,8 @@ describe("the stewards sidebar list (BB-44)", () => {
{ activeProjectId: "personal" },
);
await waitFor(() => expect(slot.getByRole("tab", { name: "Personal" }).getAttribute("aria-selected")).toBe("true"));
expect(slot.getByText("My notes")).toBeTruthy();
fireEvent.click(slot.getByRole("button", { name: /Threads/u }));
await waitFor(() => expect(slot.getByText("My notes")).toBeTruthy());
fireEvent.click(slot.getByRole("tab", { name: "Acme" }));
await waitFor(() => expect(slot.getByRole("tab", { name: "Acme" }).getAttribute("aria-selected")).toBe("true"));
slot.lifecycle.unmount();
Expand Down
30 changes: 24 additions & 6 deletions plugins/stewards/sidebar.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,26 @@ describe("stewards sidebar grouping", () => {
threads: [thread({ id: "thr_root" }), thread({ id: "thr_child", parentThreadId: "thr_root" }), thread({ id: "thr_fork", lifecycleOwnerThreadId: "thr_child" })],
data: [data({ projectId: "p1" })],
});
expect(tabs[0]!.efforts).toHaveLength(1);
expect(tabs[0]!.efforts[0]).toMatchObject({ rootThreadId: "thr_root", key: "thread:thr_root" });
expect(tabs[0]!.efforts[0]!.children).toMatchObject([{ threadId: "thr_child", role: "thread", children: [{ threadId: "thr_fork", role: "thread" }] }]);
expect(tabs[0]!.efforts).toHaveLength(0);
expect(tabs[0]!.threads).toHaveLength(1);
expect(tabs[0]!.threads[0]).toMatchObject({ rootThreadId: "thr_root", key: "thread:thr_root" });
expect(tabs[0]!.threads[0]!.children).toMatchObject([{ threadId: "thr_child", role: "thread", children: [{ threadId: "thr_fork", role: "thread" }] }]);
});

it("returns stewarded efforts, one-off threads and ops watches as separate lists", () => {
const tabs = buildSidebar({
projects: [project({ id: "p1" })],
threads: [thread({ id: "thr_steward" }), thread({ id: "thr_ops" }), thread({ id: "thr_oneoff" })],
data: [
data({
projectId: "p1",
bindings: [binding({ key: "ENG-1", threadId: "thr_steward" }), binding({ key: "acme/web", threadId: "thr_ops", kind: "ops", stage: null })],
}),
],
});
expect(tabs[0]!.efforts.map((e) => e.key)).toEqual(["ENG-1"]);
expect(tabs[0]!.threads.map((e) => e.key)).toEqual(["thread:thr_oneoff"]);
expect(tabs[0]!.watches.map((e) => e.key)).toEqual(["acme/web"]);
});

it("skips a binding whose steward thread is not in the live view", () => {
Expand All @@ -103,7 +120,8 @@ describe("stewards sidebar grouping", () => {
threads: [thread({ id: "thr_other" })],
data: [data({ projectId: "p1", bindings: [binding({ key: "ENG-1", threadId: "thr_archived" })] })],
});
expect(tabs[0]!.efforts.map((e) => e.key)).toEqual(["thread:thr_other"]);
expect(tabs[0]!.efforts).toHaveLength(0);
expect(tabs[0]!.threads.map((e) => e.key)).toEqual(["thread:thr_other"]);
});

it("gives every live project a tab, stewarded or not, including the personal project", () => {
Expand Down Expand Up @@ -148,12 +166,12 @@ describe("stewards sidebar ordering", () => {
expect(["idle", "finished", "failed"].some(isBusy)).toBe(false);
});

it("orders a tab's efforts and watches with the same comparator", () => {
it("orders a tab's threads and watches with the same comparator", () => {
const tabs = buildSidebar({
projects: [project({ id: "p1" })],
threads: [thread({ id: "thr_quiet", updatedAt: 5 }), thread({ id: "thr_busy", status: "active", updatedAt: 1 })],
data: [data({ projectId: "p1" })],
});
expect(tabs[0]!.efforts.map((e) => e.rootThreadId)).toEqual(["thr_busy", "thr_quiet"]);
expect(tabs[0]!.threads.map((e) => e.rootThreadId)).toEqual(["thr_busy", "thr_quiet"]);
});
});
7 changes: 5 additions & 2 deletions plugins/stewards/sidebar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,10 @@ export interface SidebarTab {
projectId: string;
name: string;
isPersonal: boolean;
/** In-flight efforts, ordered. `ops` bindings are in `watches`, not here. */
/** In-flight stewarded efforts, ordered. `ops` bindings are in `watches`, one-off threads in `threads`. */
efforts: SidebarEffort[];
/** One-off threads (no steward binding), ordered. */
threads: SidebarEffort[];
/** `ops`, Dependabot and Sentry bindings, grouped in a collapsed row. */
watches: SidebarEffort[];
projectStewardThreadId: string | null;
Expand Down Expand Up @@ -278,7 +280,8 @@ function buildTab(project: SidebarLiveProject, data: SidebarProjectData | undefi
projectId: project.id,
name: project.name,
isPersonal: project.isPersonal,
efforts: efforts.filter((e) => e.kind !== "ops").sort(compareEfforts),
efforts: efforts.filter((e) => e.bindingKey !== null && e.kind !== "ops").sort(compareEfforts),
threads: efforts.filter((e) => e.bindingKey === null).sort(compareEfforts),
watches: efforts.filter((e) => e.kind === "ops").sort(compareEfforts),
projectStewardThreadId: stewardThreadId,
ended: data?.ended ?? [],
Expand Down
Loading