Skip to content

Commit 04eae7c

Browse files
authored
feat(ui): link session hovercard identities to their activity feed (#128313)
* feat(ui): link session hovercard identities to their activity feed Names shown in the session hovercard are now links to that person's Activity feed. `activityPersonLocation` in app-route-paths owns the `person` query contract that the Activity filters parse and the sidebar ONLINE list already hand-rolled, so every identity surface builds the same link. The creator avatar gets a decorative twin link (aria-hidden, out of the tab order) and participant names keep the locale's own "with {name}" phrasing and list separators while each name becomes its own link. * test(ui): capture the hovercard identity at rest for PR proof
1 parent 7c7e10a commit 04eae7c

8 files changed

Lines changed: 421 additions & 53 deletions

‎ui/src/app-route-paths.ts‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,19 @@ export function pathForRoute(routeId: RouteId, basePath = ""): string {
107107
return normalizedBasePath ? `${normalizedBasePath}${path}` : path;
108108
}
109109

110+
/** Query key the Activity feed reads to scope its session list to one person. */
111+
export const ACTIVITY_PERSON_PARAM = "person";
112+
113+
/** Activity feed scoped to one person, for every surface that shows an identity. */
114+
export function activityPersonLocation(
115+
personId: string,
116+
basePath = "",
117+
): { pathname: string; search: string; href: string } {
118+
const pathname = pathForRoute("activity", basePath);
119+
const search = `?${new URLSearchParams({ [ACTIVITY_PERSON_PARAM]: personId }).toString()}`;
120+
return { pathname, search, href: `${pathname}${search}` };
121+
}
122+
110123
export function pathForWorkboardBoard(boardId: string, basePath = ""): string {
111124
if (!isValidWorkboardBoardId(boardId)) {
112125
throw new Error("Invalid Workboard board id.");

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
type NavigationRouteId,
66
type SidebarZoneEntry,
77
} from "../app-navigation.ts";
8-
import { isRouteId, isSessionRouteId, pathForRoute } from "../app-route-paths.ts";
8+
import { activityPersonLocation, isRouteId, isSessionRouteId } from "../app-route-paths.ts";
99
import { resolveControlUiAuthToken } from "../app/control-ui-auth.ts";
1010
import { isNativeWebChromeHost } from "../app/native-web-chrome.ts";
1111
import { readPresenceEntries, resolveCurrentSelfUser } from "../app/user-profile.ts";
@@ -315,14 +315,13 @@ export function renderAppSidebarOnline(host: AppSidebarRenderHost) {
315315
? nothing
316316
: html`<div class="sidebar-online__list">
317317
${users.map((user) => {
318-
const pathname = pathForRoute("activity", host.basePath);
319-
const search = `?${new URLSearchParams({ person: user.id }).toString()}`;
318+
const { pathname, search, href } = activityPersonLocation(user.id, host.basePath);
320319
return html`<a
321320
class="sidebar-online__person ${isPresenceViewerIdle(user)
322321
? "sidebar-online__person--away"
323322
: ""}"
324323
data-online-user-id=${user.id}
325-
href=${`${pathname}${search}`}
324+
href=${href}
326325
@click=${(event: MouseEvent) => {
327326
if (!shouldHandleNavigationClick(event)) {
328327
return;

‎ui/src/components/session-hovercard.test.ts‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,78 @@ describe("renderSessionHovercard", () => {
338338
).toBe("Alice Baker, Mira, Riley 3 more participants");
339339
});
340340

341+
it("opens the creator's activity feed from the identity row", () => {
342+
const container = document.createElement("div");
343+
const navigate = vi.fn();
344+
render(
345+
renderSessionHovercard({
346+
row: row(),
347+
personActivity: { basePath: "/ui", navigate },
348+
}),
349+
container,
350+
);
351+
352+
const name = container.querySelector<HTMLAnchorElement>(".session-hovercard__identity-name");
353+
expect(name?.getAttribute("href")).toBe("/ui/activity?person=alice");
354+
expect(
355+
container
356+
.querySelector(".session-hovercard__identity-avatar-link")
357+
?.getAttribute("aria-hidden"),
358+
).toBe("true");
359+
360+
const click = new MouseEvent("click", { bubbles: true, cancelable: true });
361+
name?.dispatchEvent(click);
362+
expect(navigate).toHaveBeenCalledWith("alice");
363+
expect(click.defaultPrevented).toBe(true);
364+
});
365+
366+
it("links every participant name while keeping the locale's list phrasing", () => {
367+
const container = document.createElement("div");
368+
const navigate = vi.fn();
369+
render(
370+
renderSessionHovercard({
371+
selfUserId: "self",
372+
row: row({
373+
participants: [
374+
{ type: "human", id: "self", label: "You" },
375+
{ type: "human", id: "mira", label: "Mira" },
376+
{ type: "human", id: "riley", label: "Riley" },
377+
],
378+
participantCount: 5,
379+
}),
380+
personActivity: { basePath: "", navigate },
381+
}),
382+
container,
383+
);
384+
385+
expect(
386+
container
387+
.querySelector(".session-hovercard__identity-copy")
388+
?.textContent?.replace(/\s+/gu, " ")
389+
.trim(),
390+
).toBe("Alice Baker · with Mira, Riley +2");
391+
const participantLinks = [
392+
...container.querySelectorAll<HTMLAnchorElement>("a.session-hovercard__participant-name"),
393+
];
394+
expect(participantLinks.map((link) => [link.textContent, link.getAttribute("href")])).toEqual([
395+
["Mira", "/activity?person=mira"],
396+
["Riley", "/activity?person=riley"],
397+
]);
398+
399+
participantLinks[1]?.dispatchEvent(
400+
new MouseEvent("click", { bubbles: true, cancelable: true }),
401+
);
402+
expect(navigate).toHaveBeenCalledWith("riley");
403+
});
404+
405+
it("keeps the identity plain text when no activity route is available", () => {
406+
const container = document.createElement("div");
407+
render(renderSessionHovercard({ row: row() }), container);
408+
409+
expect(container.querySelector(".session-hovercard__identity-name")?.tagName).toBe("SPAN");
410+
expect(container.querySelector(".session-hovercard__identity-avatar-link")).toBeNull();
411+
});
412+
341413
it("keeps authoritative overflow when the participant projection is truncated", () => {
342414
const container = document.createElement("div");
343415
render(

‎ui/src/components/session-hovercard.ts‎

Lines changed: 142 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,48 @@
11
import type { ProgressCard } from "@openclaw/gateway-protocol";
22
import { bucketRelativeTimeMs, type RelativeTimeUnit } from "@openclaw/normalization-core";
3-
import { html, nothing } from "lit";
3+
import { html, nothing, type TemplateResult } from "lit";
44
import type {
55
ControlUiSessionPullRequest,
66
ControlUiSessionPullRequestSnapshot,
77
} from "../../../src/gateway/control-ui-contract.js";
8+
import { activityPersonLocation } from "../app-route-paths.ts";
89
import { i18n, t } from "../i18n/index.ts";
10+
import { shouldHandleNavigationClick } from "../lib/navigation-click.ts";
911
import type { SidebarSessionHovercardRow } from "./app-sidebar-session-types.ts";
1012
import { icons } from "./icons.ts";
11-
import { sessionOwnerInitials } from "./session-owner-chip.ts";
13+
import { sessionOwnerInitials, type SessionCreatedActor } from "./session-owner-chip.ts";
1214
import { renderSessionProgressCard } from "./session-progress-card.ts";
1315
import "./viewer-facepile.ts";
1416

1517
const MAX_VISIBLE_PULL_REQUESTS = 4;
1618
const MAX_VISIBLE_PARTICIPANTS = 3;
1719

20+
function participantLabel(participant: SessionCreatedActor): string {
21+
return participant.label?.trim() || participant.id?.trim() || "";
22+
}
23+
1824
type SessionAgeUnit = RelativeTimeUnit | "week" | "month" | "year";
1925

2026
type SessionHovercardAvatarAuth = {
2127
authTokens: readonly string[];
2228
authReady: boolean;
2329
};
2430

31+
/** Opens the Activity feed for one identity; supplied by the hovercard host that owns routing. */
32+
export type SessionHovercardPersonActivity = {
33+
basePath: string;
34+
navigate: (personId: string) => void;
35+
};
36+
37+
type SessionHovercardInput = {
38+
row?: SidebarSessionHovercardRow;
39+
selfUserId?: string;
40+
avatarAuth?: SessionHovercardAvatarAuth;
41+
personActivity?: SessionHovercardPersonActivity;
42+
pullRequests?: ControlUiSessionPullRequestSnapshot;
43+
progressCard?: ProgressCard | null;
44+
};
45+
2546
let channelAvatarElementLoad: Promise<unknown> | undefined;
2647
function ensureChannelAvatarElement(): void {
2748
channelAvatarElementLoad ??= import("./channel-avatar.ts");
@@ -158,11 +179,80 @@ function renderHeader(row: SidebarSessionHovercardRow) {
158179
</header>`;
159180
}
160181

161-
function renderSessionContext(
162-
row: SidebarSessionHovercardRow | undefined,
163-
selfUserId?: string,
164-
avatarAuth?: SessionHovercardAvatarAuth,
182+
type PersonActivityLink = { href: string; open: (event: MouseEvent) => void };
183+
184+
function personActivityLink(
185+
personId: string,
186+
personActivity: SessionHovercardPersonActivity | undefined,
187+
): PersonActivityLink | null {
188+
if (!personActivity) {
189+
return null;
190+
}
191+
return {
192+
href: activityPersonLocation(personId, personActivity.basePath).href,
193+
open: (event: MouseEvent) => {
194+
if (!shouldHandleNavigationClick(event)) {
195+
return;
196+
}
197+
event.preventDefault();
198+
personActivity.navigate(personId);
199+
},
200+
};
201+
}
202+
203+
function renderPersonName(label: string, link: PersonActivityLink | null, className: string) {
204+
return link
205+
? html`<a
206+
class="${className} session-hovercard__identity-link"
207+
href=${link.href}
208+
@click=${link.open}
209+
>${label}</a
210+
>`
211+
: html`<span class=${className}>${label}</span>`;
212+
}
213+
214+
/**
215+
* Keeps the locale's own "with {name}" phrasing and list separators while making each
216+
* name its own link. A translation that lost its placeholder falls back to plain text
217+
* rather than dropping the names.
218+
*/
219+
function renderParticipantNames(
220+
participants: readonly SessionCreatedActor[],
221+
formattedNames: string,
222+
personActivity: SessionHovercardPersonActivity | undefined,
165223
) {
224+
const [prefix, suffix] = t("sessionsView.withParticipant").split("{name}");
225+
if (suffix === undefined) {
226+
return t("sessionsView.withParticipant", { name: formattedNames });
227+
}
228+
const links = participants.map((participant) =>
229+
participant.id ? personActivityLink(participant.id, personActivity) : null,
230+
);
231+
const parts = new Intl.ListFormat(i18n.getLocale(), {
232+
style: "long",
233+
type: "unit",
234+
}).formatToParts(participants.map(participantLabel));
235+
const names: (TemplateResult | string)[] = [];
236+
let index = 0;
237+
for (const part of parts) {
238+
if (part.type === "literal") {
239+
names.push(part.value);
240+
continue;
241+
}
242+
names.push(
243+
renderPersonName(part.value, links[index] ?? null, "session-hovercard__participant-name"),
244+
);
245+
index += 1;
246+
}
247+
return html`${prefix}${names}${suffix}`;
248+
}
249+
250+
function renderSessionContext({
251+
row,
252+
selfUserId,
253+
avatarAuth,
254+
personActivity,
255+
}: SessionHovercardInput) {
166256
const creator = row?.createdActor;
167257
const creatorLabel = creator?.label?.trim() || creator?.id?.trim();
168258
const creatorInitials = creator ? sessionOwnerInitials(creator) : "";
@@ -187,9 +277,7 @@ function renderSessionContext(
187277
return true;
188278
});
189279
const visibleParticipants = participants.slice(0, MAX_VISIBLE_PARTICIPANTS);
190-
const participantNames = visibleParticipants.map(
191-
(participant) => participant.label || participant.id || "",
192-
);
280+
const participantNames = visibleParticipants.map(participantLabel);
193281
const formattedParticipantNames = new Intl.ListFormat(i18n.getLocale(), {
194282
style: "long",
195283
type: "unit",
@@ -213,40 +301,53 @@ function renderSessionContext(
213301
if (row?.channelAvatarUrl) {
214302
ensureChannelAvatarElement();
215303
}
304+
const creatorId = creator?.id;
305+
const creatorActivity = creatorId ? personActivityLink(creatorId, personActivity) : null;
306+
const creatorAvatar = row?.channelAvatarUrl
307+
? html`<openclaw-channel-avatar
308+
class="session-hovercard__creator-avatar"
309+
.routeUrl=${row.channelAvatarUrl}
310+
.authTokens=${avatarAuth?.authTokens ?? []}
311+
.authReady=${avatarAuth?.authReady ?? false}
312+
.fallback=${avatarFallback}
313+
aria-hidden="true"
314+
></openclaw-channel-avatar>`
315+
: creatorId
316+
? html`<openclaw-viewer-avatar
317+
class="session-hovercard__creator-avatar"
318+
.user=${{
319+
id: creatorId,
320+
name: creator?.label,
321+
avatarUrl: creator?.avatarUrl,
322+
watchedSessions: [],
323+
}}
324+
.markAsViewer=${false}
325+
variant="session"
326+
aria-hidden="true"
327+
></openclaw-viewer-avatar>`
328+
: html`<span class="session-hovercard__context-icon" aria-hidden="true"
329+
>${icons.users}</span
330+
>`;
216331
return html`<div class="session-hovercard__context">
217332
${creatorLabel || visibleParticipants.length > 0
218333
? html`<div
219334
class="session-hovercard__context-row session-hovercard__identity-row"
220335
aria-label=${[creatorLabel, participantSummary].filter(Boolean).join(", ")}
221336
>
222-
${row?.channelAvatarUrl
223-
? html`<openclaw-channel-avatar
224-
class="session-hovercard__creator-avatar"
225-
.routeUrl=${row.channelAvatarUrl}
226-
.authTokens=${avatarAuth?.authTokens ?? []}
227-
.authReady=${avatarAuth?.authReady ?? false}
228-
.fallback=${avatarFallback}
337+
${creatorActivity
338+
? // Decorative twin of the name link: the name below carries the accessible target.
339+
html`<a
340+
class="session-hovercard__identity-avatar-link"
341+
href=${creatorActivity.href}
342+
tabindex="-1"
229343
aria-hidden="true"
230-
></openclaw-channel-avatar>`
231-
: creator?.id
232-
? html`<openclaw-viewer-avatar
233-
class="session-hovercard__creator-avatar"
234-
.user=${{
235-
id: creator.id,
236-
name: creator.label,
237-
avatarUrl: creator.avatarUrl,
238-
watchedSessions: [],
239-
}}
240-
.markAsViewer=${false}
241-
variant="session"
242-
aria-hidden="true"
243-
></openclaw-viewer-avatar>`
244-
: html`<span class="session-hovercard__context-icon" aria-hidden="true"
245-
>${icons.users}</span
246-
>`}
344+
@click=${creatorActivity.open}
345+
>${creatorAvatar}</a
346+
>`
347+
: creatorAvatar}
247348
<span class="session-hovercard__identity-copy">
248349
${creatorLabel
249-
? html`<span class="session-hovercard__identity-name">${creatorLabel}</span>`
350+
? renderPersonName(creatorLabel, creatorActivity, "session-hovercard__identity-name")
250351
: nothing}
251352
${creatorLabel && visibleParticipants.length > 0
252353
? html`<span class="session-hovercard__identity-separator" aria-hidden="true"
@@ -256,9 +357,11 @@ function renderSessionContext(
256357
${visibleParticipants.length > 0
257358
? html`<span class="session-hovercard__participants">
258359
<span class="session-hovercard__participant"
259-
>${t("sessionsView.withParticipant", {
260-
name: formattedParticipantNames,
261-
})}</span
360+
>${renderParticipantNames(
361+
visibleParticipants,
362+
formattedParticipantNames,
363+
personActivity,
364+
)}</span
262365
>
263366
${hiddenParticipantCount > 0
264367
? html`<span class="session-hovercard__participants-more"
@@ -386,13 +489,7 @@ function renderPullRequestDetails(snapshot: ControlUiSessionPullRequestSnapshot
386489
`;
387490
}
388491

389-
export function renderSessionHovercard(input: {
390-
row?: SidebarSessionHovercardRow;
391-
selfUserId?: string;
392-
avatarAuth?: SessionHovercardAvatarAuth;
393-
pullRequests?: ControlUiSessionPullRequestSnapshot;
394-
progressCard?: ProgressCard | null;
395-
}) {
492+
export function renderSessionHovercard(input: SessionHovercardInput) {
396493
const hasPullRequestDetails = Boolean(
397494
input.pullRequests && (input.pullRequests.pullRequests.length > 0 || input.pullRequests.branch),
398495
);
@@ -421,7 +518,7 @@ export function renderSessionHovercard(input: {
421518
: nothing}
422519
${hasContext
423520
? html`<section class="session-hovercard__section session-hovercard__section--metadata">
424-
${renderSessionContext(input.row, input.selfUserId, input.avatarAuth)}
521+
${renderSessionContext(input)}
425522
</section>`
426523
: nothing}
427524
${hasPullRequestDetails

0 commit comments

Comments
 (0)