Skip to content

Commit 52445b5

Browse files
matt2eclaude
andcommitted
fix(shell): keep Messages selected for pages in its sidebar
Opening Drafts & sent (or Usage, Link Lab, or any plugin page placed in the Messages sidebar) cleared the Messages highlight in the app dock and hid the Messages sidebar it was opened from. The dock and the sidebar each compared the raw selected page key: the dock highlighted only an exact dock-page match, and the shell showed the Messages sidebar only for the buzz.channels page. The dock move in #2626 dropped the old headerPageSelection mapping that handled this. Add navigationOwner in presentation.ts as the single mapping from a selected destination to the app whose navigation lists it: pages placed in the Messages sidebar belong to Messages, and every other destination owns itself. Conversations, DMs, threads and Solo chats already select the Messages page. AppShell uses the owner for the dock selection, its tab panel linkage and Messages sidebar visibility. Because Messages now stays the selected dock tab, activating it from one of its sidebar pages reselects it and returns to Messages. Cover the mapping for every bundled page and external placement, and the dock selection, sidebar visibility and return from each kind of Messages sidebar destination. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: mtoohey <[email protected]>
1 parent 7d06475 commit 52445b5

7 files changed

Lines changed: 180 additions & 16 deletions

File tree

‎docs/buzz-help.md‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,12 @@ revokes all of them, and a pairing unused for 30 days expires.
433433
Activity second, followed by the other apps. Community and profile controls
434434
sit at the bottom of the dock. Search stays wide in the top bar.
435435
Messages has All / Solo / Team sidebar filters; other apps use their main
436-
view unless they provide their own sidebar. The sidebar and message pane
437-
share one surface with a persistent divider; panel headers also have bottom
438-
hairlines. Dock icons stay still, highlight on hover, and show instant labels
439-
to their right. Bestie uses your configured avatar.
436+
view unless they provide their own sidebar. Pages listed in the Messages
437+
sidebar, such as Drafts & sent, keep Messages selected and its sidebar open.
438+
The sidebar and message pane share one surface with a persistent divider;
439+
panel headers also have bottom hairlines. Dock icons stay still, highlight
440+
on hover, and show instant labels to their right. Bestie uses your
441+
configured avatar.
440442
The **+** opens New from the sidebar. **Cmd/Ctrl+N** opens that menu where
441443
the current app has a creation sidebar.
442444
- **Link boundaries**: a bare http(s) or buzz link ends at whitespace and at

‎docs/shell-design.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ semantic tokens, UI authoring rules and the local component reference.
5656
channel sidebar's surface, resize owner, row treatment and section recipes.
5757
Bestie and Inbox lead the left app dock, followed by Messages and the other
5858
dock destinations. Sidebar-placed contributions remain in the conversation
59-
sidebar. Its plus opens New for chat, project, DM and channel creation;
59+
sidebar; `navigationOwner` keeps Messages selected, with its sidebar, while
60+
one is open. Its plus opens New for chat, project, DM and channel creation;
6061
Cmd/Ctrl+N opens that menu only where the current app has a creation sidebar. Every conversation, Solo or Team, opens in Messages; see
6162
[Solo](solo/README.md) for the Solo treatment, placement and the relay privacy
6263
boundary. Messages is the default destination.

‎src/app/shell/AppShell.test.tsx‎

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ it("hides and shows the channel sidebar without re-rendering its content", async
9191
title: "Inbox",
9292
component: () => null,
9393
primary: true,
94+
placement: "topbar",
9495
},
9596
];
9697
const onSelect = () => {};
@@ -170,10 +171,20 @@ it.each([true, false])(
170171
</ToastProvider>,
171172
);
172173
expect(screen.getByText("Main app content")).toBeVisible();
173-
expect(
174-
screen.queryByRole("complementary", { name: "Message sidebar" }),
175-
).toBeNull();
176-
expect(screen.queryByRole("button", { name: /sidebar/i })).toBeNull();
174+
// A primary page is listed in the Messages sidebar, so it keeps it.
175+
if (primary) {
176+
expect(
177+
screen.getByRole("complementary", { name: "Message sidebar" }),
178+
).toBeVisible();
179+
expect(
180+
screen.getByRole("button", { name: "Hide sidebar" }),
181+
).toBeVisible();
182+
} else {
183+
expect(
184+
screen.queryByRole("complementary", { name: "Message sidebar" }),
185+
).toBeNull();
186+
expect(screen.queryByRole("button", { name: /sidebar/i })).toBeNull();
187+
}
177188
},
178189
);
179190

@@ -477,6 +488,74 @@ it("shows global pages in the side dock and keeps the conversation mounted acros
477488
expect(unmounted).not.toHaveBeenCalled();
478489
});
479490

491+
it.each([
492+
// Channels, DMs, threads and Solo chats all open the Messages page.
493+
["a conversation", "buzz.channels/channels"],
494+
["Drafts & sent", "buzz.drafts-sent/drafts-sent"],
495+
["Usage", "buzz.usage/usage"],
496+
["a plugin's sidebar page", "example.notes/notes"],
497+
])(
498+
"keeps Messages selected in the dock with its sidebar on %s",
499+
async (_destination, selected) => {
500+
const current = createServices();
501+
services = current;
502+
const onSelect = vi.fn();
503+
const pages = [
504+
{ id: "channels", pluginId: "buzz.channels", title: "Channels" },
505+
{ id: "inbox", pluginId: "buzz.inbox", title: "Activity" },
506+
{ id: "drafts-sent", pluginId: "buzz.drafts-sent", title: "Drafts" },
507+
{ id: "usage", pluginId: "buzz.usage", title: "Usage" },
508+
{ id: "notes", pluginId: "example.notes", title: "Notes" },
509+
].map((page) => ({
510+
...page,
511+
key: `${page.pluginId}/${page.id}`,
512+
revision: "one",
513+
primary: true,
514+
component: () => null,
515+
}));
516+
render(
517+
<ToastProvider>
518+
<AppShell
519+
pages={pages}
520+
selected={selected}
521+
navigationAttempt=""
522+
onSelect={onSelect}
523+
tone="default"
524+
sidebar={(links) => <aside aria-label="Sidebar">{links}</aside>}
525+
communities={current.communities}
526+
accountActions={current.accountActions}
527+
appearance={testAppearance}
528+
>
529+
Page content
530+
</AppShell>
531+
</ToastProvider>,
532+
);
533+
const dock = screen.getByRole("navigation", { name: "Apps dock" });
534+
const messages = within(dock).getByRole("tab", { name: "Messages" });
535+
expect(messages).toHaveAttribute("aria-selected", "true");
536+
expect(within(dock).getByRole("tab", { name: "Activity" })).toHaveAttribute(
537+
"aria-selected",
538+
"false",
539+
);
540+
expect(
541+
screen.getByRole("tabpanel", { name: "Messages" }),
542+
).toHaveTextContent("Page content");
543+
expect(
544+
screen.getByRole("complementary", { name: "Sidebar" }),
545+
).toBeVisible();
546+
547+
// Messages returns from a page opened in its sidebar.
548+
await userEvent.click(messages);
549+
if (selected === "buzz.channels/channels")
550+
expect(onSelect).not.toHaveBeenCalled();
551+
else
552+
expect(onSelect).toHaveBeenCalledExactlyOnceWith(
553+
"buzz.channels/channels",
554+
{ focus: "preserve" },
555+
);
556+
},
557+
);
558+
480559
it.each(["sidebar", "topbar", "toolbar"] as const)(
481560
"keeps %s plugin icons, badge failures, selection and removal at the navigation boundary",
482561
async (placement) => {

‎src/app/shell/AppShell.tsx‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ActivityNavigationProvider } from "./ActivityNavigation";
22
import { PageNavigation } from "./PageNavigation";
3-
import { orderPages, pagePlacement } from "./presentation";
3+
import { navigationOwner, orderPages, pagePlacement } from "./presentation";
44
import {
55
useEffect,
66
useLayoutEffect,
@@ -176,7 +176,8 @@ function AppShellContent({
176176
const [creationOpen, setCreationOpen] = useState(false);
177177
const connection = useRelayConnection(communities.relay);
178178
const sidebarScope = connection.scope ?? "disconnected";
179-
const channelsNavigation = selected === "buzz.channels/channels";
179+
const owner = navigationOwner(pages, selected);
180+
const channelsNavigation = owner === "buzz.channels/channels";
180181
const hasNavigation =
181182
channelsNavigation ||
182183
pages.some((page) => page.key === selected && !!page.sidebar);
@@ -271,7 +272,7 @@ function AppShellContent({
271272
pages.filter((page) => page.primary && pagePlacement(page) !== "sidebar"),
272273
"dock",
273274
);
274-
const selectedDockPage = dockPages.some((page) => page.key === selected);
275+
const selectedDockPage = dockPages.some((page) => page.key === owner);
275276
return (
276277
<div
277278
data-shell-tone={tone}
@@ -354,7 +355,8 @@ function AppShellContent({
354355
<div className="shell-dock-pages">
355356
<PageNavigation
356357
pages={dockPages}
357-
selected={selected}
358+
selected={owner}
359+
currentPage={selected}
358360
onSelect={onSelect}
359361
placement="dock"
360362
previews
@@ -430,12 +432,12 @@ function AppShellContent({
430432
<Panel as="div" joined>
431433
<PanelFrame scope={connection.scope} companion={companion}>
432434
<div
433-
id={`shell-page-${selected}`}
435+
id={`shell-page-${owner}`}
434436
{...(selectedDockPage
435437
? {
436438
role: "tabpanel",
437439
"data-focus-inset": "",
438-
"aria-labelledby": `shell-page-${selected}-tab`,
440+
"aria-labelledby": `shell-page-${owner}-tab`,
439441
tabIndex: 0,
440442
}
441443
: {})}

‎src/app/shell/PageNavigation.tsx‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,15 @@ import {
3333
export function PageNavigation({
3434
pages,
3535
selected,
36+
currentPage = selected,
3637
onSelect,
3738
placement = "sidebar",
3839
previews = false,
3940
}: {
4041
pages: readonly RegisteredPage[];
4142
selected: string;
43+
/** The open destination when `selected` is the app that lists it. */
44+
currentPage?: string;
4245
onSelect(key: string, options?: Pick<NavigationOpenOptions, "focus">): void;
4346
/** The app dock is a vertical icon tablist; the sidebar lists rows. */
4447
placement?: "sidebar" | "dock";
@@ -57,6 +60,10 @@ export function PageNavigation({
5760
orientation="vertical"
5861
value={pages.some((page) => page.key === selected) ? selected : null}
5962
onValueChange={(key) => onSelect(key, { focus: "preserve" })}
63+
// The selected app returns from a page opened in its navigation.
64+
onReselect={(key) => {
65+
if (key !== currentPage) onSelect(key, { focus: "preserve" });
66+
}}
6067
items={pages.map((page) => {
6168
const Badge = page.badge;
6269
const Preview = page.preview;

‎src/app/shell/presentation.test.ts‎

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ import {
66
ChatsCircleIcon,
77
RobotIcon,
88
} from "../../shared/design-system/icons/index";
9-
import { pagePlacement, orderPages, pagePresentation } from "./presentation";
9+
import {
10+
navigationOwner,
11+
pagePlacement,
12+
orderPages,
13+
pagePresentation,
14+
} from "./presentation";
1015

1116
function page(key: string, title: string, icon?: string): RegisteredPage {
1217
const separator = key.indexOf("/");
@@ -135,3 +140,57 @@ test.each([undefined, "toolbar"] as const)(
135140
).toBe("topbar");
136141
},
137142
);
143+
144+
describe("navigation owner", () => {
145+
// Mirrors the bundled registrations' navigation fields.
146+
const primary = (
147+
key: string,
148+
fields: Partial<RegisteredPage> = {},
149+
): RegisteredPage => ({ ...page(key, key), primary: true, ...fields });
150+
const entries = [
151+
primary(messages.key, { placement: "topbar" }),
152+
primary(inbox.key),
153+
primary(bestie.key),
154+
primary("buzz.reminders/reminders"),
155+
primary("buzz.agents/agents"),
156+
primary("buzz.workflows/workflows"),
157+
primary("buzz.relay-notes/notes", { placement: "topbar" }),
158+
primary("buzz.drafts-sent/drafts-sent"),
159+
primary("buzz.usage/usage"),
160+
primary("buzz.link-lab/link-lab"),
161+
primary("buzz.repos/repos", { primary: false }),
162+
primary("example.sidebar/main"),
163+
primary("example.listed/main", { placement: "sidebar" }),
164+
primary("example.own-sidebar/main", { sidebar: () => null }),
165+
primary("example.header/main", { placement: "topbar" }),
166+
primary("example.tools/main", { placement: "toolbar" }),
167+
primary("example.linked/main", { primary: false, placement: "sidebar" }),
168+
];
169+
test.each([
170+
// Channels, DMs, threads and Solo chats all open the Messages page.
171+
[messages.key, messages.key],
172+
// Every page listed in the Messages sidebar keeps Messages selected.
173+
["buzz.drafts-sent/drafts-sent", messages.key],
174+
["buzz.usage/usage", messages.key],
175+
["buzz.link-lab/link-lab", messages.key],
176+
["example.sidebar/main", messages.key],
177+
["example.listed/main", messages.key],
178+
["example.own-sidebar/main", messages.key],
179+
// Dock apps own themselves.
180+
[inbox.key, inbox.key],
181+
[bestie.key, bestie.key],
182+
["buzz.reminders/reminders", "buzz.reminders/reminders"],
183+
["buzz.agents/agents", "buzz.agents/agents"],
184+
["buzz.workflows/workflows", "buzz.workflows/workflows"],
185+
["buzz.relay-notes/notes", "buzz.relay-notes/notes"],
186+
["example.header/main", "example.header/main"],
187+
["example.tools/main", "example.tools/main"],
188+
// Destinations without a navigation entry select nothing in the dock.
189+
["buzz.repos/repos", "buzz.repos/repos"],
190+
["example.linked/main", "example.linked/main"],
191+
["settings", "settings"],
192+
["missing/page", "missing/page"],
193+
])("%s belongs to %s", (selected, owner) => {
194+
expect(navigationOwner(entries, selected)).toBe(owner);
195+
});
196+
});

‎src/app/shell/presentation.ts‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ export function pagePlacement(page: RegisteredPage) {
7979
}
8080
}
8181

82+
/** The app whose navigation lists a destination: the dock selects it and the
83+
* shell shows its sidebar. Pages listed in the Messages sidebar belong to
84+
* Messages; conversations already select the Messages page. Every other
85+
* destination, including Settings and unlisted pages, owns itself. */
86+
export function navigationOwner(
87+
pages: readonly RegisteredPage[],
88+
selected: string,
89+
) {
90+
const page = pages.find((page) => page.key === selected);
91+
return page && pagePlacement(page) === "sidebar"
92+
? "buzz.channels/channels"
93+
: selected;
94+
}
95+
8296
type PagePresentation = Readonly<{
8397
label: string;
8498
icon: typeof BrowserIcon;

0 commit comments

Comments
 (0)