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
12 changes: 9 additions & 3 deletions plugins/stewards/DESIGN.md
Original file line number Diff line number Diff line change
Expand Up @@ -1364,9 +1364,15 @@ 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
question, `stewardsNeedAction { action: "choose" }` for a `decide` item) and
refetches; a row without choices, or a `provide-secret` item, opens the
Stewards page at that project, where the free-text answer and the secret form
live. The block adds no write path of its own.
refetches. An `approve-pr` row carries the page's three actions — **Open the
pull request** (`navigate.openUrl` on the item's `url`), **Approve**
(`stewardsNeedAction { action: "approve" }`, no confirmation, the server's
refusal shown in the row) and **Details** (the board at that project) — and
its text wraps instead of truncating, so the repository, number and title are
readable before the click. Every other row's page button is **Details** too: a
row without choices, or a `provide-secret` item, opens the Stewards page at
that project, where the free-text answer and the secret form live. The block
adds no write path the page does not already make.

**One source of truth.** `server.ts`'s `needsYou(projectId, { actionableOnly
})` builds the board's `questions`, `withUser` and `needs` lists in one place;
Expand Down
12 changes: 9 additions & 3 deletions plugins/stewards/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -376,9 +376,15 @@ 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,
`stewardsNeedAction { action: "choose" }` for a `decide` item) and refetches;
a row without choices, or a `provide-secret` item, opens the Stewards page at
that project. The block and the board page read one server function
`stewardsNeedAction { action: "choose" }` for a `decide` item) and refetches.
An `approve-pr` row carries the page's three actions: **Open the pull
request** opens the item's `url`, **Approve** makes the page's one-click
approval (`stewardsNeedAction { action: "approve" }`, no confirmation, the
server's refusal shown in the row), and **Details** opens the Stewards page at
that project; its text wraps so the repository, number and title are readable.
Every other row's page button is **Details** too: a row without choices, or a
`provide-secret` item, opens the Stewards page at that project. The block and
the board page read one server function
(`needsYou`), so the sidebar and the page can never disagree; a
non-actionable need is on the page but not in the sidebar. The count and the
items come from `stewardsSidebar`; the plugin publishes
Expand Down
81 changes: 78 additions & 3 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -392,14 +392,89 @@ describe("the stewards sidebar's needs you block (BB-46)", () => {
slot.lifecycle.unmount();
});

it("opens the board for a row without choices", async () => {
it("opens the board for a row without choices, under a Details label", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "configure", choices: [] })] }) });
await waitFor(() => expect(slot.getByRole("button", { name: "Open" })).toBeTruthy());
fireEvent.click(slot.getByRole("button", { name: "Open" }));
await waitFor(() => expect(slot.getByRole("button", { name: "Details" })).toBeTruthy());
expect(slot.queryByRole("button", { name: "Open" })).toBeNull();
fireEvent.click(slot.getByRole("button", { name: "Details" }));
await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "toPluginPanel", path: "board", options: { subPath: "p1" } }));
slot.lifecycle.unmount();
});

it("offers Open the pull request, Approve and Details on an approve-pr row, with wrapped text", async () => {
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "approve-pr", url: "https://github.com/bitcomplete/bb-gate/pull/17", what: "Approve bitcomplete/bb-gate#17" })] }),
});
await waitFor(() => expect(slot.getByRole("button", { name: "Open the pull request" })).toBeTruthy());
expect(slot.getByRole("button", { name: "Approve" })).toBeTruthy();
expect(slot.getByRole("button", { name: "Details" })).toBeTruthy();
const text = slot.getByText("Approve bitcomplete/bb-gate#17");
expect(text.className).not.toContain("truncate");
expect(text.className).toContain("break-words");
slot.lifecycle.unmount();
});

it("opens the pull request's url from the row and makes no RPC", async () => {
const url = "https://github.com/bitcomplete/bb-gate/pull/17";
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "approve-pr", url })] }),
stewardsNeedAction: () => ({ ok: true, message: "done" }),
});
fireEvent.click(await waitFor(() => slot.getByRole("button", { name: "Open the pull request" })));
await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "openUrl", url }));
expect(slot.inspection.rpcCalls.some((c) => c.method === "stewardsNeedAction")).toBe(false);
slot.lifecycle.unmount();
});

it("sends the approve action with no note or choice, and refetches on success", async () => {
let calls = 0;
const slot = await renderSidebar({
stewardsSidebar: () => {
calls += 1;
return sidebarData({ count: 1, items: [needItem({ kind: "approve-pr", url: "https://github.com/bitcomplete/bb-gate/pull/17" })] });
},
stewardsNeedAction: () => ({ ok: true, message: "approved" }),
});
fireEvent.click(await waitFor(() => slot.getByRole("button", { name: "Approve" })));
await waitFor(() => expect(slot.inspection.rpcCalls).toContainEqual({ method: "stewardsNeedAction", input: { needId: "need_1", action: "approve", note: null, choice: null } }));
await waitFor(() => expect(calls).toBe(2));
slot.lifecycle.unmount();
});

it("shows the server's refusal in the row and re-enables the buttons", async () => {
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "approve-pr", url: "https://github.com/bitcomplete/bb-gate/pull/17" })] }),
stewardsNeedAction: () => ({ ok: false, message: "the owner must approve first" }),
});
fireEvent.click(await waitFor(() => slot.getByRole("button", { name: "Approve" })));
await waitFor(() => expect(slot.getByText("the owner must approve first")).toBeTruthy());
expect((slot.getByRole("button", { name: "Approve" }) as HTMLButtonElement).disabled).toBe(false);
slot.lifecycle.unmount();
});

it("opens the board at the project from Details on an approve-pr row", async () => {
const slot = await renderSidebar({
stewardsSidebar: () => sidebarData({ count: 1, items: [needItem({ kind: "approve-pr", url: "https://github.com/bitcomplete/bb-gate/pull/17" })] }),
});
fireEvent.click(await waitFor(() => slot.getByRole("button", { name: "Details" })));
await waitFor(() => expect(slot.inspection.navigateCalls).toContainEqual({ method: "toPluginPanel", path: "board", options: { subPath: "p1" } }));
slot.lifecycle.unmount();
});

it("labels the page button Details on every other row, with no Open label", async () => {
const items = [
needItem({ id: "need_merge", kind: "merge", url: "https://github.com/bitcomplete/bb-gate/pull/17" }),
needItem({ id: "need_secret", kind: "provide-secret", choices: [] }),
needItem({ id: "need_config", kind: "configure", choices: [] }),
needItem({ id: "need_decide", kind: "decide", choices: [] }),
questionItem({ id: "qst_1", choices: [] }),
];
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: items.length, items }) });
await waitFor(() => expect(slot.getAllByRole("button", { name: "Details" })).toHaveLength(5));
expect(slot.queryByRole("button", { name: "Open" })).toBeNull();
slot.lifecycle.unmount();
});

it("refetches on a realtime event for a shown project and ignores an unknown one", async () => {
let calls = 0;
const slot = await renderSidebar({
Expand Down
47 changes: 39 additions & 8 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1030,17 +1030,18 @@ function ProjectTabs({ tabs, counts, activeId, onPick, onNewThread }: { tabs: Ar
*/
function SidebarNeedRow({ item, onChanged, onOpenBoard }: { item: SidebarNeedItem; onChanged: () => void; onOpenBoard: () => void }) {
const rpc = useRpc<typeof rpcContract>();
const navigate = useBbNavigate();
const [state, setState] = useState<"idle" | "running" | { error: string }>("idle");
// Choices are a decide item's or a question's; every other item opens the page.
const choices = item.type === "question" ? item.choices : item.type === "need" && item.kind === "decide" ? item.choices : [];
const text = item.type === "need" ? item.what : item.question;
const entityUrl = item.type === "need" ? item.entityUrl : item.url;
const choose = (choice: string) => {
const prUrl = item.url;
// An approve-pr row offers the page's one-click approval and the pull
// request beside Details; every other row without choices opens the page.
const isApprovePr = item.type === "need" && item.kind === "approve-pr";
const run = (call: Promise<{ ok: boolean; message: string }>) => {
setState("running");
const call =
item.type === "question"
? rpc.call("stewardsAnswerQuestion", { questionId: item.id, answer: null, choice })
: rpc.call("stewardsNeedAction", { needId: item.id, action: "choose", note: null, choice });
call.then(
(r) => {
if (!r.ok) return setState({ error: r.message });
Expand All @@ -1049,16 +1050,46 @@ function SidebarNeedRow({ item, onChanged, onOpenBoard }: { item: SidebarNeedIte
(e: unknown) => setState({ error: message(e) }),
);
};
const choose = (choice: string) =>
run(
item.type === "question"
? rpc.call("stewardsAnswerQuestion", { questionId: item.id, answer: null, choice })
: rpc.call("stewardsNeedAction", { needId: item.id, action: "choose", note: null, choice }),
);
const approve = () => run(rpc.call("stewardsNeedAction", { needId: item.id, action: "approve", note: null, choice: null }));
return (
<li className="flex flex-col gap-1 px-2 py-1.5">
<p className="flex flex-wrap items-center gap-2">
{item.key !== null ? <EntityLink entityKey={item.key} url={entityUrl} /> : null}
{item.type === "withUser" ? <Badge tone="bad">{item.kind === "approval" ? "approval request" : `${item.kind} escalation`}</Badge> : null}
{item.type === "need" ? <Badge tone="bad">{item.kind}</Badge> : null}
</p>
<p className="min-w-0 truncate">{text}</p>
<p className={isApprovePr ? "min-w-0 break-words" : "min-w-0 truncate"}>{text}</p>
<div className="flex flex-wrap items-center gap-1">
{choices.length > 0 ? (
{isApprovePr ? (
<>
{prUrl !== null ? (
<button
type="button"
className="rounded-md border border-input px-2 py-0.5 text-[11px] hover:bg-state-hover"
onClick={() => navigate.openUrl(prUrl)}
>
Open the pull request
</button>
) : null}
<button
type="button"
disabled={state === "running"}
className="rounded-md border border-input px-2 py-0.5 text-[11px] hover:bg-state-hover disabled:opacity-50"
onClick={approve}
>
Approve
</button>
<button type="button" className="rounded-md border border-input px-2 py-0.5 text-[11px] hover:bg-state-hover" onClick={onOpenBoard}>
Details
</button>
</>
) : choices.length > 0 ? (
choices.map((choice) => (
<button
key={choice}
Expand All @@ -1072,7 +1103,7 @@ function SidebarNeedRow({ item, onChanged, onOpenBoard }: { item: SidebarNeedIte
))
) : (
<button type="button" className="rounded-md border border-input px-2 py-0.5 text-[11px] hover:bg-state-hover" onClick={onOpenBoard}>
Open
Details
</button>
)}
{typeof state === "object" ? <span className="text-destructive">{state.error}</span> : null}
Expand Down
Loading