Skip to content

Commit 33d0169

Browse files
feat(ui): the object's colour tile replaces its line icon in list headers, search, recents, pointers, hover cards, related lists and the studio (#36042)
repo:objectstack#1 · os-sales · session_01L6bhgWCsFBKwcq7ocDfUhR Part of #35985 Clause-②: yes (widening): an optional prop on `ConsolePageHeader` (an icon that brings its own frame is drawn as is), and an optional `color` on `RecordSearchHit` and on `RecordHoverCardObjectDef`. No spec change. The seat runs the declaration L2. Metadata-protocol: none ## 维护者速读 - 用户在列表页标题、数据页标题、记录页和记录抽屉的记录名前、记录页的关联列表、快捷面板、搜索结果、首页「最近访问」、表格里的关联单元格、关联悬停卡,以及设计器的对象清单和导航里,看到的对象图标都从灰色线条图标变成「对象颜色的圆角小方块 + 白色图标」,和上一步已经换好的左侧菜单一致。 - 这是对象颜色专题(控制台核心体验改进)的第 2 步:上一步给对象加了颜色并换了菜单,这一步把其余地方统一过来。 - 没设颜色的对象显示灰色方块;出问题只影响图标的样子,不动数据,撤回这个 PR 即恢复原来的线条图标。 - 无。 ## What changes PR 1 (#36012) added `ObjectSchema.color`, the nine-name palette and `ObjectIconTile`, and switched the navigation. This PR draws the tile everywhere else an object's icon names the object. The colour always comes from the object definition the host already holds; no new metadata read is added. | Place | File | Colour from | |---|---|---| | List page title and the view bar's object name | `ui/packages/app-shell/src/views/objectViewPageHeader.tsx` | `objectDef.color` | | URL data page title | `ui/packages/app-shell/src/views/ObjectDataPage.tsx` | `objectDef.color` | | Page header takes an icon that brings its own frame | `ui/packages/app-shell/src/layout/PageHeader.tsx` (new optional `iconTile`) | — | | Record row of the record page and of the record drawer, before the record's name | `ui/packages/app-shell/src/views/RecordDetailView.tsx`, `recordDrawerStack.tsx` | `objectDef.color` / the drawer's `defOf(...).color` | | Related list section heading on the record page | `ui/packages/plugin-detail/src/RelatedList.tsx` | the child schema the block already reads | | Command palette: recent records, record hit groups and rows, object navigation items | `ui/packages/app-shell/src/chrome/CommandPalette.tsx` | object definition / `useNavTargetColor` | | Search results page: group heading and hit cards | `ui/packages/app-shell/src/views/SearchResultsPage.tsx` | object definition, else the hit's `color` | | Global search block hits | `ui/packages/app-shell/src/views/global-search-renderer.tsx` | `hit.color` | | Search hit data | `ui/packages/react/src/hooks/useRecordSearch.ts` (`RecordSearchHit.color`) | object definition, server and fan-out paths | | Home "Recently accessed" record rows | `ui/packages/app-shell/src/console/home/HomeRail.tsx`, `HomePage.tsx` | object definition | | Grid reference (pointer) cell | `ui/packages/plugin-grid/src/RecordPointerCell.tsx` | `def.color` | | Reference hover card | `ui/packages/fields/src/RecordHoverCard.tsx` (`RecordHoverCardObjectDef.color`) | `objectSchema.color` | | Studio: data rail and header, interfaces rail and object header | `ui/packages/app-shell/src/views/metadata-admin/studio-design/StudioDesignSurface.tsx`, `InterfacesNavRail.tsx`, `StudioItemHeader.tsx`, `navSurface.ts` | the package's object list, now carrying `color` | | Tile glyph keeps its size inside hosts that size every nested `svg` | `ui/packages/components/src/custom/object-icon-tile.tsx` | — | - **`ConsolePageHeader.iconTile`** (new, optional). Drawn as given in every posture (list, setup, row) in place of `icon`, with no accent chip and no forced glyph size. Hosts that pass `icon` are unchanged. - **Glyph size.** The command palette's `[&_svg]:size-4` (cmdk) grew the tile's glyph to 16px inside a 20px square. The tile's glyph classes now carry Tailwind's important suffix (`h-3! w-3!` …), so a host's nested-`svg` rule no longer resizes it. - **Navigation rule as PR 1.** A menu or interface navigation entry that sets its own `icon` keeps that glyph; the colour is the object's. - Not changed (the card's "not in scope"): action buttons, app icons, views (favourited views included), fields, empty states, context pickers, section icons. The approval page's `SubmittedRecord` and the metadata `ResourceListPage` draw no object icon, so they are untouched. - The record row's two places switched after #35983 (two-row record header) merged; main is merged in. On a phone the record page draws no record-row icon, before or after. This PR closes PR 1's L2 nit N1 (the tile only in the navigation). PR 3 of #35985 (`domain:skills`) writes the colour names into the skills text and the CLI `explain` object table. ## Tests - New `ui/packages/app-shell/src/layout/__tests__/PageHeader.iconTile-35985.test.tsx`: `iconTile` is drawn in the list, setup and row postures, without the accent chip; control: `icon` alone still draws the chip. - `RecordHoverCard-27604.test.tsx`: a coloured object draws its tile in that colour, an uncoloured one in gray. - `ObjectGrid.recordPointerCell-12608.test.tsx`: the pointer cell's tile carries the target object's colour. - `useRecordSearch.test.ts`: hits carry the object's colour, and none for an uncoloured object. - `RecordDetailView.topBar-27524.test.tsx`: the page's record row and a pane's record row each draw one tile in the object's colour. Ablation: with the two source files reverted both cases go red; restored, they pass. - `HomePage.recentlyAccessed-12604.test.tsx`: the record row of a coloured object draws its tile; other rows keep the kind icon. - Ablation: with `HomeRail.tsx`'s tile reverted to the line icon the home pin goes red; restored, `git diff HEAD` empty. ## Acceptance notes - Home "Recently accessed" rows for a list visit (object type, no record) still show the kind icon; only record rows draw the object tile. - Search results' navigation-match rows and the Studio command palette's object entries keep their kind icons: they name a kind of place, not an object. ## Verification Read first, by risk: 1. `ui/packages/app-shell/src/layout/PageHeader.tsx`: the `iconTile` branch in all three postures (contract face, L2). 2. `ui/packages/app-shell/src/chrome/CommandPalette.tsx`: where each group's colour comes from. 3. `ui/packages/app-shell/src/views/metadata-admin/studio-design/StudioDesignSurface.tsx`: the colour map threaded into both rails and headers. Two-minute check: open the showcase app, give `account` a colour (for example `orange`), open Accounts: the list title, the palette (⌘K, type an account name) and the home recents all show an orange square with a white glyph. Browser evidence (Chromium, showcase app with seven objects coloured locally for the shot, not committed): before and after, light and dark, 1280 and 375 wide, for the list (account, contact), the record page's record row (light, dark, 1280, 375) and the record drawer (light, dark, 1280; files `after-record-header-*`, `after-record-drawer-*`), record page related lists, contact hover card, home recents, palette, search, approvals pointer cell, Studio data and interfaces. 80 files `before-*` / `after-*` in the project folder `build-seat1/35985/PR2/`. <details><summary>Local gates</summary> - `turbo run type-check` for `@object-ui/components`, `@object-ui/react`, `@object-ui/fields`, `@object-ui/plugin-grid`, `@object-ui/plugin-detail`, `@object-ui/app-shell`: exit 0. - vitest over the touched packages' affected test files: 408 files, 3379 tests passed; the new and edited pins: 6 files, 58 tests passed. After the merge of main and the record-row change: every app-shell test file that names `RecordDetailView` or `recordDrawerStack`, 225 files, 1877 tests passed. - `node scripts/pm/dispatch-gates.mjs --commands` derived set (39 commands): 39 of 39 exit 0 (one red on the first run, `check:test-source-alias` on the home recents pin, fixed by its module-top `@objectstack/lint` import) - `node scripts/pm/overlap-check.mjs`: clean against `origin/main` 8145424 and #36024 - eslint on every changed file: 0 errors. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWCsFBKwcq7ocDfUhR --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent fddb9cb commit 33d0169

27 files changed

Lines changed: 368 additions & 99 deletions
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/components': patch
4+
'@object-ui/react': patch
5+
'@object-ui/fields': patch
6+
'@object-ui/plugin-grid': patch
7+
'@object-ui/plugin-detail': patch
8+
---
9+
10+
feat(ui): the object's colour tile replaces its line icon wherever else the object is named
11+
12+
Clause-②: yes (widening) — `ConsolePageHeaderProps` gains the optional `iconTile`, and `RecordSearchHit` and `RecordHoverCardObjectDef` the optional `color`; nothing removed or renamed
13+
Metadata-protocol: none
14+
15+
The tile the navigation already draws for an object (a white glyph on the object's palette colour, gray when it has none) now also names the object in:
16+
17+
- **List and data pages:** the page bar and the view bar's object name in front of the view switcher; the URL data page's header.
18+
- **The record page and the record drawer:** the record row in front of the record's name.
19+
- **The record page's related lists:** each section's title, with the list's own icon else the related object's, on that object's colour.
20+
- **Search:** the command palette's recent records, record hits and object entries; the search results page (group headings and hit cards); the global search block.
21+
- **Home:** a record row in "Recently accessed".
22+
- **References:** a pointer cell in a grid (`referenceVia`) and the record hover card.
23+
- **Studio:** the data pillar's object list and header, and the interfaces pillar's object entries and header.
24+
25+
`ConsolePageHeader` takes `iconTile`, an icon that draws its own square, drawn as given in every posture in place of `icon`. `RecordSearchHit.color` carries the object's palette name beside `icon`, and `RecordHoverCardObjectDef` names `color` beside `icon`. `ObjectIconTile`'s glyph keeps its size inside a host row that sizes every nested `svg`.

‎ui/packages/app-shell/README.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,9 @@ to draw the same header. Below `sm` it draws the icon, the title and the actions
450450
the secondary line is hidden there.
451451

452452
Its props are the exported `ConsolePageHeaderProps`: `title` (required),
453-
`subtitle`, `icon` (a rendered element, sized by the chip), `actions`,
453+
`subtitle`, `icon` (a rendered element, sized by the chip), `iconTile` (an
454+
icon that draws its own square, such as `ObjectIconTile`, drawn as given in
455+
place of `icon`), `actions`,
454456
`foldedActions`, `accentColor`, `sticky`, `className` and `data-testid`. The
455457
secondary line is `subtitle`; there is no `description` prop.
456458

‎ui/packages/app-shell/src/chrome/CommandPalette.tsx‎

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
CommandItem,
3636
CommandList,
3737
CommandSeparator,
38+
ObjectIconTile,
3839
} from '@object-ui/components';
3940
import {
4041
LayoutDashboard,
@@ -70,6 +71,7 @@ import { resolveHref, resolveNavItemLabel } from '@object-ui/layout';
7071
import type { NavigationItem } from '@object-ui/types';
7172
import { findByName, useNavTargetLabel, type NavTargetLabelOptions } from '../hooks/useNavTargetLabel.js';
7273
import { readObjectsByName } from '../hooks/useObjectPresence.js';
74+
import { useNavTargetColor } from '../hooks/useNavTargetIcon.js';
7375

7476
import { useAuth } from '@object-ui/auth';
7577
import { matchesPaletteQuery } from './paletteMatch.js';
@@ -411,15 +413,19 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
411413
*/
412414
const metadata = useMetadata();
413415
const recentTargetLabel = useNavTargetLabel(RECENT_ROW_LABELS);
414-
const recentContext = (item: RecentItem): { type?: string; icon?: string } => {
416+
const recentContext = (item: RecentItem): { objectName?: string; type?: string; icon?: string; color?: string } => {
415417
const objectName = recentItemObject(item);
416418
if (!objectName) return {};
417-
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as { icon?: unknown } | undefined;
419+
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as { icon?: unknown; color?: unknown } | undefined;
418420
return {
421+
objectName,
419422
type: recentTargetLabel({ kind: 'object', objectName }) ?? objectName,
420423
icon: typeof def?.icon === 'string' && def.icon !== '' ? def.icon : undefined,
424+
color: typeof def?.color === 'string' ? def.color : undefined,
421425
};
422426
};
427+
// objectstack#35985 — an object entry draws the object's tile, in its colour.
428+
const navTargetColor = useNavTargetColor();
423429

424430
// Index object defs by name so group headings can resolve the object's
425431
// localized label (labels may be `{ key, defaultValue }` i18n objects, which
@@ -440,7 +446,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
440446
const order: string[] = [];
441447
const byObject = new Map<
442448
string,
443-
{ objectLabel: string; icon?: string; hits: typeof recordHits }
449+
{ objectLabel: string; icon?: string; color?: string; hits: typeof recordHits }
444450
>();
445451
for (const hit of recordHits) {
446452
let group = byObject.get(hit.objectName);
@@ -449,7 +455,12 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
449455
// label (already objectName when the def had no string label).
450456
const objDef = objectsByName.get(hit.objectName);
451457
const label = resolveKeyedI18nLabel(objDef?.label, t) || hit.objectLabel;
452-
group = { objectLabel: label, icon: hit.icon, hits: [] };
458+
group = {
459+
objectLabel: label,
460+
icon: hit.icon,
461+
color: typeof objDef?.color === 'string' ? objDef.color : hit.color,
462+
hits: [],
463+
};
453464
byObject.set(hit.objectName, group);
454465
order.push(hit.objectName);
455466
}
@@ -503,15 +514,19 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
503514
heading={t('console.commandPalette.recentRecords', { defaultValue: 'Recently viewed' })}
504515
>
505516
{recentRecords.map((item) => {
506-
const { type, icon } = recentContext(item);
517+
const { objectName, type, icon, color } = recentContext(item);
507518
const Icon = icon ? getIcon(icon) : FileText;
508519
return (
509520
<CommandItem
510521
key={`recent:${item.id}`}
511522
value={`recent ${recentLabel(item)} ${item.id}`}
512523
onSelect={() => leaveTo(item.href)}
513524
>
514-
<Icon className="mr-2 h-4 w-4" />
525+
{objectName ? (
526+
<ObjectIconTile glyph={Icon} color={color} className="mr-2" />
527+
) : (
528+
<Icon className="mr-2 h-4 w-4" />
529+
)}
515530
<span className="truncate">{recentLabel(item)}</span>
516531
{type && (
517532
<span
@@ -556,7 +571,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
556571
value={`record ${hit.display} ${hit.objectLabel} ${hit.objectName} ${hit.recordId}`}
557572
onSelect={() => leaveTo(`${recordHitBaseUrl(hit.objectName)}/${hit.objectName}/record/${hit.recordId}`)}
558573
>
559-
<Icon className="mr-2 h-4 w-4" />
574+
<ObjectIconTile glyph={Icon} color={group.color} className="mr-2" />
560575
<span className="truncate">{hit.display}</span>
561576
{hit.subtitle && (
562577
<span className="ml-auto max-w-[45%] truncate text-xs text-muted-foreground">
@@ -574,13 +589,14 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
574589
{objectItems
575590
.map(item => {
576591
const Icon = getIcon(item.icon);
592+
const color = item.objectName ? navTargetColor({ kind: 'object', objectName: item.objectName }) : undefined;
577593
return (
578594
<CommandItem
579595
key={item.id}
580596
value={`object ${navLabel(item)} ${item.objectName}`}
581597
onSelect={() => leaveTo(resolveHref(item, baseUrl, templateContext).href)}
582598
>
583-
<Icon className="mr-2 h-4 w-4" />
599+
<ObjectIconTile glyph={Icon} color={color} className="mr-2" />
584600
<span>{navLabel(item)}</span>
585601
</CommandItem>
586602
);

‎ui/packages/app-shell/src/console/home/HomePage.tsx‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,19 +615,21 @@ export function HomePage({ checklist }: HomePageProps = {}) {
615615
icon: undefined,
616616
};
617617
}
618-
const objectIcon =
618+
const objectDef =
619619
item.type === 'record' && objectName
620-
? (readObjectsByName(metadata, [objectName]) as Array<{ name?: unknown; icon?: unknown } | null | undefined>).find(
620+
? (readObjectsByName(metadata, [objectName]) as Array<{ name?: unknown; icon?: unknown; color?: unknown } | null | undefined>).find(
621621
(o) => o?.name === objectName,
622-
)?.icon
622+
)
623623
: undefined;
624+
const objectIcon = objectDef?.icon;
624625
return {
625626
context:
626627
item.type === 'record' && objectName
627628
? targetLabel({ kind: 'object', objectName }) ?? objectName
628629
: recentItemTypeLabel(t, item.type),
629630
app: app ? appLabel(app) : undefined,
630631
icon: typeof objectIcon === 'string' && objectIcon !== '' ? objectIcon : undefined,
632+
color: typeof objectDef?.color === 'string' ? objectDef.color : undefined,
631633
};
632634
};
633635

‎ui/packages/app-shell/src/console/home/HomeRail.tsx‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
FileText, Database, LayoutDashboard, File, List, CircleAlert, Rocket, Lock,
1919
} from 'lucide-react';
2020
import { useDisplayLocale } from '@object-ui/i18n';
21-
import { Button, cn } from '@object-ui/components';
21+
import { Button, cn, ObjectIconTile } from '@object-ui/components';
2222
import type { ActivityFeedReading } from '../../hooks/sharedUserFeeds.js';
2323
import type { HomeInboxStatus, HomeNotification, PendingApprovalRequest } from '../../hooks/useHomeInbox.js';
2424
import type { RecentItem } from '../../hooks/useRecentItems.js';
@@ -484,6 +484,11 @@ export interface RecentItemContext {
484484
app?: string;
485485
/** A record's object icon (a Lucide name), or `undefined` to draw the kind's icon. */
486486
icon?: string;
487+
/**
488+
* A record's object palette colour (`ObjectSchema.color`): with `icon`, the
489+
* row draws the object's tile in that colour (objectstack#35985).
490+
*/
491+
color?: string;
487492
}
488493

489494
/**
@@ -524,7 +529,7 @@ export function HomeContinue({
524529
) : (
525530
<ul className="overflow-hidden rounded-lg border border-border bg-card">
526531
{items.map((it) => {
527-
const { context, app, icon } = describe(it);
532+
const { context, app, icon, color } = describe(it);
528533
const Icon = icon ? getIcon(icon) : RECENT_ICON[it.type] || FileText;
529534
const trail = [context, app, timeAgo(it.visitedAt, displayLocale)].filter(Boolean).join(' · ');
530535
return (
@@ -536,13 +541,19 @@ export function HomeContinue({
536541
data-recent-type={it.type}
537542
className="flex h-10 w-full items-center gap-2.5 px-3 text-left text-[13px] transition-colors hover:bg-muted/60 max-sm:h-11"
538543
>
539-
<span
540-
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground"
541-
data-testid="home-recent-icon"
542-
data-icon={icon ?? it.type}
543-
>
544-
<Icon className="h-[13px] w-[13px]" />
545-
</span>
544+
{icon ? (
545+
<span className="inline-flex shrink-0" data-testid="home-recent-icon" data-icon={icon}>
546+
<ObjectIconTile glyph={Icon} color={color} size="md" />
547+
</span>
548+
) : (
549+
<span
550+
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground"
551+
data-testid="home-recent-icon"
552+
data-icon={it.type}
553+
>
554+
<Icon className="h-[13px] w-[13px]" />
555+
</span>
556+
)}
546557
<span className="min-w-0 flex-1 truncate">{labelOf(it)}</span>
547558
<span className="shrink-0 text-xs text-muted-foreground" data-testid="home-recent-trail">
548559
{trail}

‎ui/packages/app-shell/src/console/home/__tests__/HomePage.recentlyAccessed-12604.test.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
import '@testing-library/jest-dom/vitest';
2424
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
25+
// Pays the lint package's first load during collection, not inside a clocked case (check:test-source-alias).
26+
import '@objectstack/lint';
2527
import React from 'react';
2628
import { render, screen, cleanup, within } from '@testing-library/react';
2729
import { useDisplayLocale } from '@object-ui/i18n';
@@ -151,6 +153,7 @@ const ACCOUNT = {
151153
label: 'Account',
152154
pluralLabel: 'Accounts',
153155
icon: 'building',
156+
color: 'orange',
154157
listViews: { 'crm_account.all_accounts': { name: 'crm_account.all_accounts', label: 'All Accounts' } },
155158
};
156159

@@ -277,6 +280,14 @@ describe('Home "Recently accessed" (objectui#12604)', () => {
277280
});
278281
});
279282

283+
describe('a record row draws its object\'s tile (objectstack#35985)', () => {
284+
it('in the object\'s palette colour; the other kinds keep their muted kind icon', () => {
285+
renderPage();
286+
const tiles = rows().map((row) => row.querySelector('[data-object-icon-tile]')?.getAttribute('data-object-icon-tile') ?? null);
287+
expect(tiles).toEqual(['orange', null, null, null]);
288+
});
289+
});
290+
280291
describe('the activity column gate (objectui#12081, objectui#12604)', () => {
281292
/** The grid that holds the two columns. */
282293
function grid(): HTMLElement {

‎ui/packages/app-shell/src/layout/PageHeader.tsx‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,13 @@ export interface ConsolePageHeaderProps {
117117
* the chip will scale child `<svg>` elements to fit.
118118
*/
119119
icon?: React.ReactNode;
120+
/**
121+
* A leading icon that draws its own square — an object's `ObjectIconTile`
122+
* (objectstack#35985), so the page names its object in the colour the menu
123+
* draws it in. Drawn as given, in every posture, in place of `icon`: no
124+
* accent chip around it and no forced glyph size inside it.
125+
*/
126+
iconTile?: React.ReactNode;
120127
/**
121128
* The page's kind chip, drawn right after the title (objectui#12606) — the
122129
* `ManagedByBadge` of a `sys_*` list, a metadata type's writability badge.
@@ -208,6 +215,7 @@ export function PageHeader({
208215
title,
209216
subtitle,
210217
icon,
218+
iconTile,
211219
badge,
212220
breadcrumb,
213221
refresh,
@@ -297,14 +305,14 @@ export function PageHeader({
297305

298306
{list ? (
299307
<div className="flex h-full items-center justify-between gap-3 px-4">
300-
{/* One line at 13px: the object's icon in one colour (the object
301-
model carries no colour, objectstack#35547), its name, its kind. */}
308+
{/* One line at 13px: the object's icon (its tile, objectstack#35985),
309+
its name, its kind. */}
302310
<div ref={textRef} className="flex min-w-0 flex-1 items-center gap-2">
303-
{icon && (
311+
{iconTile ?? (icon && (
304312
<span className="flex shrink-0 text-muted-foreground [&_svg]:h-4 [&_svg]:w-4" data-testid="page-header-icon">
305313
{icon}
306314
</span>
307-
)}
315+
))}
308316
<h1 className="min-w-0 max-w-full shrink-0 truncate text-[13px] font-semibold leading-5 text-foreground">
309317
{title}
310318
</h1>
@@ -315,7 +323,7 @@ export function PageHeader({
315323
) : setup ? (
316324
<div className="flex justify-between items-center gap-3 py-3 px-4 sm:px-6">
317325
<div className="flex items-center gap-3 min-w-0 flex-1">
318-
{icon && <IconTile size="setup">{icon}</IconTile>}
326+
{iconTile ?? (icon && <IconTile size="setup">{icon}</IconTile>)}
319327
<div ref={textRef} className="min-w-0 flex-1">
320328
<div className="flex items-center gap-2 min-w-0">
321329
<h1 className="min-w-0 truncate text-lg font-semibold leading-6 tracking-tight text-foreground">
@@ -347,7 +355,7 @@ export function PageHeader({
347355
(objectui#12553). It sits here, not on the padded row above: under
348356
`border-box` a min-height there would count that row's padding. */}
349357
<div ref={textRef} className="flex items-center gap-2.5 min-w-0 flex-1 min-h-9">
350-
{icon && <IconTile size="row">{icon}</IconTile>}
358+
{iconTile ?? (icon && <IconTile size="row">{icon}</IconTile>)}
351359
{/* The 60 % cap keeps room for the description beside the title;
352360
the compact form draws none, so its title takes the whole row
353361
(objectstack#35446). */}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/**
2+
* ObjectUI
3+
* Copyright (c) 2024-present ObjectStack Inc.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
/**
10+
* objectstack#35985 — a page that names an object leads with the object's
11+
* tile (`iconTile`), drawn as given in every posture: no accent chip around it
12+
* and no icon slot forcing its glyph size, and in place of `icon`.
13+
*/
14+
import { describe, it, expect } from 'vitest';
15+
import { render, screen } from '@testing-library/react';
16+
import '@testing-library/jest-dom';
17+
import * as React from 'react';
18+
import { MemoryRouter, Routes, Route } from 'react-router-dom';
19+
import { ObjectIconTile } from '@object-ui/components';
20+
import { PageHeader } from '../PageHeader';
21+
22+
// The row and list postures come from the `posture` prop; Setup's is read off
23+
// the route (`/apps/setup/...`), so that case mounts the header under it.
24+
const postures = [
25+
{ reached: 'row', posture: undefined, app: 'crm' },
26+
{ reached: 'list', posture: 'list', app: 'crm' },
27+
{ reached: 'setup', posture: undefined, app: 'setup' },
28+
] as const;
29+
30+
describe('PageHeader draws an object tile as given (objectstack#35985)', () => {
31+
it.each(postures)('posture $reached: the tile sits directly in the title row, and `icon` is not drawn', ({ reached, posture, app }) => {
32+
const { container } = render(
33+
<MemoryRouter initialEntries={[`/apps/${app}/x`]}>
34+
<Routes>
35+
<Route
36+
path="/apps/:appName/*"
37+
element={
38+
<PageHeader
39+
title="Accounts"
40+
posture={posture}
41+
icon={<svg data-testid="line-icon" />}
42+
iconTile={<ObjectIconTile icon="building" color="orange" />}
43+
/>
44+
}
45+
/>
46+
</Routes>
47+
</MemoryRouter>,
48+
);
49+
expect(container.querySelector('[data-posture]')).toHaveAttribute('data-posture', reached);
50+
const tile = document.querySelector('[data-object-icon-tile]') as HTMLElement;
51+
expect(tile).toHaveAttribute('data-object-icon-tile', 'orange');
52+
expect(screen.queryByTestId('line-icon')).toBeNull();
53+
// Not wrapped: no list icon slot, no accent chip with an inline style.
54+
expect(screen.queryByTestId('page-header-icon')).toBeNull();
55+
expect(tile.parentElement!.getAttribute('style')).toBeNull();
56+
expect(tile.parentElement!.contains(screen.getByRole('heading', { level: 1 }))).toBe(true);
57+
});
58+
59+
it('CONTROL: without `iconTile` the line icon still draws in its slot', () => {
60+
render(<PageHeader title="Accounts" posture="list" icon={<svg data-testid="line-icon" />} />);
61+
expect(screen.getByTestId('page-header-icon')).toContainElement(screen.getByTestId('line-icon'));
62+
});
63+
});

0 commit comments

Comments
 (0)