Skip to content

Commit 539bb13

Browse files
tellahoCarl
andauthored
feat(channels): unify header actions and inline details editing (#487)
Signed-off-by: Taylor Ho <[email protected]> Co-authored-by: Carl <acda9e433d19dcd0e6b6840f7f4b98f3a56f1fab98049d444c087019e6d36560@buzz.block.builderlab.xyz>
1 parent c9946be commit 539bb13

56 files changed

Lines changed: 2935 additions & 811 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎docs/channels.md‎

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,29 @@ Focused coverage lives in `NewMessage.test.tsx`, `direct-messages.test.ts`,
294294
The browser journey uses the production app and broker with ephemeral identities
295295
and modeled upstream I/O; it does not send messages to a live community.
296296

297+
## Channel header actions
298+
299+
The conversation header’s **Channel actions** ellipsis opens the shared, default-size
300+
(non-compact) menu. **View channel details** is first and opens or focuses the existing
301+
Channel Settings tab; selecting it again never closes the pane. Editing is available
302+
from that pane, not directly from the menu. **View canvas**, optional **Save as template…** and
303+
**New session**, **Move channel**, **Mute/Unmute**, and **Mark as Read/Unread**
304+
reuse the sidebar’s action composition and persistent mutation/recovery owners.
305+
Move replaces the redundant Personal group shortcut. Permission-gated lifecycle
306+
actions follow in **Leave → Archive → Delete** order, with Delete in the shared
307+
danger tone. DMs retain Hide conversation and the separate Remove from Messages
308+
action; their permissions are not inferred from stream channels. Members retains its adjacent button and Diagnostics remains inside Settings.
309+
Session headings are unchanged. Header moves and dialog cancellation return focus
310+
to the ellipsis, while session creation hands focus to its composer. Read-only, cached, archived and DM eligibility stays
311+
with the existing capabilities. Opening the menu reads permissions, never publishes
312+
a lifecycle command. Menu Escape/outside dismissal returns to the header; Canvas, template
313+
and lifecycle confirmation cancellation also return there. Dialog owners outlive menu dismissal,
314+
while channel/session navigation retires header-origin dialogs. Canvas is bound to
315+
its opening channel and visit, so navigation never mounts another channel’s editor.
316+
The sidebar’s own dialogs and session-owned writes/recovery keep their existing
317+
lifetime; retiring a header does not undo a command already sent. The redundant Canvas card and saved-content
318+
preview are omitted from Channel Settings; opening details does not read Canvas.
319+
297320
## Channel lifecycle
298321

299322
Lifecycle actions extend the persistent sidebar’s existing context popup after
@@ -451,22 +474,38 @@ No dismissal saves, retries, replaces setup or confirms a destructive action.
451474

452475
Channel Settings shows the signed name, description and explicit visibility for
453476
ordinary channels; missing visibility stays **Not available**, not implicitly
454-
Public. **Edit details** opens the shared Dialog with one Name/Description/Duration/Private
455-
draft. Duration uses Create's Ongoing/Temporary cards, and Private uses the same
477+
Public. The centered title opens the same editor, revealing a pencil with a short
478+
left-to-right fade on hover or keyboard focus (always visible on touch, no animation
479+
for reduced motion). The pencil follows the final text line;
480+
balanced side padding keeps the text centered and lets long titles wrap without clipping it.
481+
Description and Visibility have small pencils immediately after their labels,
482+
revealed with a short left-to-right fade on whole-row hover or keyboard focus
483+
(always visible on touch, no animation for reduced motion) without shifting layout;
484+
each whole row opens the shared Dialog with one Name/Description/Duration/Private draft.
485+
Opening Description focuses its textarea; the title and Visibility still focus Name.
486+
Only authorized editors get the interactive rows; other viewers retain plain metadata.
487+
Members has a right chevron and opens the existing member list. Channel ID has a
488+
small inline copy icon with the same hover/focus/touch behavior; selecting its row
489+
copies the exact ID. Only a successful copy opens a confirmation tooltip, without
490+
growing the row; hovering or focusing does not open a hint or replay old feedback.
491+
Clipboard failure shows an inline error and leaves the row available to retry. The redundant standalone
492+
Edit details button, header-menu Edit details entry and informational Channel type
493+
row are omitted.
494+
Duration uses Create's Ongoing/Temporary cards, and Private uses the same
456495
switch in the action row. These controls stage changes; neither publishes immediately.
457496
**Save changes** submits the draft together and is enabled only for valid, changed values.
458497
**Cancel** explicitly discards edits and closes without confirmation. Close, Escape
459498
and backdrop clicks close untouched forms immediately; changed drafts first show
460499
**Discard changes?** with **Keep editing** initially focused. Keep editing, Escape,
461500
Close or a backdrop click in that confirmation returns to the intact form.
462-
**Discard changes** drops the draft and returns focus to Edit details without
501+
**Discard changes** drops the draft and returns focus to its originating control without
463502
closing Settings, as does the form’s explicit **Cancel**. Pending saves and status
464503
checks block dialog dismissal and show a
465-
loading spinner on the disabled **Edit details** button without changing its label.
504+
loading spinner on the disabled edit control without changing its label.
466505
Saving and permission loading do not add text status rows or reserve empty space;
467-
viewers without editing authority see neither Edit details nor an explanatory hint.
506+
viewers without editing authority see neither edit controls nor an explanatory hint.
468507
Actionable errors and uncertain-save warnings remain visible.
469-
After an uncertain outcome, **Edit details** re-enables so the save may be closed
508+
After an uncertain outcome, the edit controls re-enable so the save may be closed
470509
and reopened for check-only recovery, never a blind resend. The panel retains its
471510
own Close/Escape focus return, conversation and collapsed Diagnostics.
472511
Names accept 1–120 code points and descriptions up to 1,000. Typing and paste

‎docs/plugin-architecture.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ quotes and fenced examples are not tasks in this view. Doing and checkbox edits
246246
change one source byte; additions insert below the heading without rewriting other
247247
content.
248248
Duplicate Todos sections block editing until corrected in Canvas. Disabling removes
249-
the convenience UI, not the saved list: Channel settings → Canvas remains editable.
249+
the convenience UI, not the saved list: Channel actions → View canvas remains editable.
250250

251251
An optional terminal suffix records assignment as ordinary Markdown:
252252
` · Assignee: [Display name](nostr:npub…)`, using a full valid npub, not the abbreviated

‎src/bundled/channel-templates/ChannelTemplatesDialog.tsx‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
type Template,
1717
} from "../../features/channel-templates/model";
1818
import { Button } from "../../shared/design-system/ui/Button";
19-
import { Dialog } from "../../shared/design-system/ui/Dialog";
19+
import { Dialog, type DialogProps } from "../../shared/design-system/ui/Dialog";
2020
import { Field } from "../../shared/design-system/ui/Field";
2121
import { Input } from "../../shared/design-system/ui/Input";
2222
import { AgentSelection, TemplateFields } from "./TemplateFields";
@@ -31,8 +31,10 @@ export function ChannelTemplatesDialog({
3131
initial,
3232
notice,
3333
active,
34+
finalFocus,
3435
}: {
3536
session?: RelaySession | undefined;
37+
finalFocus?: DialogProps["finalFocus"];
3638
active(): boolean;
3739
open: boolean;
3840
onOpenChange(open: boolean): void;
@@ -95,6 +97,7 @@ export function ChannelTemplatesDialog({
9597
<Dialog
9698
dismissOnOutsideClick
9799
open={open}
100+
finalFocus={finalFocus}
98101
onOpenChange={onOpenChange}
99102
preventClose={busy}
100103
title={

‎src/bundled/channel-templates/TemplateSettings.tsx‎

Lines changed: 52 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { RelaySession } from "../../features/relay/session";
44
import { useRelayConnection } from "../../features/relay/react";
55
import type { SaveTemplateProps } from "../../features/channel-templates/provider";
66
import type { Template } from "../../features/channel-templates/model";
7+
import { MenuItem, MenuNote } from "../../shared/design-system/ui/Menu";
78
import { Button } from "../../shared/design-system/ui/Button";
89
import { ChannelTemplatesDialog } from "./ChannelTemplatesDialog";
910
import { useTemplateCatalog } from "./useTemplateCatalog";
@@ -85,49 +86,64 @@ export function SaveAsTemplate({
8586
session,
8687
channel,
8788
active,
89+
menu,
8890
}: SaveTemplateProps) {
8991
const catalog = useTemplateCatalog(session);
9092
const [draft, setDraft] = useState<Template>();
9193
const [copyWarning, setCopyWarning] = useState<string>();
9294
const [error, setError] = useState("");
9395
const [busy, setBusy] = useState(false);
96+
const copy = async () => {
97+
if (!active()) return;
98+
setBusy(true);
99+
setError("");
100+
try {
101+
const canvas = await session.canvas.read(channel.id);
102+
if (!active()) return;
103+
setCopyWarning(
104+
catalog.agentsComplete
105+
? undefined
106+
: "Incomplete agent inventory: this copy includes only currently known agents and may omit others in the channel. Review the lineup before saving; reload agents and copy again for a complete snapshot.",
107+
);
108+
menu?.close();
109+
setDraft({
110+
type: "template",
111+
id: crypto.randomUUID(),
112+
name: channel.name,
113+
description: "",
114+
teamIds: [],
115+
agents: catalog.agents
116+
.filter((a) => channel.members?.includes(a.pubkey))
117+
.map((a) => a.pubkey),
118+
canvas: canvas?.content ?? "",
119+
});
120+
} catch (error) {
121+
if (active()) setError(String(error));
122+
} finally {
123+
if (active()) setBusy(false);
124+
}
125+
};
126+
const disabled =
127+
busy || !session.channelKit.available || !catalog.agentsReady;
94128
return (
95129
<>
96-
<Button
97-
disabled={busy || !session.channelKit.available || !catalog.agentsReady}
98-
onClick={async () => {
99-
if (!active()) return;
100-
setBusy(true);
101-
setError("");
102-
try {
103-
const canvas = await session.canvas.read(channel.id);
104-
if (!active()) return;
105-
setCopyWarning(
106-
catalog.agentsComplete
107-
? undefined
108-
: "Incomplete agent inventory: this copy includes only currently known agents and may omit others in the channel. Review the lineup before saving; reload agents and copy again for a complete snapshot.",
109-
);
110-
setDraft({
111-
type: "template",
112-
id: crypto.randomUUID(),
113-
name: channel.name,
114-
description: "",
115-
teamIds: [],
116-
agents: catalog.agents
117-
.filter((a) => channel.members?.includes(a.pubkey))
118-
.map((a) => a.pubkey),
119-
canvas: canvas?.content ?? "",
120-
});
121-
} catch (error) {
122-
if (active()) setError(String(error));
123-
} finally {
124-
if (active()) setBusy(false);
125-
}
126-
}}
127-
>
128-
Save as template…
129-
</Button>
130-
{error && <p role="alert">{error}</p>}
130+
{menu ? (
131+
menu.render(
132+
<>
133+
<MenuItem disabled={disabled} onClick={copy} closeOnClick={false}>
134+
Save as template…
135+
</MenuItem>
136+
{error && <MenuNote role="alert">{error}</MenuNote>}
137+
</>,
138+
)
139+
) : (
140+
<>
141+
<Button disabled={disabled} onClick={copy}>
142+
Save as template…
143+
</Button>
144+
{error && <p role="alert">{error}</p>}
145+
</>
146+
)}
131147
{draft && (
132148
<ChannelTemplatesDialog
133149
session={session}
@@ -138,6 +154,7 @@ export function SaveAsTemplate({
138154
kit={session.channelKit}
139155
agents={catalog.agents}
140156
initial={draft}
157+
finalFocus={menu?.finalFocus}
141158
notice={copyWarning}
142159
active={active}
143160
/>

‎src/bundled/channel-templates/agent-selection.test.tsx‎

Lines changed: 126 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import {
1414
} from "@testing-library/react";
1515
import userEvent from "@testing-library/user-event";
1616
import { afterEach, beforeEach, assert, expect, it, vi } from "vitest";
17-
import { useState, useSyncExternalStore } from "react";
17+
import { useRef, useState, useSyncExternalStore } from "react";
1818
import { createRelaySession } from "../../features/relay/session";
1919
import { connectBrokerTransport } from "../../features/relay/transport";
2020
import type { RelayData } from "../../features/relay/service";
@@ -46,6 +46,7 @@ import { CreateChannelDialog } from "../channels/CreateChannelDialog";
4646
import { TemplateEditor } from "./TemplateEditor";
4747
import { Dialog } from "../../shared/design-system/ui/Dialog";
4848
import { SaveAsTemplate } from "./TemplateSettings";
49+
import { ChannelHeaderMenu } from "../channels/ChannelHeaderMenu";
4950
import { MentionPicker } from "../mentions/MentionPicker";
5051
import { MentionCompletion } from "../mentions/MentionCompletion";
5152
import type { CompletionResult } from "../../features/conversation/contracts";
@@ -89,6 +90,7 @@ function harness(
8990
beforeNativeRead?: () => Promise<void>,
9091
beforePublish?: (event: RelayEvent) => Promise<void>,
9192
afterPublish?: (event: RelayEvent) => Promise<void>,
93+
beforeCanvasRead?: () => Promise<void>,
9294
) {
9395
const viewer = keypair(),
9496
relay = keypair();
@@ -177,6 +179,8 @@ function harness(
177179
},
178180
},
179181
query: async (filters) => {
182+
if (filters.some((filter) => filter.kinds?.includes(40100)))
183+
await beforeCanvasRead?.();
180184
if (
181185
filters.some((filter) =>
182186
filter.kinds?.some((kind) => [39000, 39002].includes(kind)),
@@ -1770,3 +1774,124 @@ it("template replacement dismisses only its confirmation and preserves setup unt
17701774
test.dispose();
17711775
}
17721776
});
1777+
1778+
function HeaderTemplateMenu({
1779+
test,
1780+
registry,
1781+
}: {
1782+
test: ReturnType<typeof harness>;
1783+
registry: ReturnType<typeof providerFixture>;
1784+
}) {
1785+
const entries = useSyncExternalStore(
1786+
registry.providers.subscribe,
1787+
registry.providers.snapshot,
1788+
);
1789+
const trigger = useRef<HTMLButtonElement>(null);
1790+
return (
1791+
<ChannelHeaderMenu
1792+
channel={{ id: "11111111-1111-4111-8111-111111111111", name: "Copy me" }}
1793+
session={test.owner.session}
1794+
providers={registry.providers}
1795+
templateProvider={entries[0]}
1796+
trigger={trigger}
1797+
openDetails={() => {}}
1798+
openCanvas={() => {}}
1799+
/>
1800+
);
1801+
}
1802+
1803+
it("keeps failed template reads retryable in the header and opens the existing dialog only after success", async () => {
1804+
const read = vi
1805+
.fn(async () => {})
1806+
.mockRejectedValueOnce(new Error("Canvas unavailable"));
1807+
const test = harness(
1808+
undefined,
1809+
undefined,
1810+
true,
1811+
undefined,
1812+
undefined,
1813+
undefined,
1814+
read,
1815+
),
1816+
registry = providerFixture(),
1817+
user = userEvent.setup();
1818+
try {
1819+
render(<HeaderTemplateMenu test={test} registry={registry} />);
1820+
const trigger = screen.getByRole("button", { name: "Channel actions" });
1821+
await user.click(trigger);
1822+
const copy = await screen.findByRole("menuitem", {
1823+
name: "Save as template…",
1824+
});
1825+
await waitFor(() =>
1826+
expect(copy).not.toHaveAttribute("aria-disabled", "true"),
1827+
);
1828+
await user.click(copy);
1829+
expect(await screen.findByRole("alert")).toHaveTextContent(
1830+
"Canvas unavailable",
1831+
);
1832+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
1833+
await user.click(copy);
1834+
await screen.findByRole("dialog", { name: "Channel template" });
1835+
expect(read).toHaveBeenCalledTimes(2);
1836+
await waitFor(() =>
1837+
expect(screen.queryByRole("menu")).not.toBeInTheDocument(),
1838+
);
1839+
await user.keyboard("{Escape}");
1840+
await waitFor(() => expect(trigger).toHaveFocus());
1841+
expect(test.published).toEqual([]);
1842+
} finally {
1843+
cleanup();
1844+
test.dispose();
1845+
}
1846+
});
1847+
1848+
it("retires an in-flight header template copy when its optional provider is disabled", async () => {
1849+
let release!: () => void;
1850+
const held = new Promise<void>((resolve) => {
1851+
release = resolve;
1852+
});
1853+
const read = vi.fn(async () => {
1854+
await held;
1855+
});
1856+
const test = harness(
1857+
undefined,
1858+
undefined,
1859+
true,
1860+
undefined,
1861+
undefined,
1862+
undefined,
1863+
read,
1864+
),
1865+
registry = providerFixture(),
1866+
user = userEvent.setup();
1867+
try {
1868+
render(<HeaderTemplateMenu test={test} registry={registry} />);
1869+
await user.click(screen.getByRole("button", { name: "Channel actions" }));
1870+
const copy = await screen.findByRole("menuitem", {
1871+
name: "Save as template…",
1872+
});
1873+
await waitFor(() =>
1874+
expect(copy).not.toHaveAttribute("aria-disabled", "true"),
1875+
);
1876+
await user.click(copy);
1877+
await waitFor(() => expect(read).toHaveBeenCalledOnce());
1878+
expect(copy).toHaveAttribute("aria-disabled", "true");
1879+
act(() => registry.toggle(false));
1880+
await act(async () => {
1881+
release();
1882+
await held;
1883+
});
1884+
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
1885+
expect(
1886+
screen.queryByRole("menuitem", { name: "Save as template…" }),
1887+
).not.toBeInTheDocument();
1888+
expect(
1889+
screen.getByRole("menuitem", { name: "View channel details" }),
1890+
).toBeVisible();
1891+
expect(test.published).toEqual([]);
1892+
} finally {
1893+
release();
1894+
cleanup();
1895+
test.dispose();
1896+
}
1897+
});

0 commit comments

Comments
 (0)