From 5e1d0c0740cd89aa8b949ac36d275b17d4b32155 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 12:02:26 +0000 Subject: [PATCH 1/3] fix(ui): four initials faces draw letters-only initials by the one shared rule Move getPersonInitials to @object-ui/types (the lowest package the user menu in @object-ui/auth can reach); @object-ui/fields re-exports it. The kanban card owner and history timeline call it through @object-ui/fields, the user menu and presence stack through @object-ui/types. Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude --- pnpm-lock.yaml | 3 ++ ui/packages/auth/package.json | 1 + ui/packages/auth/src/types.ts | 15 ++---- .../collaboration/src/PresenceAvatars.tsx | 12 +---- .../fields/src/widgets/personDisplay.ts | 29 ++---------- .../plugin-detail/src/HistoryTimeline.tsx | 16 +------ .../plugin-kanban/src/KanbanCardOwner.ts | 11 ----- ui/packages/plugin-kanban/src/KanbanImpl.tsx | 5 +- ui/packages/types/src/index.ts | 6 +++ ui/packages/types/src/person-initials.ts | 47 +++++++++++++++++++ 10 files changed, 74 insertions(+), 71 deletions(-) create mode 100644 ui/packages/types/src/person-initials.ts diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a8be9528981..c6d8c5e6cbd 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -4258,6 +4258,9 @@ importers: ui/packages/auth: dependencies: + '@object-ui/types': + specifier: workspace:* + version: link:../types '@objectstack/spec': specifier: workspace:^ version: link:../../../packages/spec diff --git a/ui/packages/auth/package.json b/ui/packages/auth/package.json index 68ada6975b3..8a3026bf6df 100644 --- a/ui/packages/auth/package.json +++ b/ui/packages/auth/package.json @@ -38,6 +38,7 @@ "react": "^19.0.0" }, "dependencies": { + "@object-ui/types": "workspace:*", "@objectstack/spec": "workspace:^", "better-auth": "1.7.12" }, diff --git a/ui/packages/auth/src/types.ts b/ui/packages/auth/src/types.ts index 672c2242306..a4921a70f15 100644 --- a/ui/packages/auth/src/types.ts +++ b/ui/packages/auth/src/types.ts @@ -7,6 +7,7 @@ */ import type React from 'react'; +import { getPersonInitials } from '@object-ui/types'; import type { AuthUser as SpecAuthUser, DelegableScope, @@ -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 | 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() ?? '?'; } diff --git a/ui/packages/collaboration/src/PresenceAvatars.tsx b/ui/packages/collaboration/src/PresenceAvatars.tsx index 0adbca3673a..9c21367e7b6 100644 --- a/ui/packages/collaboration/src/PresenceAvatars.tsx +++ b/ui/packages/collaboration/src/PresenceAvatars.tsx @@ -7,6 +7,7 @@ */ import React, { useMemo } from 'react'; +import { getPersonInitials } from '@object-ui/types'; import type { PresenceUser } from './usePresence.js'; import { useCollaborationTranslation, @@ -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. * @@ -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, diff --git a/ui/packages/fields/src/widgets/personDisplay.ts b/ui/packages/fields/src/widgets/personDisplay.ts index acad1f54f34..24b04ea2619 100644 --- a/ui/packages/fields/src/widgets/personDisplay.ts +++ b/ui/packages/fields/src/widgets/personDisplay.ts @@ -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 { diff --git a/ui/packages/plugin-detail/src/HistoryTimeline.tsx b/ui/packages/plugin-detail/src/HistoryTimeline.tsx index 7add39f4198..c3990f6df2e 100644 --- a/ui/packages/plugin-detail/src/HistoryTimeline.tsx +++ b/ui/packages/plugin-detail/src/HistoryTimeline.tsx @@ -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'; @@ -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". * @@ -276,7 +264,7 @@ export function HistoryTimeline({ data-testid="history-system-actor-glyph" /> ) : ( - initialsFromName(entry.user_name) + getPersonInitials(entry.user_name ?? '') )} diff --git a/ui/packages/plugin-kanban/src/KanbanCardOwner.ts b/ui/packages/plugin-kanban/src/KanbanCardOwner.ts index 356c4e54c2e..d6c7122ef20 100644 --- a/ui/packages/plugin-kanban/src/KanbanCardOwner.ts +++ b/ui/packages/plugin-kanban/src/KanbanCardOwner.ts @@ -47,14 +47,3 @@ export function resolveCardOwner( const image = typeof person.image === 'string' && person.image ? person.image : undefined; 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); -} diff --git a/ui/packages/plugin-kanban/src/KanbanImpl.tsx b/ui/packages/plugin-kanban/src/KanbanImpl.tsx index a89170ac2fb..d69564b5326 100644 --- a/ui/packages/plugin-kanban/src/KanbanImpl.tsx +++ b/ui/packages/plugin-kanban/src/KanbanImpl.tsx @@ -34,7 +34,8 @@ import { Plus, Sigma } from "lucide-react" import { useKanbanRecordsSettled } from './KanbanRecordsSettled' import { useKanbanColumnSummary, sumLaneField } from './KanbanColumnSummary' import { laneCount, useKanbanLanePaging } from './KanbanLanePaging' -import { ownerInitials, type KanbanCardOwner } from './KanbanCardOwner' +import { getPersonInitials } from '@object-ui/fields' +import type { KanbanCardOwner } from './KanbanCardOwner' import { createKanbanDndAnnouncer } from './kanbanDndAnnouncements' // Utility function to merge class names (inline to avoid external dependency) @@ -419,7 +420,7 @@ function SortableCard({ card, onCardClick, conditionalFormatting, objectFields } {owner.image && } - {ownerInitials(owner.name)} + {getPersonInitials(owner.name)} diff --git a/ui/packages/types/src/index.ts b/ui/packages/types/src/index.ts index 26548aa0c84..c6c3a2207ad 100644 --- a/ui/packages/types/src/index.ts +++ b/ui/packages/types/src/index.ts @@ -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'; diff --git a/ui/packages/types/src/person-initials.ts b/ui/packages/types/src/person-initials.ts new file mode 100644 index 00000000000..0eb3e2f40c0 --- /dev/null +++ b/ui/packages/types/src/person-initials.ts @@ -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)) ?? ''; +} From 96825e61b339dbe7504729094eb760a7ff5ecda6 Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 12:32:44 +0000 Subject: [PATCH 2/3] test(ui): one family pin across the four initials faces; auth tests follow the shared rule; changeset Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude --- .changeset/36346-initials-one-rule.md | 17 ++++ .../personInitialsFamily-36346.test.tsx | 99 +++++++++++++++++++ ui/packages/auth/src/__tests__/types.test.ts | 8 +- 3 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 .changeset/36346-initials-one-rule.md create mode 100644 ui/packages/app-shell/src/__tests__/personInitialsFamily-36346.test.tsx diff --git a/.changeset/36346-initials-one-rule.md b/.changeset/36346-initials-one-rule.md new file mode 100644 index 00000000000..fec1ac20437 --- /dev/null +++ b/.changeset/36346-initials-one-rule.md @@ -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`. diff --git a/ui/packages/app-shell/src/__tests__/personInitialsFamily-36346.test.tsx b/ui/packages/app-shell/src/__tests__/personInitialsFamily-36346.test.tsx new file mode 100644 index 00000000000..12cdc2c3c57 --- /dev/null +++ b/ui/packages/app-shell/src/__tests__/personInitialsFamily-36346.test.tsx @@ -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>({ + 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( + + + , + ); + 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( + , + ); + 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( + , + ); + expect(within(container).getByText(INITIALS)).toBeInTheDocument(); + }); +}); diff --git a/ui/packages/auth/src/__tests__/types.test.ts b/ui/packages/auth/src/__tests__/types.test.ts index bb83f4600f7..8dbf798c6b9 100644 --- a/ui/packages/auth/src/__tests__/types.test.ts +++ b/ui/packages/auth/src/__tests__/types.test.ts @@ -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', () => { From 998bb5fdd189bd86825c958cdef4b6659b7a025e Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 22 Nov 2026 13:01:56 +0000 Subject: [PATCH 3/3] fix(ui): keep the kanban board file untouched; ownerInitials delegates to the shared rule Claude-Session: https://claude.ai/code/session_01QsR2jUc3qp6bHKSWijbjds Co-authored-by: Claude --- ui/packages/plugin-kanban/src/KanbanCardOwner.ts | 7 +++++++ ui/packages/plugin-kanban/src/KanbanImpl.tsx | 5 ++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/packages/plugin-kanban/src/KanbanCardOwner.ts b/ui/packages/plugin-kanban/src/KanbanCardOwner.ts index d6c7122ef20..b2f602e04c7 100644 --- a/ui/packages/plugin-kanban/src/KanbanCardOwner.ts +++ b/ui/packages/plugin-kanban/src/KanbanCardOwner.ts @@ -47,3 +47,10 @@ export function resolveCardOwner( const image = typeof person.image === 'string' && person.image ? person.image : undefined; return image ? { name, image } : { name }; } + +/** + * 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'; diff --git a/ui/packages/plugin-kanban/src/KanbanImpl.tsx b/ui/packages/plugin-kanban/src/KanbanImpl.tsx index d69564b5326..a89170ac2fb 100644 --- a/ui/packages/plugin-kanban/src/KanbanImpl.tsx +++ b/ui/packages/plugin-kanban/src/KanbanImpl.tsx @@ -34,8 +34,7 @@ import { Plus, Sigma } from "lucide-react" import { useKanbanRecordsSettled } from './KanbanRecordsSettled' import { useKanbanColumnSummary, sumLaneField } from './KanbanColumnSummary' import { laneCount, useKanbanLanePaging } from './KanbanLanePaging' -import { getPersonInitials } from '@object-ui/fields' -import type { KanbanCardOwner } from './KanbanCardOwner' +import { ownerInitials, type KanbanCardOwner } from './KanbanCardOwner' import { createKanbanDndAnnouncer } from './kanbanDndAnnouncements' // Utility function to merge class names (inline to avoid external dependency) @@ -420,7 +419,7 @@ function SortableCard({ card, onCardClick, conditionalFormatting, objectFields } {owner.image && } - {getPersonInitials(owner.name)} + {ownerInitials(owner.name)}