Skip to content

Commit bbb5164

Browse files
fix(ui): keep chat sharing menu compact (#122322)
* fix(ui): keep chat sharing menu compact * fix(ui): refine sharing menu sections * fix(ui): use one sharing menu scroll
1 parent 021ea77 commit bbb5164

4 files changed

Lines changed: 299 additions & 22 deletions

File tree

‎ui/src/e2e/session-ownership.e2e.test.ts‎

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,148 @@ suite.define(() => {
468468
expect(await gateway.getRequests("session.members.add")).toHaveLength(0);
469469
});
470470

471+
it("scrolls high-volume sharing through one compact menu", async () => {
472+
const context = await suite.browser.newContext({ viewport: { height: 800, width: 1280 } });
473+
const currentPage = await context.newPage();
474+
page = currentPage;
475+
const sessions = sessionsList(["profile-ada", "profile-bob"]);
476+
const activeSession = sessions.sessions[0];
477+
if (!activeSession) {
478+
throw new Error("expected active session fixture");
479+
}
480+
Object.assign(activeSession, { visibility: "shared", sharingRole: "owner" });
481+
sessions.count = 1;
482+
sessions.creators = [{ id: "profile-ada", label: "Ada" }];
483+
sessions.sessions = [activeSession];
484+
const humanIdentities = Array.from({ length: 30 }, (_, index) => ({
485+
type: "human" as const,
486+
id: `profile-member-${index}`,
487+
label: `Member ${index + 1}`,
488+
}));
489+
const channelIdentities = [
490+
{ type: "human" as const, id: "channel:chn_design", label: "Design" },
491+
{ type: "human" as const, id: "discord:channel:operations", label: "Operations" },
492+
];
493+
const gateway = await installMockGateway(currentPage, {
494+
sessionKey: "agent:main:ada",
495+
hasMultipleSessionSharingIdentities: true,
496+
featureMethods: [
497+
"chat.metadata",
498+
"chat.startup",
499+
"session.members.list",
500+
"session.members.add",
501+
"session.members.remove",
502+
"session.visibility.set",
503+
],
504+
operatorScopes: ["operator.read", "operator.write"],
505+
historyMessages: [{ role: "assistant", content: [{ type: "text", text: "Ready." }] }],
506+
methodResponses: {
507+
"sessions.list": sessions,
508+
"session.members.list": {
509+
sessionKey: "agent:main:ada",
510+
members: [],
511+
identities: [...humanIdentities, ...channelIdentities],
512+
role: "owner",
513+
allowedVisibilities: ["shared", "read-only", "suggest", "draft"],
514+
},
515+
},
516+
});
517+
518+
await currentPage.goto(`${suite.server?.baseUrl ?? ""}chat`);
519+
await currentPage.getByText("Ready.", { exact: true }).waitFor();
520+
await currentPage.locator(".chat-pane__sharing-trigger").click();
521+
await gateway.waitForRequest("session.members.list");
522+
const dropdown = currentPage.locator(".chat-pane__sharing-menu");
523+
await dropdown.locator('wa-dropdown-item[value="member:profile-member-0"]').waitFor();
524+
await dropdown.evaluate(async (element) => {
525+
const menu = element.shadowRoot?.querySelector<HTMLElement>('[part="menu"]');
526+
const animations = [...element.getAnimations(), ...(menu?.getAnimations() ?? [])];
527+
await Promise.all(animations.map((animation) => animation.finished.catch(() => {})));
528+
});
529+
530+
const beforeScroll = await dropdown.evaluate((element) => {
531+
const menu = element.shadowRoot?.querySelector<HTMLElement>('[part="menu"]');
532+
const visibilityTitle = element.querySelector<HTMLElement>(
533+
".chat-pane__sharing-visibility-title",
534+
);
535+
const visibilityItems = [
536+
...element.querySelectorAll<HTMLElement>(".chat-pane__sharing-visibility-item"),
537+
];
538+
const membersTitle = element.querySelector<HTMLElement>(".chat-pane__sharing-members-title");
539+
const firstMember = element.querySelector<HTMLElement>(".chat-pane__sharing-member");
540+
const previousVisibilityRect = visibilityItems.at(-2)?.getBoundingClientRect();
541+
const lastVisibilityRect = visibilityItems.at(-1)?.getBoundingClientRect();
542+
const membersTitleRect = membersTitle?.getBoundingClientRect();
543+
return {
544+
menuHeight: menu?.getBoundingClientRect().height ?? 0,
545+
menuTop: menu?.getBoundingClientRect().top ?? 0,
546+
scrollHeight: menu?.scrollHeight ?? 0,
547+
clientHeight: menu?.clientHeight ?? 0,
548+
firstMemberTop: firstMember?.getBoundingClientRect().top ?? 0,
549+
groupGap:
550+
membersTitleRect && lastVisibilityRect
551+
? membersTitleRect.top - lastVisibilityRect.bottom
552+
: 0,
553+
rowGap:
554+
previousVisibilityRect && lastVisibilityRect
555+
? lastVisibilityRect.top - previousVisibilityRect.bottom
556+
: 0,
557+
membersTitleInset: Number.parseFloat(
558+
membersTitle ? getComputedStyle(membersTitle).paddingInlineStart : "0",
559+
),
560+
firstMemberInset: Number.parseFloat(
561+
firstMember ? getComputedStyle(firstMember).paddingInlineStart : "0",
562+
),
563+
visibilityTitlePosition: visibilityTitle ? getComputedStyle(visibilityTitle).position : "",
564+
membersTitlePosition: membersTitle ? getComputedStyle(membersTitle).position : "",
565+
nestedScrollers: [...element.children].filter((child) => {
566+
const node = child as HTMLElement;
567+
return (
568+
node.scrollHeight > node.clientHeight &&
569+
["auto", "scroll"].includes(getComputedStyle(node).overflowY)
570+
);
571+
}).length,
572+
};
573+
});
574+
const afterScroll = await dropdown.evaluate(async (element) => {
575+
const menu = element.shadowRoot?.querySelector<HTMLElement>('[part="menu"]');
576+
const visibilityTitle = element.querySelector<HTMLElement>(
577+
".chat-pane__sharing-visibility-title",
578+
);
579+
const membersTitle = element.querySelector<HTMLElement>(".chat-pane__sharing-members-title");
580+
const firstMember = element.querySelector<HTMLElement>(".chat-pane__sharing-member");
581+
if (menu) {
582+
menu.scrollTop = menu.scrollHeight;
583+
}
584+
await new Promise<void>((resolve) => {
585+
requestAnimationFrame(() => resolve());
586+
});
587+
return {
588+
scrollTop: menu?.scrollTop ?? 0,
589+
visibilityTitleBottom: visibilityTitle?.getBoundingClientRect().bottom ?? 0,
590+
membersTitleTop: membersTitle?.getBoundingClientRect().top ?? 0,
591+
firstMemberTop: firstMember?.getBoundingClientRect().top ?? 0,
592+
};
593+
});
594+
595+
expect(beforeScroll.menuHeight).toBeLessThanOrEqual(421);
596+
expect(beforeScroll.scrollHeight).toBeGreaterThan(beforeScroll.clientHeight);
597+
expect(beforeScroll.membersTitleInset).toBe(beforeScroll.firstMemberInset);
598+
expect(beforeScroll.groupGap).toBeGreaterThanOrEqual(8);
599+
expect(beforeScroll.groupGap).toBeGreaterThan(beforeScroll.rowGap + 6);
600+
expect(beforeScroll.visibilityTitlePosition).not.toBe("sticky");
601+
expect(beforeScroll.membersTitlePosition).not.toBe("sticky");
602+
expect(beforeScroll.nestedScrollers).toBe(0);
603+
expect(afterScroll.scrollTop).toBeGreaterThan(0);
604+
expect(afterScroll.visibilityTitleBottom).toBeLessThan(beforeScroll.menuTop);
605+
expect(afterScroll.membersTitleTop).toBeLessThan(beforeScroll.menuTop);
606+
expect(afterScroll.firstMemberTop).toBeLessThan(beforeScroll.firstMemberTop);
607+
await expectBrowser(
608+
dropdown.locator(".chat-pane__sharing-member openclaw-session-owner-chip"),
609+
).toHaveCount(30);
610+
await expectBrowser(dropdown.locator(".chat-pane__sharing-channel-icon")).toHaveCount(2);
611+
});
612+
471613
it("clears a selected draft mode when sharing policy becomes unavailable", async () => {
472614
const context = await suite.browser.newContext({ viewport: { height: 800, width: 1200 } });
473615
const currentPage = await context.newPage();

‎ui/src/pages/chat/components/chat-session-sharing.test.ts‎

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ describe("chat session sharing menu", () => {
5555
expect(root.textContent).not.toContain("Suggest");
5656
expect(root.textContent).toContain("Alice");
5757
expect(root.querySelector('wa-dropdown-item[value="member:owner"]')).toBeNull();
58+
expect(root.querySelector(".session-menu__separator")).toBeNull();
5859

5960
dropdown?.dispatchEvent(
6061
new CustomEvent("wa-select", {
@@ -70,6 +71,49 @@ describe("chat session sharing menu", () => {
7071
expect(onMemberChange).toHaveBeenCalledWith("alice", true);
7172
});
7273

74+
it("distinguishes people from channel-backed members", () => {
75+
const root = mount(
76+
renderChatSessionSharing({
77+
session: {
78+
key: "agent:main:main",
79+
kind: "direct",
80+
updatedAt: 1,
81+
visibility: "shared",
82+
sharingRole: "owner",
83+
},
84+
state: {
85+
loading: false,
86+
result: {
87+
sessionKey: "agent:main:main",
88+
members: [],
89+
identities: [
90+
{ type: "human", id: "profile-vyctor", label: "Vyctor Brzezowski" },
91+
{ type: "human", id: "channel:chn_design", label: "Design" },
92+
{ type: "human", id: "discord:channel:operations", label: "Operations" },
93+
],
94+
role: "owner",
95+
allowedVisibilities: ["shared"],
96+
},
97+
},
98+
onOpen: vi.fn(),
99+
onVisibilityChange: vi.fn(),
100+
onMemberChange: vi.fn(),
101+
}),
102+
);
103+
104+
const human = root.querySelector('wa-dropdown-item[value="member:profile-vyctor"]');
105+
const channels = [
106+
root.querySelector('wa-dropdown-item[value="member:channel:chn_design"]'),
107+
root.querySelector('wa-dropdown-item[value="member:discord:channel:operations"]'),
108+
];
109+
110+
expect(human?.querySelector("openclaw-session-owner-chip")).not.toBeNull();
111+
for (const channel of channels) {
112+
expect(channel?.querySelector("openclaw-session-owner-chip")).toBeNull();
113+
expect(channel?.querySelector(".chat-pane__sharing-channel-icon svg")).not.toBeNull();
114+
}
115+
});
116+
73117
it("shows only the draft marker to a non-manager", () => {
74118
const root = mount(
75119
renderChatSessionSharing({

‎ui/src/pages/chat/components/chat-session-sharing.ts‎

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type {
55
SessionVisibility,
66
} from "../../../api/types.ts";
77
import { icons } from "../../../components/icons.ts";
8+
import { renderSessionOwnerChip } from "../../../components/session-owner-chip.ts";
89
import "../../../components/web-awesome.ts";
910
import { t } from "../../../i18n/index.ts";
1011

@@ -42,6 +43,10 @@ function sharingIcon(visibility: SessionVisibility): TemplateResult {
4243
return visibility === "shared" ? icons.users : icons.lock;
4344
}
4445

46+
function isChannelIdentity(identityId: string): boolean {
47+
return identityId.startsWith("channel:") || identityId.includes(":channel:");
48+
}
49+
4550
export function canManageChatSessionSharing(
4651
session: Pick<GatewaySessionRow, "sharingRole">,
4752
): boolean {
@@ -70,9 +75,12 @@ export function renderChatSessionSharing(props: ChatSessionSharingProps) {
7075
const allowed = result?.allowedVisibilities ?? props.allowedVisibilities ?? [visibility];
7176
const canPublish = visibility === "draft" && allowed.includes("shared");
7277
const membersAvailable = props.membersAvailable !== false;
78+
const visibilityOptions = allowed.filter((option) => !canPublish || option !== "shared");
79+
const shouldCapMembers =
80+
membersAvailable && visibilityOptions.length + identities.length + (canPublish ? 1 : 0) > 12;
7381
return html`
7482
<wa-dropdown
75-
class="chat-pane__sharing-menu"
83+
class="chat-pane__sharing-menu ${shouldCapMembers ? "chat-pane__sharing-menu--capped" : ""}"
7684
placement="bottom-end"
7785
@wa-show=${() => {
7886
if (!props.openDisabledReason) {
@@ -124,41 +132,60 @@ export function renderChatSessionSharing(props: ChatSessionSharingProps) {
124132
</wa-dropdown-item>
125133
<div class="session-menu__separator" role="separator"></div>`
126134
: nothing}
127-
<div class="chat-pane__sharing-title">${t("chat.sessionSharing.visibility")}</div>
128-
${allowed
129-
.filter((option) => !canPublish || option !== "shared")
130-
.map(
131-
(option) => html`
132-
<wa-dropdown-item
133-
value=${`visibility:${option}`}
134-
?disabled=${option === visibility || Boolean(props.visibilityDisabledReason)}
135-
title=${props.visibilityDisabledReason ?? nothing}
136-
>
137-
<span>${t(VISIBILITY_LABEL_KEYS[option])}</span>
138-
${option === visibility
139-
? html`<span slot="details" aria-hidden="true">${icons.check}</span>`
140-
: nothing}
141-
</wa-dropdown-item>
142-
`,
143-
)}
135+
<div class="chat-pane__sharing-title chat-pane__sharing-visibility-title">
136+
${t("chat.sessionSharing.visibility")}
137+
</div>
138+
${visibilityOptions.map(
139+
(option) => html`
140+
<wa-dropdown-item
141+
class="session-menu__item chat-pane__sharing-visibility-item"
142+
value=${`visibility:${option}`}
143+
?disabled=${option === visibility || Boolean(props.visibilityDisabledReason)}
144+
title=${props.visibilityDisabledReason ?? nothing}
145+
>
146+
<span>${t(VISIBILITY_LABEL_KEYS[option])}</span>
147+
${option === visibility
148+
? html`<span slot="details" aria-hidden="true">${icons.check}</span>`
149+
: nothing}
150+
</wa-dropdown-item>
151+
`,
152+
)}
144153
${membersAvailable
145154
? html`
146-
<div class="session-menu__separator" role="separator"></div>
147-
<div class="chat-pane__sharing-title">${t("chat.sessionSharing.members")}</div>
155+
<div class="chat-pane__sharing-title chat-pane__sharing-members-title">
156+
${t("chat.sessionSharing.members")}
157+
</div>
148158
${props.state?.loading
149159
? html`<div class="chat-pane__sharing-status">${t("common.loading")}</div>`
150160
: identities.length > 0
151161
? identities.map((identity) => {
152162
const disabledReason = members.has(identity.id)
153163
? props.memberRemoveDisabledReason
154164
: props.memberAddDisabledReason;
165+
const channelIdentity = isChannelIdentity(identity.id);
155166
return html`
156167
<wa-dropdown-item
168+
class="session-menu__item chat-pane__sharing-member"
157169
value=${`member:${identity.id}`}
158170
?disabled=${Boolean(disabledReason)}
159171
title=${disabledReason ?? nothing}
160172
>
161-
<span>${identity.label ?? identity.id}</span>
173+
<span
174+
slot="icon"
175+
class="chat-pane__sharing-member-icon ${channelIdentity
176+
? "chat-pane__sharing-channel-icon"
177+
: ""}"
178+
aria-hidden="true"
179+
>
180+
${channelIdentity
181+
? icons.messageSquare
182+
: identity.type === "human"
183+
? renderSessionOwnerChip(identity, "header")
184+
: icons.bot}
185+
</span>
186+
<span class="chat-pane__sharing-member-label"
187+
>${identity.label ?? identity.id}</span
188+
>
162189
${members.has(identity.id)
163190
? html`<span
164191
slot="details"

0 commit comments

Comments
 (0)