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
27 changes: 19 additions & 8 deletions plugins/stewards/app.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ describe("the sidebar-footer toggle (BB-45)", () => {
});
});

// BB-46: the sidebar's count badge and "Needs you" block, fed by the
// BB-46: the sidebar's "Needs you" block, fed by the
// `stewardsSidebar` call and refreshed over the realtime channel.
const sidebarProjects = [
{ id: "p1", name: "Acme", isPersonal: false, href: "/projects/p1", settingsHref: "/projects/p1/settings" },
Expand Down Expand Up @@ -340,22 +340,33 @@ describe("the stewards sidebar's needs you block (BB-46)", () => {
} as never);
};

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: [] }) });
it("does not render a summed count badge beside the picker", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem()] }) });
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();
await waitFor(() => expect(slot.getByRole("option", { name: "Acme (2)" })).toBeTruthy());
expect(slot.queryByLabelText("2 waiting on you")).toBeNull();
expect(slot.getByRole("option", { name: "Beta" })).toBeTruthy();
slot.lifecycle.unmount();
});

it.each([false, true])("sums the count beside the picker and shows per-project counts in its options (compact=%s)", async (isCompactViewport) => {
it.each([false, true])("shows per-project counts in its options and no summed badge (compact=%s)", async (isCompactViewport) => {
const slot = await renderSidebar(
{ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem(), needItem()] }, { count: 1, items: [needItem({ id: "need_2" })] }) },
{ isCompactViewport },
);
await waitFor(() => expect(slot.getByLabelText("3 waiting on you")).toBeTruthy());
expect(slot.getByRole("option", { name: "Acme (2)" })).toBeTruthy();
await waitFor(() => expect(slot.getByRole("option", { name: "Acme (2)" })).toBeTruthy());
expect(slot.getByRole("option", { name: "Beta (1)" })).toBeTruthy();
expect(slot.queryByLabelText("3 waiting on you")).toBeNull();
slot.lifecycle.unmount();
});

it("sizes the picker and the New thread button as h-8 controls", async () => {
const slot = await renderSidebar({ stewardsSidebar: () => sidebarData({ count: 2, items: [questionItem()] }) });
const select = await waitFor(() => slot.getByLabelText("Project"));
expect(select.className).toContain("h-8");
const button = slot.getByRole("button", { name: "New thread" });
expect(button.className).toContain("size-8");
expect(button.className).toContain("shrink-0");
slot.lifecycle.unmount();
});

Expand Down
25 changes: 7 additions & 18 deletions plugins/stewards/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,6 @@ function Badge({ children, tone = "muted" }: { children: ReactNode; tone?: "mute
return <span className={`inline-flex items-center rounded-full border px-2 py-0.5 text-[11px] ${colors}`}>{children}</span>;
}

/** The count of everything waiting on the user for one project; rendered only when non-zero. */
function NeedsBadge({ count }: { count: number }) {
return (
<span aria-label={`${count} waiting on you`} className="ml-1 inline-flex min-w-4 items-center justify-center rounded-full bg-destructive/10 px-1 text-[10px] font-medium leading-4 text-destructive">
{count}
</span>
);
}

function EntityLink({ entityKey, url }: { entityKey: string; url: string | null }) {
const navigate = useBbNavigate();
if (url === null) return <span className="font-medium">{entityKey}</span>;
Expand Down Expand Up @@ -993,18 +984,17 @@ function SidebarCollapsible({ title, count, children }: { title: string; count:
}

/**
* 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.
* The project dropdown, always a native `<select>`, with the per-project needs
* count in each option. 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);
return (
<div className="flex items-center gap-1 px-1 py-1">
<div className="flex items-center gap-1 px-2 py-1.5">
<select
aria-label="Project"
className="min-w-0 flex-1 rounded-md border border-input bg-transparent px-2 py-1 text-sm"
className="h-8 min-w-0 flex-1 rounded-md border border-input bg-transparent px-3 text-sm"
value={activeId ?? ""}
onChange={(e) => onPick(e.target.value)}
>
Expand All @@ -1017,13 +1007,12 @@ function ProjectTabs({ tabs, counts, activeId, onPick, onNewThread }: { tabs: Ar
);
})}
</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"
className="flex size-8 shrink-0 items-center justify-center rounded-md border border-input text-muted-foreground hover:bg-state-hover hover:text-foreground"
onClick={onNewThread}
>
<Icon name="Plus" className="size-4" />
Expand Down
Loading