Skip to content

Commit 9d77e5c

Browse files
authored
feat(ui): move chat view toggles into a header session menu (#121452)
* feat(ui): move chat view toggles into a header session menu Control UI: replace the chat composer eye-icon View dropdown with a Claude Desktop-style three-dot session menu at the far right of the chat pane header. The menu adds Open in for editor/worktree sessions, Rename, the three display toggles under View, Fork, Archive/Restore with undo, and Delete with confirmation. Reuse the sidebar session-organizer actions through a narrowed SessionActionHost seam, consolidate session permission gating in sessionMenuReasons, and remove the obsolete composer menu state, dismissal handling, tests, and CSS. * test(ui): update header session menu e2e interactions
1 parent 17bea11 commit 9d77e5c

27 files changed

Lines changed: 1154 additions & 1016 deletions
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import type { ApplicationGatewaySnapshot } from "../app/gateway.ts";
2+
import { readSessionMethodAccess } from "../lib/session-method-access.ts";
3+
import type { CloudWorkerStopAction } from "./cloud-worker-stop.ts";
4+
import type { SessionMenuActionKind } from "./session-menu.ts";
5+
6+
type SessionMenuAccessRow = {
7+
key: string;
8+
archived?: boolean;
9+
};
10+
11+
export function sessionMenuReasons(params: {
12+
snapshot: ApplicationGatewaySnapshot | undefined;
13+
session: SessionMenuAccessRow;
14+
batchRows?: readonly SessionMenuAccessRow[] | null;
15+
cloudWorkerStopAction?: CloudWorkerStopAction | null;
16+
}): Partial<Record<SessionMenuActionKind, string>> {
17+
const { snapshot, session, batchRows = null, cloudWorkerStopAction } = params;
18+
const reason = (request: {
19+
method: string;
20+
params?: unknown;
21+
requiredScope?: "operator.write" | "operator.admin";
22+
}) => {
23+
const access = readSessionMethodAccess(snapshot, request);
24+
return access.allowed ? undefined : access.reason;
25+
};
26+
const patchReason = reason({
27+
method: "sessions.patch",
28+
params: { key: session.key, label: null },
29+
});
30+
const batchPatchReason = (patch: Record<string, unknown>) => {
31+
if (!batchRows) {
32+
return patchReason;
33+
}
34+
const access = readSessionMethodAccess(snapshot, {
35+
method: "sessions.patchMany",
36+
params: {
37+
targets: batchRows.map((row) => ({ key: row.key })),
38+
patch,
39+
},
40+
});
41+
if (access.allowed) {
42+
return undefined;
43+
}
44+
return access.cause === "method-unavailable" ? patchReason : access.reason;
45+
};
46+
const unreadReason = batchPatchReason({ unread: true });
47+
const categoryReason = batchPatchReason({ category: null });
48+
const archiveReason = batchPatchReason({ archived: true });
49+
const groupReason = reason({
50+
method: "sessions.groups.put",
51+
requiredScope: "operator.write",
52+
});
53+
const deleteReason = (batchRows ?? [session])
54+
.map((row) =>
55+
reason({
56+
method: "sessions.delete",
57+
params: { key: row.key, ...(row.archived ? { archivedOnly: true } : {}) },
58+
}),
59+
)
60+
.find((value): value is string => Boolean(value));
61+
const forkReason = batchRows
62+
? undefined
63+
: reason({
64+
method: "sessions.create",
65+
params: { parentSessionKey: session.key, fork: true },
66+
});
67+
const cloudWorkerStopReason = cloudWorkerStopAction ? reason(cloudWorkerStopAction) : undefined;
68+
return {
69+
...(patchReason
70+
? {
71+
"toggle-pin": patchReason,
72+
rename: patchReason,
73+
}
74+
: {}),
75+
...(unreadReason ? { "toggle-unread": unreadReason } : {}),
76+
...(categoryReason ? { "move-to-group": categoryReason } : {}),
77+
...(archiveReason ? { "toggle-archived": archiveReason } : {}),
78+
...(groupReason || categoryReason ? { "new-group": groupReason ?? categoryReason } : {}),
79+
...(forkReason ? { fork: forkReason } : {}),
80+
...(cloudWorkerStopReason ? { "stop-cloud-worker": cloudWorkerStopReason } : {}),
81+
...(deleteReason ? { delete: deleteReason } : {}),
82+
};
83+
}

‎ui/src/components/session-organizer-batch-mutations.ts‎

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ import type {
1616
} from "./app-sidebar-session-types.ts";
1717
import type { SessionOrganizerControllerHost } from "./session-organizer-controller.ts";
1818

19+
export type SessionActionRow = Pick<
20+
SidebarRecentSession,
21+
"key" | "label" | "pinned" | "archived" | "active"
22+
>;
23+
24+
export type SessionActionHost = Pick<
25+
SessionOrganizerControllerHost,
26+
| "pruneSidebarSessionEntry"
27+
| "replaceCurrentSession"
28+
| "selectSession"
29+
| "sidebarSessionStatusFilter"
30+
> & {
31+
readonly sessionData: Pick<
32+
SessionOrganizerControllerHost["sessionData"],
33+
"isSessionMutationScopeCurrent" | "publishSessionMutationError" | "refreshSidebarSessions"
34+
>;
35+
};
36+
1937
function isLegacyPatchManyMethodRejection(error: unknown): boolean {
2038
return (
2139
error instanceof GatewayRequestError &&
@@ -25,7 +43,7 @@ function isLegacyPatchManyMethodRejection(error: unknown): boolean {
2543
}
2644

2745
export function sessionRowAgentId(
28-
session: SidebarRecentSession,
46+
session: SessionActionRow,
2947
scope: SidebarSessionMutationScope,
3048
): string {
3149
return parseAgentSessionKey(session.key)?.agentId ?? scope.selectedAgentId;
@@ -39,9 +57,9 @@ export function sessionRowAgentId(
3957
* result carries the stale/failed reporting the per-row refresh owed its caller.
4058
*/
4159
export async function refreshSessionsAfterBatch(
42-
host: SessionOrganizerControllerHost,
60+
host: SessionActionHost,
4361
scope: SidebarSessionMutationScope,
44-
rows: readonly SidebarRecentSession[],
62+
rows: readonly SessionActionRow[],
4563
): Promise<SidebarSessionMutationResult> {
4664
const agentIds = [...new Set(rows.map((row) => sessionRowAgentId(row, scope)))];
4765
const refreshSidebar = host.sidebarSessionStatusFilter() !== "active";
@@ -66,17 +84,17 @@ export async function refreshSessionsAfterBatch(
6684
}
6785

6886
export async function patchSessionRows(
69-
host: SessionOrganizerControllerHost,
70-
rows: readonly SidebarRecentSession[],
87+
host: SessionActionHost,
88+
rows: readonly SessionActionRow[],
7189
patch: SessionsPatchMutation,
7290
scope: SidebarSessionMutationScope,
7391
options: {
7492
deferListRefresh?: boolean;
75-
fallback?: () => Promise<SidebarRecentSession[] | null>;
93+
fallback?: () => Promise<SessionActionRow[] | null>;
7694
} = {},
77-
): Promise<SidebarRecentSession[] | null> {
95+
): Promise<SessionActionRow[] | null> {
7896
const dispatched: Array<{
79-
rows: readonly SidebarRecentSession[];
97+
rows: readonly SessionActionRow[];
8098
result: SessionsPatchManyResult;
8199
}> = [];
82100
let terminalError: unknown = null;

‎ui/src/components/session-organizer-operations.runtime.ts‎

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,13 @@ import {
2121
refreshSessionsAfterBatch,
2222
sessionRowAgentId,
2323
} from "./session-organizer-batch-mutations.ts";
24+
import type { SessionActionHost, SessionActionRow } from "./session-organizer-batch-mutations.ts";
2425
import type { SessionOrganizerControllerHost } from "./session-organizer-controller.ts";
2526

27+
export type { SessionActionHost, SessionActionRow } from "./session-organizer-batch-mutations.ts";
28+
2629
function requireSessionMutationAccess(
27-
host: SessionOrganizerControllerHost,
30+
host: SessionActionHost,
2831
scope: SidebarSessionMutationScope,
2932
request: {
3033
method: string;
@@ -41,8 +44,8 @@ function requireSessionMutationAccess(
4144
}
4245

4346
export async function patchSession(
44-
host: SessionOrganizerControllerHost,
45-
session: SidebarRecentSession,
47+
host: SessionActionHost,
48+
session: SessionActionRow,
4649
patch: SidebarSessionPatch,
4750
scope: SidebarSessionMutationScope,
4851
refresh: { deferListRefresh?: boolean } = {},
@@ -120,13 +123,13 @@ export async function patchSessions(
120123
}
121124

122125
async function patchSessionRowsSerial(
123-
host: SessionOrganizerControllerHost,
124-
rows: readonly SidebarRecentSession[],
126+
host: SessionActionHost,
127+
rows: readonly SessionActionRow[],
125128
patch: SidebarSessionPatch,
126129
scope: SidebarSessionMutationScope,
127130
options: { deferListRefresh?: boolean } = {},
128-
): Promise<SidebarRecentSession[] | null> {
129-
const completed: SidebarRecentSession[] = [];
131+
): Promise<SessionActionRow[] | null> {
132+
const completed: SessionActionRow[] = [];
130133
for (const row of rows) {
131134
const result = await patchSession(host, row, patch, scope, { deferListRefresh: true });
132135
if (result === "stale") {
@@ -146,8 +149,8 @@ async function patchSessionRowsSerial(
146149
}
147150

148151
export async function archiveSessionWithUndo(
149-
host: SessionOrganizerControllerHost,
150-
session: SidebarRecentSession,
152+
host: SessionActionHost,
153+
session: SessionActionRow,
151154
scope: SidebarSessionMutationScope,
152155
) {
153156
const result = await patchSession(host, session, { archived: true }, scope);
@@ -157,9 +160,8 @@ export async function archiveSessionWithUndo(
157160
showToast({
158161
message: t("sessionsView.sessionArchived"),
159162
actionLabel: t("common.undo"),
160-
onAction: () => {
161-
void restoreArchivedSessions(host, [{ session, pinned: session.pinned }], scope);
162-
},
163+
onAction: () =>
164+
void restoreArchivedSessions(host, [{ session, pinned: session.pinned }], scope),
163165
});
164166
}
165167

@@ -189,8 +191,8 @@ async function archiveSessionsWithUndo(
189191
}
190192

191193
async function restoreArchivedSessions(
192-
host: SessionOrganizerControllerHost,
193-
archived: readonly { session: SidebarRecentSession; pinned: boolean }[],
194+
host: SessionActionHost,
195+
archived: readonly { session: SessionActionRow; pinned: boolean }[],
194196
scope: SidebarSessionMutationScope,
195197
) {
196198
const rows = archived.map((entry) => entry.session);
@@ -514,8 +516,8 @@ export async function assignSessionCategory(
514516
}
515517

516518
export async function forkSession(
517-
host: SessionOrganizerControllerHost,
518-
session: SidebarRecentSession,
519+
host: SessionActionHost,
520+
session: SessionActionRow,
519521
scope: SidebarSessionMutationScope,
520522
) {
521523
if (!host.sessionData.isSessionMutationScopeCurrent(scope)) {
@@ -593,8 +595,8 @@ export async function stopCloudWorker(
593595
}
594596

595597
export async function deleteSession(
596-
host: SessionOrganizerControllerHost,
597-
session: SidebarRecentSession,
598+
host: SessionActionHost,
599+
session: SessionActionRow,
598600
scope: SidebarSessionMutationScope,
599601
) {
600602
if (!window.confirm(t("sessionsView.deleteSessionConfirm", { session: session.label }))) {

‎ui/src/components/sidebar-menus-render.ts‎

Lines changed: 5 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import { html, nothing } from "lit";
22
import { keyed } from "lit/directives/keyed.js";
33
import { DEFAULT_SIDEBAR_ENTRIES, serializeSidebarEntry } from "../app-navigation.ts";
4-
import type { RouteId } from "../app-route-paths.ts";
5-
import type { ApplicationContext } from "../app/context.ts";
64
import { readPresenceEntries, resolveCurrentSelfUser } from "../app/user-profile.ts";
75
import { normalizeAgentLabel } from "../lib/agents/display.ts";
86
import { openEditor } from "../lib/editor-links.ts";
@@ -22,96 +20,13 @@ import {
2220
renderSidebarSessionGroupMenu,
2321
renderSidebarSessionSortMenu,
2422
} from "./app-sidebar-session-menu-renderers.ts";
25-
import type { SidebarRecentSession } from "./app-sidebar-session-types.ts";
23+
import { sessionMenuReasons } from "./session-menu-access.ts";
2624
import type { SessionMenuAction } from "./session-menu.ts";
2725
import type {
2826
SidebarMenusController,
2927
SidebarMenusControllerHost,
3028
} from "./sidebar-menus-controller.ts";
3129

32-
function sessionMenuActionDisabledReasons(
33-
snapshot: ApplicationContext<RouteId>["gateway"]["snapshot"] | undefined,
34-
session: SidebarRecentSession,
35-
batchRows: readonly SidebarRecentSession[] | null,
36-
): Partial<Record<SessionMenuAction["kind"], string>> {
37-
const reason = (request: {
38-
method: string;
39-
params?: unknown;
40-
requiredScope?: "operator.write" | "operator.admin";
41-
}) => {
42-
const access = readSessionMethodAccess(snapshot, request);
43-
return access.allowed ? undefined : access.reason;
44-
};
45-
const patchReason = reason({
46-
method: "sessions.patch",
47-
params: { key: session.key, label: null },
48-
});
49-
const batchPatchReason = (patch: Record<string, unknown>) => {
50-
if (!batchRows) {
51-
return patchReason;
52-
}
53-
const access = readSessionMethodAccess(snapshot, {
54-
method: "sessions.patchMany",
55-
params: {
56-
targets: batchRows.map((row) => ({ key: row.key })),
57-
patch,
58-
},
59-
});
60-
if (access.allowed) {
61-
return undefined;
62-
}
63-
return access.cause === "method-unavailable" ? patchReason : access.reason;
64-
};
65-
const unreadReason = batchPatchReason({ unread: true });
66-
const categoryReason = batchPatchReason({ category: null });
67-
const archiveReason = batchPatchReason({ archived: true });
68-
const groupReason = reason({
69-
method: "sessions.groups.put",
70-
requiredScope: "operator.write",
71-
});
72-
const deleteRows = batchRows ?? [session];
73-
const cloudWorkerStopReason = session.cloudWorkerStopAction
74-
? reason(session.cloudWorkerStopAction)
75-
: undefined;
76-
const deleteReason = deleteRows
77-
.map((row) =>
78-
reason({
79-
method: "sessions.delete",
80-
params: { key: row.key, ...(row.archived ? { archivedOnly: true } : {}) },
81-
}),
82-
)
83-
.find((value): value is string => Boolean(value));
84-
return {
85-
...(patchReason
86-
? {
87-
"toggle-pin": patchReason,
88-
rename: patchReason,
89-
}
90-
: {}),
91-
...(unreadReason ? { "toggle-unread": unreadReason } : {}),
92-
...(categoryReason ? { "move-to-group": categoryReason } : {}),
93-
...(archiveReason ? { "toggle-archived": archiveReason } : {}),
94-
...(groupReason || categoryReason ? { "new-group": groupReason ?? categoryReason } : {}),
95-
...(deleteReason ? { delete: deleteReason } : {}),
96-
...(batchRows
97-
? {}
98-
: {
99-
...(reason({
100-
method: "sessions.create",
101-
params: { parentSessionKey: session.key, fork: true },
102-
})
103-
? {
104-
fork: reason({
105-
method: "sessions.create",
106-
params: { parentSessionKey: session.key, fork: true },
107-
}),
108-
}
109-
: {}),
110-
...(cloudWorkerStopReason ? { "stop-cloud-worker": cloudWorkerStopReason } : {}),
111-
}),
112-
};
113-
}
114-
11530
export function renderSidebarCustomizeMenuForController(controller: SidebarMenusController) {
11631
const { host } = controller;
11732
const position = controller.customizeMenuPosition;
@@ -269,11 +184,12 @@ export function renderSidebarSessionMenuForController(controller: SidebarMenusCo
269184
.anchor=${menu}
270185
.trigger=${controller.sessionMenuTrigger}
271186
.disabled=${!host.connected}
272-
.actionDisabledReasons=${sessionMenuActionDisabledReasons(
273-
context?.gateway.snapshot,
187+
.actionDisabledReasons=${sessionMenuReasons({
188+
snapshot: context?.gateway.snapshot,
274189
session,
275190
batchRows,
276-
)}
191+
cloudWorkerStopAction: session.cloudWorkerStopAction,
192+
})}
277193
.forkDisabled=${host.sessionData.sessionsLoading || session.modelSelectionLocked}
278194
.archiveAllowed=${archiveAllowed}
279195
.deleteAllowed=${deleteAllowed}

0 commit comments

Comments
 (0)