Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions .changeset/36346-initials-one-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'@object-ui/types': patch
'@object-ui/fields': patch
'@object-ui/plugin-kanban': patch
'@object-ui/plugin-detail': patch
'@object-ui/auth': patch
'@object-ui/collaboration': patch
---

fix(ui): the kanban card owner, history timeline, user menu and presence stack draw letters-only initials

Clause-②: yes (widening)
Metadata-protocol: none

A person whose display name carries punctuation, such as `Alice (Sales)`, now shows `AS` on the kanban card owner's avatar, the history timeline, the user menu and the presence stack, where those four faces drew `A(`. They now use the same rule as the people cell and the avatar widget: initials are made of letters only, a single-word name gives its first two letters (`Admin` → `AD`), a name of three or more words gives its first and last words' first letters (`John Michael Doe` → `JD`), a single CJK word gives its last one or two characters, and a name with no letter gives `?`. The user menu still falls back to the email's first character when there is no name.

The rule, `getPersonInitials`, is now exported by `@object-ui/types`, the lowest package all of these faces can reach; `@object-ui/fields` re-exports the same function, so its `getPersonInitials` export is unchanged. `@object-ui/auth` now depends on `@object-ui/types`.
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* objectstack#36346 — every face that draws a person's initials draws them
* letters-only, by the one `getPersonInitials` rule: a display name such as
* "Alice (Sales)" gives "AS" on each of them, never "A(".
*
* ## Why this file lives in `app-shell`
*
* The faces sit in four packages — the kanban card owner in `plugin-kanban`,
* the history timeline in `plugin-detail`, the user menu's `getUserInitials`
* in `auth` and the presence stack in `collaboration` — and none depends on all
* the others. `app-shell` depends on all four, so the REAL faces are mounted
* here side by side with no new dependency edge. The rule's own cases (CJK,
* single words, no letter at all) are pinned beside it in `@object-ui/fields`.
*/
import React from 'react';
import { describe, it, expect, vi, afterEach } from 'vitest';
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ValueDataSource } from '@object-ui/core';
import { SchemaRendererProvider } from '@object-ui/react';
import { ObjectKanban } from '@object-ui/plugin-kanban';
import { HistoryTimeline } from '@object-ui/plugin-detail';
import { getUserInitials } from '@object-ui/auth';
import { PresenceAvatars } from '@object-ui/collaboration';
// Loads the board's lazy chunk at module scope (AGENTS.md, test discipline).
import '../../../plugin-kanban/src/KanbanImpl';

const NAME = 'Alice (Sales)';
const INITIALS = 'AS';

afterEach(cleanup);

describe('every initials face draws letters only for "Alice (Sales)" (objectstack#36346)', () => {
it('the kanban card owner', async () => {
const def = {
name: 'deal',
label: 'Deal',
fields: {
name: { type: 'text', label: 'Name' },
stage: { type: 'select', label: 'Stage', options: [{ value: 'open', label: 'Open' }] },
owner_id: { type: 'lookup', label: 'Owner', reference: 'sys_user' },
},
};
const store = new ValueDataSource<Record<string, unknown>>({
items: [{ id: 'd1', name: 'Deal one', stage: 'open', owner_id: { id: 'u1', name: NAME } }],
});
const adapter = {
find: vi.fn(async (object: string, params: any) => store.find(object, params)),
findOne: vi.fn(),
create: vi.fn(),
update: vi.fn(),
delete: vi.fn(),
getObjectSchema: vi.fn(async () => def),
} as any;
render(
<SchemaRendererProvider dataSource={adapter}>
<ObjectKanban
schema={{ type: 'object-kanban', objectName: 'deal', groupBy: 'stage' } as any}
dataSource={adapter}
ownerField="owner_id"
/>
</SchemaRendererProvider>,
);
await waitFor(() => expect(document.querySelector('[data-kanban-card-owner]')).not.toBeNull());
const avatar = document.querySelector('[data-kanban-card-owner]') as HTMLElement;
expect(avatar).toHaveAttribute('aria-label', NAME);
expect(avatar).toHaveTextContent(INITIALS);
});

it('the history timeline', () => {
render(
<HistoryTimeline
entries={[{ id: 'h1', action: 'update', user_id: 'u1', user_name: NAME, created_at: '2026-01-01T00:00:00Z' }]}
/>,
);
expect(screen.getByText(INITIALS)).toBeInTheDocument();
});

it('the user menu (`getUserInitials`, drawn by UserMenu, AccountMenu and the profile page)', () => {
expect(getUserInitials({ name: NAME, email: 'alice@example.com' })).toBe(INITIALS);
});

it('the presence stack', () => {
const { container } = render(
<PresenceAvatars
users={[{ userId: 'u1', userName: NAME, color: '#000', status: 'active', lastActivity: '2026-01-01T00:00:00Z' }]}
/>,
);
expect(within(container).getByText(INITIALS)).toBeInTheDocument();
});
});
1 change: 1 addition & 0 deletions ui/packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"react": "^19.0.0"
},
"dependencies": {
"@object-ui/types": "workspace:*",
"@objectstack/spec": "workspace:^",
"better-auth": "1.7.12"
},
Expand Down
8 changes: 4 additions & 4 deletions ui/packages/auth/src/__tests__/types.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ describe('getUserInitials', () => {
expect(getUserInitials({ name: 'John Doe', email: 'j@test.com' })).toBe('JD');
});

it('returns single initial for single-word name', () => {
expect(getUserInitials({ name: 'Admin', email: 'a@test.com' })).toBe('A');
it('returns the first two letters of a single-word name (the shared getPersonInitials rule)', () => {
expect(getUserInitials({ name: 'Admin', email: 'a@test.com' })).toBe('AD');
});

it('returns at most 2 characters for long names', () => {
expect(getUserInitials({ name: 'John Michael Doe', email: 'j@test.com' })).toBe('JM');
it('returns the first and last words\' initials for long names', () => {
expect(getUserInitials({ name: 'John Michael Doe', email: 'j@test.com' })).toBe('JD');
});

it('returns first letter of email when name is empty', () => {
Expand Down
15 changes: 5 additions & 10 deletions ui/packages/auth/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import type React from 'react';
import { getPersonInitials } from '@object-ui/types';
import type {
AuthUser as SpecAuthUser,
DelegableScope,
Expand Down Expand Up @@ -83,19 +84,13 @@ export interface AuthUser extends SpecAuthUser {
}

/**
* Get user initials from their name or email.
* Returns up to 2 uppercase characters.
* Get user initials from their name or email: the name by the shared
* letters-only rule (`getPersonInitials`, objectstack#36346), else the email's
* first character. Returns up to 2 characters.
*/
export function getUserInitials(user: Pick<AuthUser, 'name' | 'email'> | null | undefined): string {
if (!user) return '?';
if (user.name) {
return user.name
.split(' ')
.map((n) => n[0])
.join('')
.toUpperCase()
.slice(0, 2);
}
if (user.name) return getPersonInitials(user.name);
return user.email?.[0]?.toUpperCase() ?? '?';
}

Expand Down
12 changes: 2 additions & 10 deletions ui/packages/collaboration/src/PresenceAvatars.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

import React, { useMemo } from 'react';
import { getPersonInitials } from '@object-ui/types';
import type { PresenceUser } from './usePresence.js';
import {
useCollaborationTranslation,
Expand Down Expand Up @@ -73,15 +74,6 @@ function statusLabel(status: string, t: CollaborationTranslate): string {
return key ? t(key) : status;
}

function getInitials(name: string): string {
return name
.split(' ')
.map(part => part[0])
.join('')
.toUpperCase()
.slice(0, 2);
}

/**
* Avatar stack component showing active users with overflow indicator.
*
Expand Down Expand Up @@ -195,7 +187,7 @@ export function PresenceAvatars({
alt: user.userName,
style: { width: '100%', height: '100%', objectFit: 'cover' as const },
})
: getInitials(user.userName),
: getPersonInitials(user.userName),
showStatus && React.createElement('span', {
style: {
...statusDotStyle,
Expand Down
29 changes: 5 additions & 24 deletions ui/packages/fields/src/widgets/personDisplay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,31 +49,12 @@ export function getPersonName(record: any, nameField: string | readonly string[]
}

/**
* Up-to-2-char initials for the avatar fallback, made of letters only
* (objectstack#36046): brackets, punctuation, digits and spaces are skipped,
* so a display name such as "Alice (Sales)" gives "AS", never "A(".
* - "John Doe" → "JD"; "John" → "JO"; "A." → "A" (one letter when one is all there is)
* - CJK single word → trailing 1–2 chars (given name): "张三" → "张三", "王小明" → "小明"
* - no letter at all → "?"
* The one avatar-initials rule, letters only (objectstack#36046). It lives in
* `@object-ui/types`, the lowest package every face that draws initials can
* reach (objectstack#36346); re-exported here so field renderers keep reading
* it from beside the other person helpers.
*/
export function getPersonInitials(name: string): string {
// A word is a run of letters (with their combining marks); everything else separates words.
const words = (name || '').split(/[^\p{L}\p{M}]+/u).filter(Boolean);
if (words.length === 0) return '?';
if (words.length >= 2) {
return (firstLetter(words[0]) + firstLetter(words[words.length - 1])).toUpperCase();
}
const letters = Array.from(words[0]).filter((ch) => /\p{L}/u.test(ch));
if (/[㐀-鿿]/.test(words[0])) {
return letters.length <= 2 ? letters.join('') : letters.slice(-2).join('');
}
return letters.slice(0, 2).join('').toUpperCase();
}

/** A word's first letter, a whole code point (never half a surrogate pair). */
function firstLetter(word: string): string {
return Array.from(word).find((ch) => /\p{L}/u.test(ch)) ?? '';
}
export { getPersonInitials } from '@object-ui/types';

/** Secondary line: resolve each field path, drop empties, join with " · ". */
export function getPersonSubtitle(record: any, fields?: string[]): string {
Expand Down
16 changes: 2 additions & 14 deletions ui/packages/plugin-detail/src/HistoryTimeline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import {
} from '@object-ui/components';
import { useDisplayLocale, useSafeTranslate } from '@object-ui/i18n';
import { useSafeFieldLabel } from '@object-ui/react';
import { getPersonInitials } from '@object-ui/fields';
import { Cog } from 'lucide-react';
import { hasCellValue } from './emptiness';

Expand Down Expand Up @@ -163,19 +164,6 @@ function formatRelative(value: HistoryEntry['created_at'], locale: string): stri
return formatAbsolute(value, locale);
}

function initialsFromName(name?: string | null): string {
if (!name) return '?';
const parts = name
.trim()
.split(/\s+/)
.filter(Boolean)
.slice(0, 2);
if (parts.length === 0) return '?';
return parts
.map((p) => p.charAt(0).toUpperCase())
.join('');
}

/**
* An audit value as the timeline shows it, or the `'—'` that means "nothing".
*
Expand Down Expand Up @@ -276,7 +264,7 @@ export function HistoryTimeline({
data-testid="history-system-actor-glyph"
/>
) : (
initialsFromName(entry.user_name)
getPersonInitials(entry.user_name ?? '')
)}
</AvatarFallback>
</Avatar>
Expand Down
16 changes: 6 additions & 10 deletions ui/packages/plugin-kanban/src/KanbanCardOwner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,9 @@ export function resolveCardOwner(
return image ? { name, image } : { name };
}

/** Up to two initials of a name, for the avatar with no picture. */
export function ownerInitials(name: string): string {
return name
.split(/\s+/)
.filter(Boolean)
.map((part) => part[0])
.join('')
.toUpperCase()
.slice(0, 2);
}
/**
* Up to two initials of a name, for the avatar with no picture: the one
* letters-only rule every initials face shares (objectstack#36346), so
* "Alice (Sales)" gives "AS", never "A(".
*/
export { getPersonInitials as ownerInitials } from '@object-ui/fields';
6 changes: 6 additions & 0 deletions ui/packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1645,3 +1645,9 @@ export {
// `resetInflightGetsForTesting` is test-only and stays off the barrel
// (objectui#13453); tests import it from `http-inflight` directly.
} from './http-inflight.js';

// The one avatar-initials rule (objectstack#36346). Same argument for the same
// home: its callers — the field renderers, the kanban card owner, the history
// timeline, the user menu in `@object-ui/auth` and the presence stack — have no
// package in common lower than this one.
export { getPersonInitials } from './person-initials.js';
47 changes: 47 additions & 0 deletions ui/packages/types/src/person-initials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* ObjectUI
* Copyright (c) 2024-present ObjectStack Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* The ONE rule for a person's avatar initials. Every face that draws a person
* with no picture uses it — the people cell and avatar widget (through
* `@object-ui/fields`), the kanban card owner, the history timeline, the user
* menu (`@object-ui/auth`) and the presence stack (`@object-ui/collaboration`).
*
* It lives in this package because it is the lowest one all of those callers
* can reach: `@object-ui/auth` depends on no other `@object-ui` package, and
* the field renderers are a tier above it, so the rule cannot live in
* `@object-ui/fields` without dragging that tier into the auth client.
* `@object-ui/fields` re-exports it unchanged.
*/

/**
* Up-to-2-char initials for the avatar fallback, made of letters only
* (objectstack#36046): brackets, punctuation, digits and spaces are skipped,
* so a display name such as "Alice (Sales)" gives "AS", never "A(".
* - "John Doe" → "JD"; "John" → "JO"; "A." → "A" (one letter when one is all there is)
* - CJK single word → trailing 1–2 chars (given name): "张三" → "张三", "王小明" → "小明"
* - no letter at all → "?"
*/
export function getPersonInitials(name: string): string {
// A word is a run of letters (with their combining marks); everything else separates words.
const words = (name || '').split(/[^\p{L}\p{M}]+/u).filter(Boolean);
if (words.length === 0) return '?';
if (words.length >= 2) {
return (firstLetter(words[0]) + firstLetter(words[words.length - 1])).toUpperCase();
}
const letters = Array.from(words[0]).filter((ch) => /\p{L}/u.test(ch));
if (/[㐀-鿿]/.test(words[0])) {
return letters.length <= 2 ? letters.join('') : letters.slice(-2).join('');
}
return letters.slice(0, 2).join('').toUpperCase();
}

/** A word's first letter, a whole code point (never half a surrogate pair). */
function firstLetter(word: string): string {
return Array.from(word).find((ch) => /\p{L}/u.test(ch)) ?? '';
}
Loading