mirror of
https://github.com/stablyai/orca.git
synced 2026-11-16 02:47:34 +00:00
fix(cloud-api): teammates show as a display name only, never a raw id; audit keeps it in a tooltip
This commit is contained in:
@@ -274,7 +274,7 @@ function ActorLabel({
|
||||
return mine ? (
|
||||
<>{sentence}</>
|
||||
) : (
|
||||
<PersonSentence sentence={sentence} name={entry.actor.userName} id={personId} />
|
||||
<PersonSentence sentence={sentence} name={entry.actor.userName} id={personId} idInTooltip />
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
// @vitest-environment happy-dom
|
||||
import { cleanup, render } from '@testing-library/react'
|
||||
import { afterEach, expect, it } from 'vitest'
|
||||
import { PersonName, PersonSentence } from './PersonName'
|
||||
|
||||
afterEach(cleanup)
|
||||
|
||||
it('shows the display name only, never the raw id inline', () => {
|
||||
const { container } = render(<PersonName name="Grace Hopper" id="u_grace" />)
|
||||
expect(container.textContent).toBe('Grace Hopper')
|
||||
expect(container.querySelector('[title]')).toBeNull()
|
||||
})
|
||||
|
||||
it('says "Former member" when nobody can name the person', () => {
|
||||
const { container } = render(<PersonName name=" " id="u_7f3k" />)
|
||||
expect(container.textContent).toBe('Former member')
|
||||
expect(container.innerHTML).not.toContain('u_7f3k')
|
||||
})
|
||||
|
||||
it('keeps the id one hover away in the audit log only', () => {
|
||||
const { container } = render(
|
||||
<PersonSentence sentence="<person></person> via API key" name={null} id="u_7f3k" idInTooltip />
|
||||
)
|
||||
expect(container.textContent).toBe('Former member via API key')
|
||||
expect(container.querySelector('[title]')?.getAttribute('title')).toBe('u_7f3k')
|
||||
})
|
||||
@@ -1,32 +1,43 @@
|
||||
import { Trans } from 'react-i18next'
|
||||
import { i18n } from '@/i18n/i18n'
|
||||
import { i18n, translate } from '@/i18n/i18n'
|
||||
import { useAppStore } from '@/store'
|
||||
import { useOrgRoster } from '../../billing/team/use-org-roster'
|
||||
|
||||
/** The name the control plane sent, else the team roster's (the directory Home uses), else null. */
|
||||
function useMemberName(name: string | null | undefined, id: string): string | null {
|
||||
const orgId = useAppStore((s) => s.orcaProfileAuthStatus?.cloud?.activeOrgId ?? null)
|
||||
const known = name?.trim() || null
|
||||
// Only read the shared roster when the server could not name this person.
|
||||
const roster = useOrgRoster(known ? null : orgId)
|
||||
if (known) {
|
||||
return known
|
||||
}
|
||||
if (roster.result?.status === 'ok') {
|
||||
const member = roster.result.roster.members.find((m) => m.userId === id)
|
||||
return member?.displayName?.trim() || member?.email || null
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* A teammate as the control plane knows them: "Ada Lovelace · u_ada" (name, then the id as
|
||||
* secondary text), or the id alone when no name is known. Never a vague "a teammate".
|
||||
* A teammate as a display name only, never a raw id inline; "Former member" when nobody can
|
||||
* name them. `idInTooltip` (audit log only) keeps the id one hover away for admins investigating.
|
||||
*/
|
||||
export function PersonName({
|
||||
name,
|
||||
id
|
||||
id,
|
||||
idInTooltip = false
|
||||
}: {
|
||||
name: string | null | undefined
|
||||
id: string
|
||||
idInTooltip?: boolean
|
||||
}): React.JSX.Element {
|
||||
const display = name?.trim()
|
||||
if (!display) {
|
||||
return (
|
||||
<span className="font-mono text-[0.95em]" title={id}>
|
||||
{id}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
const display =
|
||||
useMemberName(name, id) ??
|
||||
translate('auto.components.settings.cloudApi.formerMember', 'Former member')
|
||||
return (
|
||||
<span title={`${display} · ${id}`}>
|
||||
<span className="text-foreground">{display}</span>
|
||||
<span className="text-muted-foreground">
|
||||
{' · '}
|
||||
<span className="font-mono text-[0.95em]">{id}</span>
|
||||
</span>
|
||||
<span className="text-foreground" title={idInTooltip ? id : undefined}>
|
||||
{display}
|
||||
</span>
|
||||
)
|
||||
}
|
||||
@@ -38,17 +49,19 @@ export function PersonName({
|
||||
export function PersonSentence({
|
||||
sentence,
|
||||
name,
|
||||
id
|
||||
id,
|
||||
idInTooltip
|
||||
}: {
|
||||
sentence: string
|
||||
name: string | null | undefined
|
||||
id: string
|
||||
idInTooltip?: boolean
|
||||
}): React.JSX.Element {
|
||||
return (
|
||||
<Trans
|
||||
i18n={i18n}
|
||||
defaults={sentence}
|
||||
components={{ person: <PersonName name={name} id={id} /> }}
|
||||
components={{ person: <PersonName name={name} id={id} idInTooltip={idInTooltip} /> }}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -14405,6 +14405,7 @@
|
||||
"description_other": "Starts waking a sleeping sandbox when you point at its workspace or come back to Orca, so it's ready sooner. If you don't open it, it goes back to sleep after {{count}} minutes idle. Early wakes count toward your sandbox hours."
|
||||
},
|
||||
"cloudApi": {
|
||||
"formerMember": "Former member",
|
||||
"keys": {
|
||||
"createdMine": "Created {{time}}",
|
||||
"createdByPerson": "Created by <person></person> {{time}}",
|
||||
|
||||
Reference in New Issue
Block a user