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
10 changes: 5 additions & 5 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1271,8 +1271,8 @@ A **lesson** makes the answer a record and, for most of them, lands it.
## 21. The sidebar thread list

An opt-in replacement for bb's own sidebar list, registered through the
exclusive `experimental_threadList` slot (`plugins/stewards/app.tsx`). One tab
per project in the live view; in-flight efforts grouped by the steward
exclusive `experimental_threadList` slot (`plugins/stewards/app.tsx`). One
project dropdown in the live view; in-flight efforts grouped by the steward
relationship; a collapsed Watches row for `ops`, Dependabot and Sentry
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
Expand Down Expand Up @@ -1303,9 +1303,9 @@ component joins them to `experimental_useSidebarThreads` and polls

**The Needs you block and the count badge (BB-46).** The sidebar is where the
user already looks, so what waits on them is shown there, not only on the
Stewards page. Each tab carries a count pill when its project has anything
waiting; the compact picker shows the summed count and per-project counts in
its options. Above In flight, a **Needs you** block lists one row per item
Stewards page. The project dropdown carries each project's count in its option
label and the summed count in a pill beside it. Above In flight, a **Needs you**
block lists one row per item
with the entity key (opening the entity), one line of text, and a question's
or `decide` item's fixed `choices` as small buttons. A choice makes exactly
the write the page makes (`stewardsAnswerQuestion` with `answer: null` for a
Expand Down
9 changes: 4 additions & 5 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ bb. [DESIGN.md](DESIGN.md) is the design; this is how it is built and run.
## The sidebar thread list and its toggle

BB-44 registers a replacement for bb's own sidebar thread list through the
exclusive `experimental_threadList` slot: one tab per stewarded project,
exclusive `experimental_threadList` slot: one project dropdown,
in-flight efforts grouped by the steward relationship, and collapsed Watches
and Recently ended rows. BB-45 makes it switchable from where you are.

Expand Down Expand Up @@ -346,10 +346,9 @@ is left alone. The write is best-effort: a failure is logged and the sidebar
keeps working. (`bb.onInstall` is not usable here; it does not run for
plugins baked into the `bb-server` image.)

**The Needs you block and the tab badge (BB-46).** Each tab shows a small
count pill when the project has anything waiting on you, and the compact
viewport's picker shows the summed count beside it and per-project counts in
its options. Above **In flight**, a **Needs you** block lists one row per
**The Needs you block and the picker badge (BB-46).** The project dropdown
shows each project's count in its option label and the summed count in a small
pill beside it. Above **In flight**, a **Needs you** block lists one row per
item: the entity key opens the entity, one line of what, and a question's or
`decide` item's fixed `choices` as small buttons. A choice makes the same
write the page does (`stewardsAnswerQuestion` for a question,
Expand Down
7 changes: 4 additions & 3 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -340,17 +340,18 @@ describe("the stewards sidebar's needs you block (BB-46)", () => {
} as never);
};

it("shows a count badge on a tab only when the count is non-zero", async () => {
it("shows the summed count badge beside the picker only when non-zero", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem()] }, { count: 0, items: [] }) });
await waitFor(() => expect(slot.getByLabelText("Project")).toBeTruthy());
await waitFor(() => expect(slot.getByLabelText("2 waiting on you")).toBeTruthy());
expect(slot.queryByLabelText("0 waiting on you")).toBeNull();
slot.lifecycle.unmount();
});

it("sums the count on the compact picker and shows per-project counts in its options", async () => {
it.each([false, true])("sums the count beside the picker and shows per-project counts in its options (compact=%s)", async (isCompactViewport) => {
const slot = await renderSidebar(
{ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem(), needItem()] }, { count: 1, items: [needItem({ id: "need_2" })] }) },
{ isCompactViewport: true },
{ isCompactViewport },
);
await waitFor(() => expect(slot.getByLabelText("3 waiting on you")).toBeTruthy());
expect(slot.getByRole("option", { name: "Acme (2)" })).toBeTruthy();
Expand Down
91 changes: 45 additions & 46 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -820,14 +820,11 @@ function InFlightRow({ steward: s, now }: { steward: Board["stewards"][number];
// ---- The sidebar thread list -------------------------------------------------------------------
//
// The opt-in replacement for bb's sidebar list, registered through the
// exclusive `experimental_threadList` slot. One tab per project, in-flight
// exclusive `experimental_threadList` slot. One project dropdown, in-flight
// efforts grouped by the steward relationship, collapsed Watches and Recently
// ended rows, and a demoted project-steward row. Every row carries bb's own
// thread actions context menu, so nothing bb's rows can do is lost.

/** Past this many projects the tabs become a picker, as on a compact viewport. */
const SIDEBAR_TAB_LIMIT = 5;

/** The live fields bb's thread actions read, from a sidebar row. */
function actionTarget(t: PluginSidebarThread): PluginThreadActionTarget {
return {
Expand Down Expand Up @@ -990,48 +987,43 @@ function SidebarCollapsible({ title, count, children }: { title: string; count:
);
}

function ProjectTabs({ tabs, counts, activeId, compact, onPick }: { tabs: Array<{ projectId: string; name: string }>; counts: ReadonlyMap<string, number>; activeId: string | null; compact: boolean; onPick: (projectId: string) => void }) {
/**
* The project dropdown, always a native `<select>`: the per-project needs count
* in each option and the summed `NeedsBadge` beside it. The plus button opens
* the composer on the dropdown's project — the host's own New thread button
* cannot be retargeted from a thread list — then closes the mobile drawer.
*/
function ProjectTabs({ tabs, counts, activeId, onPick, onNewThread }: { tabs: Array<{ projectId: string; name: string }>; counts: ReadonlyMap<string, number>; activeId: string | null; onPick: (projectId: string) => void; onNewThread: () => void }) {
const total = [...counts.values()].reduce((sum, n) => sum + n, 0);
if (compact || tabs.length > SIDEBAR_TAB_LIMIT) {
return (
<div className="flex items-center gap-1 px-1 py-1">
<select
aria-label="Project"
className="min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 py-1 text-sm"
value={activeId ?? ""}
onChange={(e) => onPick(e.target.value)}
>
{tabs.map((t) => {
const count = counts.get(t.projectId) ?? 0;
return (
<option key={t.projectId} value={t.projectId}>
{count > 0 ? `${t.name} (${count})` : t.name}
</option>
);
})}
</select>
{total > 0 ? <NeedsBadge count={total} /> : null}
</div>
);
}
return (
<div role="tablist" className="flex flex-wrap gap-1 border-b border-border px-1 py-1">
{tabs.map((t) => {
const count = counts.get(t.projectId) ?? 0;
return (
<button
key={t.projectId}
type="button"
role="tab"
aria-selected={t.projectId === activeId}
className={`rounded-md px-2 py-0.5 text-xs ${t.projectId === activeId ? "bg-state-hover font-medium" : "text-muted-foreground hover:text-foreground"}`}
onClick={() => onPick(t.projectId)}
>
{t.name}
{count > 0 ? <NeedsBadge count={count} /> : null}
</button>
);
})}
<div className="flex items-center gap-1 px-1 py-1">
<select
aria-label="Project"
className="min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 py-1 text-sm"
value={activeId ?? ""}
onChange={(e) => onPick(e.target.value)}
>
{tabs.map((t) => {
const count = counts.get(t.projectId) ?? 0;
return (
<option key={t.projectId} value={t.projectId}>
{count > 0 ? `${t.name} (${count})` : t.name}
</option>
);
})}
</select>
{total > 0 ? <NeedsBadge count={total} /> : null}
{tabs.length > 0 ? (
<button
type="button"
aria-label="New thread"
title="New thread"
className="shrink-0 rounded-md border border-input p-1 text-muted-foreground hover:bg-state-hover hover:text-foreground"
onClick={onNewThread}
>
<Icon name="Plus" className="size-4" />
</button>
) : null}
</div>
);
}
Expand Down Expand Up @@ -1113,8 +1105,9 @@ function SidebarNeedsSection({ projectId, needs, onChanged }: { projectId: strin
);
}

function StewardsSidebar({ activeProjectId, isCompactViewport, onNavigate }: PluginThreadListProps) {
function StewardsSidebar({ activeProjectId, onNavigate }: PluginThreadListProps) {
const rpc = useRpc<typeof rpcContract>();
const navigate = useBbNavigate();
const { status, threads, projects } = experimental_useSidebarThreads();
const { data, error, refetch } = usePolled(useCallback(() => rpc.call("stewardsSidebar", null), [rpc]));
const tabs = useMemo(() => buildSidebar({ projects, threads, data: data?.projects ?? [] }), [projects, threads, data]);
Expand All @@ -1141,9 +1134,15 @@ function StewardsSidebar({ activeProjectId, isCompactViewport, onNavigate }: Plu
const active = tabs.find((t) => t.projectId === wanted) ?? tabs[0] ?? null;
const activeNeeds = active === null ? undefined : needsByProject.get(active.projectId);
const now = Date.now();
// The picker only changes local state; the plus button is what retargets the
// composer to it, then closes the drawer.
const openNewThread = () => {
if (active !== null) navigate.toCompose({ projectId: active.projectId });
onNavigate();
};
return (
<div className="flex h-full flex-col text-sm">
<ProjectTabs tabs={tabs} counts={counts} activeId={active?.projectId ?? null} compact={isCompactViewport} onPick={setPicked} />
<ProjectTabs tabs={tabs} counts={counts} activeId={active?.projectId ?? null} onPick={setPicked} onNewThread={openNewThread} />
{status === "loading" && data === null ? (
<p className="p-3 text-muted-foreground">Loading…</p>
) : active === null ? (
Expand Down
60 changes: 44 additions & 16 deletions plugins/stewards/sidebar-app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ describe("the stewards sidebar list (BB-44)", () => {
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.getByRole("option", { name: "Acme" })).toBeTruthy());
expect(slot.getByRole("option", { name: "Personal" })).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();
Expand Down Expand Up @@ -249,32 +249,60 @@ describe("the stewards sidebar list (BB-44)", () => {
slot.lifecycle.unmount();
});

it("renders a project picker on a compact viewport", async () => {
it("renders the project picker at every viewport width", async () => {
for (const isCompactViewport of [false, true]) {
const slot = await renderSidebar(
{
sidebarThreads: { projects, threads: [] },
rpc: { stewardsSidebar: () => sidebarData() } as never,
},
{ isCompactViewport },
);
await waitFor(() => expect(slot.getByLabelText("Project")).toBeTruthy());
expect(slot.queryByRole("tab")).toBeNull();
expect(slot.getByRole("option", { name: "Acme" })).toBeTruthy();
slot.lifecycle.unmount();
}
});

it("follows activeProjectId in the picker and switches on pick without navigating", async () => {
const slot = await renderSidebar(
{
sidebarThreads: { projects, threads: [] },
sidebarThreads: { projects, threads: [thread({ id: "thr_personal", projectId: "personal", displayTitle: "My notes" })] },
rpc: { stewardsSidebar: () => sidebarData() } as never,
},
{ isCompactViewport: true },
{ activeProjectId: "personal" },
);
await waitFor(() => expect(slot.getByLabelText("Project")).toBeTruthy());
expect(slot.queryByRole("tab")).toBeNull();
const select = await waitFor(() => slot.getByLabelText("Project") as HTMLSelectElement);
expect(select.value).toBe("personal");
fireEvent.click(slot.getByRole("button", { name: /Threads/u }));
await waitFor(() => expect(slot.getByText("My notes")).toBeTruthy());
fireEvent.change(select, { target: { value: "p1" } });
await waitFor(() => expect(select.value).toBe("p1"));
expect(slot.inspection.navigateCalls).not.toContainEqual(expect.objectContaining({ method: "toProject" }));
slot.lifecycle.unmount();
});

it("follows activeProjectId for the active tab and switches on pick", async () => {
const slot = await renderSidebar(
it("opens the composer on the picked project, then closes the drawer", async () => {
let slot!: RenderedSlot;
let composeSeenAtNavigate = false;
const onNavigate = vi.fn(() => {
composeSeenAtNavigate = slot.inspection.navigateCalls.some((c) => c.method === "toCompose");
});
slot = await renderSidebar(
{
sidebarThreads: { projects, threads: [thread({ id: "thr_personal", projectId: "personal", displayTitle: "My notes" })] },
sidebarThreads: { projects, threads: [] },
rpc: { stewardsSidebar: () => sidebarData() } as never,
},
{ activeProjectId: "personal" },
{ onNavigate },
);
await waitFor(() => expect(slot.getByRole("tab", { name: "Personal" }).getAttribute("aria-selected")).toBe("true"));
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"));
const select = await waitFor(() => slot.getByLabelText("Project") as HTMLSelectElement);
fireEvent.change(select, { target: { value: "personal" } });
await waitFor(() => expect(select.value).toBe("personal"));
fireEvent.click(slot.getByRole("button", { name: "New thread" }));
await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "toCompose", options: { projectId: "personal" } }));
expect(onNavigate).toHaveBeenCalledTimes(1);
expect(composeSeenAtNavigate).toBe(true);
slot.lifecycle.unmount();
});

Expand Down
Loading