Merge pull request #372 from nwparker/cloud/teammate-avatars

feat(teammates): profile pictures on Team rows and teammate profiles
This commit is contained in:
Neil
2026-11-10 21:51:44 -08:00
committed by GitHub
9 changed files with 129 additions and 8 deletions
@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest'
import { normalizeRoster } from './profile-cloud-org-members-client'
describe('normalizeRoster', () => {
it('keeps https profile pictures and drops anything else', () => {
const roster = normalizeRoster({
viewerRole: 'member',
canManageMembers: false,
pendingInvites: [],
members: [
{
userId: 'a',
email: 'a@x.dev',
role: 'member',
pictureUrl: 'https://img.propelauth.com/a.png'
},
{ userId: 'b', email: 'b@x.dev', role: 'member', pictureUrl: 'http://x.dev/b.png' },
{ userId: 'c', email: 'c@x.dev', role: 'member', pictureUrl: 'javascript:alert(1)' },
{ userId: 'd', email: 'd@x.dev', role: 'member', pictureUrl: 'file:///etc/passwd' },
{ userId: 'e', email: 'e@x.dev', role: 'member' }
]
})
expect(roster.members.map((m) => m.pictureUrl)).toEqual([
'https://img.propelauth.com/a.png',
undefined,
undefined,
undefined,
undefined
])
expect('pictureUrl' in roster.members[4]!).toBe(false)
})
})
@@ -40,6 +40,19 @@ function normalizeTimestamp(value: unknown): number {
return Date.now()
}
// The renderer loads this image, so only a plain https URL from auth is kept.
function optionalPictureUrl(value: unknown): string | undefined {
if (typeof value !== 'string' || value.length > 2048) {
return undefined
}
try {
const url = new URL(value)
return url.protocol === 'https:' && !url.username && !url.password ? url.toString() : undefined
} catch {
return undefined
}
}
function normalizeMember(value: unknown): OrcaOrgMember | null {
if (!value || typeof value !== 'object') {
return null
@@ -54,6 +67,9 @@ function normalizeMember(value: unknown): OrcaOrgMember | null {
userId: userId ?? null,
email,
displayName: optionalString(record.displayName),
...(optionalPictureUrl(record.pictureUrl)
? { pictureUrl: optionalPictureUrl(record.pictureUrl) }
: {}),
role: normalizeRole(record.role, 'member')
}
}
@@ -74,7 +90,7 @@ function normalizePendingInvite(value: unknown): OrcaOrgPendingInvite | null {
}
}
function normalizeRoster(value: unknown): OrcaOrgMembersRoster {
export function normalizeRoster(value: unknown): OrcaOrgMembersRoster {
if (!value || typeof value !== 'object') {
throw new Error('invalid_orca_org_members_roster')
}
@@ -1,5 +1,33 @@
import { useState } from 'react'
import { cn } from '@/lib/utils'
/**
* A teammate's provider profile picture filling its avatar circle, or null when there is none or it
* failed to load (the caller's initials show instead). No referrer goes to the image host.
*/
export function ProfilePicture({
url,
className
}: {
url: string | undefined
className?: string
}): React.JSX.Element | null {
const [failed, setFailed] = useState<string | null>(null)
if (!url || failed === url) {
return null
}
return (
<img
src={url}
alt=""
referrerPolicy="no-referrer"
draggable={false}
onError={() => setFailed(url)}
className={cn('absolute inset-0 size-full rounded-full object-cover', className)}
/>
)
}
/** "Ada Lovelace" → "AL", "ada@x.io" → "A", "Acme Dev" → "AD". */
export function initialsFor(nameOrEmail: string): string {
const base = nameOrEmail.includes('@') ? (nameOrEmail.split('@')[0] ?? '') : nameOrEmail
@@ -15,21 +43,23 @@ export function initialsFor(nameOrEmail: string): string {
return (first + second).toUpperCase()
}
/** Round person avatar (initials). Pending people get a dashed, hollow look. */
/** Round person avatar (picture, else initials). Pending people get a dashed, hollow look. */
export function PersonAvatar({
name,
pending = false,
pictureUrl,
className
}: {
name: string
pending?: boolean
pictureUrl?: string
className?: string
}): React.JSX.Element {
return (
<span
aria-hidden
className={cn(
'flex size-6 shrink-0 items-center justify-center rounded-full text-[10px] font-medium select-none',
'relative flex size-6 shrink-0 items-center justify-center overflow-hidden rounded-full text-[10px] font-medium select-none',
pending
? 'border border-dashed border-muted-foreground/50 text-muted-foreground'
: 'border border-border bg-secondary text-secondary-foreground',
@@ -37,6 +67,7 @@ export function PersonAvatar({
)}
>
{initialsFor(name)}
{pending ? null : <ProfilePicture url={pictureUrl} />}
</span>
)
}
@@ -259,7 +259,11 @@ export function TeamMemberList(props: TeamMemberListProps): React.JSX.Element {
className="group/row flex min-h-12 flex-col justify-center bg-card px-3 py-2 transition-colors animate-in fade-in-0 duration-200 motion-reduce:animate-none"
>
<div className="flex items-center gap-3">
<PersonAvatar name={name} pending={row.status !== 'active'} />
<PersonAvatar
name={name}
pending={row.status !== 'active'}
pictureUrl={row.kind === 'member' ? row.member.pictureUrl : undefined}
/>
<div className="min-w-0 flex-1">
<p className="flex min-w-0 items-center gap-2 text-sm font-medium">
{profileUserId && props.onOpenProfile ? (
@@ -6,6 +6,10 @@ import { sampleTeam } from '../plan-billing-fixtures'
import { TeamDialogContent } from './TeamDialogHost'
import { TeamPageView, type TeamPageViewProps } from './TeamPageView'
// Fixtures render offline: a self-contained stand-in for a provider profile picture.
const ADA_PICTURE =
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><defs><linearGradient id='g' x1='0' y1='0' x2='1' y2='1'><stop offset='0' stop-color='%23f6c38f'/><stop offset='1' stop-color='%23c0713d'/></linearGradient></defs><rect width='64' height='64' fill='url(%23g)'/><circle cx='32' cy='26' r='12' fill='%23fff3e6'/><rect x='14' y='42' width='36' height='22' rx='11' fill='%23fff3e6'/></svg>"
const NOW = Date.UTC(2026, 10, 18, 15)
const DAY = 86_400_000
const width = 1100
@@ -15,7 +19,13 @@ const roster: OrcaOrgMembersRoster = {
canManageMembers: true,
members: [
{ userId: 'u-neil', email: 'neil@acme.dev', displayName: 'Neil Parker', role: 'owner' },
{ userId: 'u-ada', email: 'ada@acme.dev', displayName: 'Ada Lovelace', role: 'admin' },
{
userId: 'u-ada',
email: 'ada@acme.dev',
displayName: 'Ada Lovelace',
role: 'admin',
pictureUrl: ADA_PICTURE
},
{ userId: 'u-grace', email: 'grace@acme.dev', displayName: 'Grace Hopper', role: 'member' },
{ userId: null, email: 'linus@acme.dev', role: 'member' }
],
@@ -89,6 +89,7 @@ function ProfileBody({ userId }: { userId: string }): React.JSX.Element {
userId={userId}
name={name}
email={member?.email ?? null}
{...(member?.pictureUrl ? { pictureUrl: member.pictureUrl } : {})}
role={member?.role ?? null}
profile={profile}
error={error}
@@ -4,6 +4,9 @@ import { FIXTURE_NOW, workspace } from '../cloud-workspaces/cloud-workspaces.tes
import { TeammateProfileView, type TeammateProfileViewProps } from './TeammateProfileView'
const DAYS = 182
// Fixtures render offline: a self-contained stand-in for a provider profile picture.
const PICTURE =
"data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'><defs><linearGradient id='g' x1='0' y1='0' x2='1' y2='1'><stop offset='0' stop-color='%23f6c38f'/><stop offset='1' stop-color='%23c0713d'/></linearGradient></defs><rect width='64' height='64' fill='url(%23g)'/><circle cx='32' cy='26' r='12' fill='%23fff3e6'/><rect x='14' y='42' width='36' height='22' rx='11' fill='%23fff3e6'/></svg>"
/** A believable work pattern: weekdays busy, weekends quiet, a vacation gap. Deterministic. */
function levels(): number[] {
@@ -87,6 +90,16 @@ export const teammate = defineFixture({
)
})
/** A teammate with a provider profile picture (falls back to initials if it fails to load). */
export const withPicture = defineFixture({
width: 600,
render: () => (
<Frame>
<TeammateProfileView {...base} pictureUrl={PICTURE} />
</Frame>
)
})
/** Your own profile: amounts in the hover caption, private workspaces included, no Poke. */
export const self = defineFixture({
width: 600,
@@ -10,6 +10,7 @@ import { cn } from '@/lib/utils'
import type { CloudWorkspace } from '../../../../shared/cloud-workspaces/cloud-workspaces-wire'
import type { OrcaOrgRole } from '../../../../shared/orca-profiles'
import type { TeammateProfile } from '../../../../shared/cloud-workspaces/team-presence-wire'
import { ProfilePicture } from '../billing/team/TeamAvatar'
import { roleLabel } from '../billing/team/team-roles'
import { dotState, statusLabel } from '../cloud-workspaces/CloudWorkspaceRow'
import {
@@ -33,6 +34,8 @@ export type TeammateProfileViewProps = {
/** Roster name, else the control plane's, else a short id. */
name: string
email: string | null
/** Profile picture from the roster (https only); initials when absent or it fails to load. */
pictureUrl?: string
role: OrcaOrgRole | null
profile: TeammateProfile | null
/** Set when the profile couldn't load; the header still shows from the roster. */
@@ -46,7 +49,15 @@ export type TeammateProfileViewProps = {
onTurnOnPokes: () => void
}
function LargeAvatar({ userId, name }: { userId: string; name: string }): React.JSX.Element {
function LargeAvatar({
userId,
name,
pictureUrl
}: {
userId: string
name: string
pictureUrl: string | undefined
}): React.JSX.Element {
// Same per-member hue as the small avatars on workspace rows, so a teammate keeps one color.
const hueStyle: React.CSSProperties & { '--avatar-hue': string } = {
'--avatar-hue': String(memberHue(userId))
@@ -56,12 +67,13 @@ function LargeAvatar({ userId, name }: { userId: string; name: string }): React.
aria-hidden
style={hueStyle}
className={cn(
'inline-flex size-12 shrink-0 select-none items-center justify-center rounded-full text-base font-medium',
'relative inline-flex size-12 shrink-0 select-none items-center justify-center overflow-hidden rounded-full text-base font-medium',
'bg-[hsl(var(--avatar-hue)_45%_88%)] text-[hsl(var(--avatar-hue)_45%_28%)]',
'dark:bg-[hsl(var(--avatar-hue)_30%_26%)] dark:text-[hsl(var(--avatar-hue)_55%_82%)]'
)}
>
{initials(name)}
<ProfilePicture url={pictureUrl} />
</span>
)
}
@@ -142,7 +154,7 @@ export function TeammateProfileView(props: TeammateProfileViewProps): React.JSX.
return (
<div className="flex flex-col gap-6" aria-busy={loading || undefined}>
<header className="flex items-center gap-4 pr-8">
<LargeAvatar userId={props.userId} name={props.name} />
<LargeAvatar userId={props.userId} name={props.name} pictureUrl={props.pictureUrl} />
<div className="min-w-0 flex-1">
<h2
className="flex min-w-0 items-center gap-2 text-base font-semibold outline-none"
+2
View File
@@ -252,6 +252,8 @@ export type OrcaOrgMember = {
userId: string | null
email: string
displayName?: string
/** Profile picture from the identity provider (https only); avatars fall back to initials. */
pictureUrl?: string
role: OrcaOrgRole
}