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
25 changes: 25 additions & 0 deletions .changeset/35985-object-color-tile-everywhere.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@object-ui/app-shell': patch
'@object-ui/components': patch
'@object-ui/react': patch
'@object-ui/fields': patch
'@object-ui/plugin-grid': patch
'@object-ui/plugin-detail': patch
---

feat(ui): the object's colour tile replaces its line icon wherever else the object is named

Clause-②: yes (widening) — `ConsolePageHeaderProps` gains the optional `iconTile`, and `RecordSearchHit` and `RecordHoverCardObjectDef` the optional `color`; nothing removed or renamed
Metadata-protocol: none

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:

- **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.
- **The record page and the record drawer:** the record row in front of the record's name.
- **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.
- **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.
- **Home:** a record row in "Recently accessed".
- **References:** a pointer cell in a grid (`referenceVia`) and the record hover card.
- **Studio:** the data pillar's object list and header, and the interfaces pillar's object entries and header.

`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`.
4 changes: 3 additions & 1 deletion ui/packages/app-shell/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,9 @@ to draw the same header. Below `sm` it draws the icon, the title and the actions
the secondary line is hidden there.

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

Expand Down
32 changes: 24 additions & 8 deletions ui/packages/app-shell/src/chrome/CommandPalette.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
CommandItem,
CommandList,
CommandSeparator,
ObjectIconTile,
} from '@object-ui/components';
import {
LayoutDashboard,
Expand Down Expand Up @@ -70,6 +71,7 @@ import { resolveHref, resolveNavItemLabel } from '@object-ui/layout';
import type { NavigationItem } from '@object-ui/types';
import { findByName, useNavTargetLabel, type NavTargetLabelOptions } from '../hooks/useNavTargetLabel.js';
import { readObjectsByName } from '../hooks/useObjectPresence.js';
import { useNavTargetColor } from '../hooks/useNavTargetIcon.js';

import { useAuth } from '@object-ui/auth';
import { matchesPaletteQuery } from './paletteMatch.js';
Expand Down Expand Up @@ -411,15 +413,19 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
*/
const metadata = useMetadata();
const recentTargetLabel = useNavTargetLabel(RECENT_ROW_LABELS);
const recentContext = (item: RecentItem): { type?: string; icon?: string } => {
const recentContext = (item: RecentItem): { objectName?: string; type?: string; icon?: string; color?: string } => {
const objectName = recentItemObject(item);
if (!objectName) return {};
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as { icon?: unknown } | undefined;
const def = findByName(readObjectsByName(metadata, [objectName]), objectName) as { icon?: unknown; color?: unknown } | undefined;
return {
objectName,
type: recentTargetLabel({ kind: 'object', objectName }) ?? objectName,
icon: typeof def?.icon === 'string' && def.icon !== '' ? def.icon : undefined,
color: typeof def?.color === 'string' ? def.color : undefined,
};
};
// objectstack#35985 — an object entry draws the object's tile, in its colour.
const navTargetColor = useNavTargetColor();

// Index object defs by name so group headings can resolve the object's
// localized label (labels may be `{ key, defaultValue }` i18n objects, which
Expand All @@ -440,7 +446,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
const order: string[] = [];
const byObject = new Map<
string,
{ objectLabel: string; icon?: string; hits: typeof recordHits }
{ objectLabel: string; icon?: string; color?: string; hits: typeof recordHits }
>();
for (const hit of recordHits) {
let group = byObject.get(hit.objectName);
Expand All @@ -449,7 +455,12 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
// label (already objectName when the def had no string label).
const objDef = objectsByName.get(hit.objectName);
const label = resolveKeyedI18nLabel(objDef?.label, t) || hit.objectLabel;
group = { objectLabel: label, icon: hit.icon, hits: [] };
group = {
objectLabel: label,
icon: hit.icon,
color: typeof objDef?.color === 'string' ? objDef.color : hit.color,
hits: [],
};
byObject.set(hit.objectName, group);
order.push(hit.objectName);
}
Expand Down Expand Up @@ -503,15 +514,19 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
heading={t('console.commandPalette.recentRecords', { defaultValue: 'Recently viewed' })}
>
{recentRecords.map((item) => {
const { type, icon } = recentContext(item);
const { objectName, type, icon, color } = recentContext(item);
const Icon = icon ? getIcon(icon) : FileText;
return (
<CommandItem
key={`recent:${item.id}`}
value={`recent ${recentLabel(item)} ${item.id}`}
onSelect={() => leaveTo(item.href)}
>
<Icon className="mr-2 h-4 w-4" />
{objectName ? (
<ObjectIconTile glyph={Icon} color={color} className="mr-2" />
) : (
<Icon className="mr-2 h-4 w-4" />
)}
<span className="truncate">{recentLabel(item)}</span>
{type && (
<span
Expand Down Expand Up @@ -556,7 +571,7 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
value={`record ${hit.display} ${hit.objectLabel} ${hit.objectName} ${hit.recordId}`}
onSelect={() => leaveTo(`${recordHitBaseUrl(hit.objectName)}/${hit.objectName}/record/${hit.recordId}`)}
>
<Icon className="mr-2 h-4 w-4" />
<ObjectIconTile glyph={Icon} color={group.color} className="mr-2" />
<span className="truncate">{hit.display}</span>
{hit.subtitle && (
<span className="ml-auto max-w-[45%] truncate text-xs text-muted-foreground">
Expand All @@ -574,13 +589,14 @@ function CommandPaletteBody(props: CommandPaletteProps & { gates: NavMemberGates
{objectItems
.map(item => {
const Icon = getIcon(item.icon);
const color = item.objectName ? navTargetColor({ kind: 'object', objectName: item.objectName }) : undefined;
return (
<CommandItem
key={item.id}
value={`object ${navLabel(item)} ${item.objectName}`}
onSelect={() => leaveTo(resolveHref(item, baseUrl, templateContext).href)}
>
<Icon className="mr-2 h-4 w-4" />
<ObjectIconTile glyph={Icon} color={color} className="mr-2" />
<span>{navLabel(item)}</span>
</CommandItem>
);
Expand Down
8 changes: 5 additions & 3 deletions ui/packages/app-shell/src/console/home/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -615,19 +615,21 @@ export function HomePage({ checklist }: HomePageProps = {}) {
icon: undefined,
};
}
const objectIcon =
const objectDef =
item.type === 'record' && objectName
? (readObjectsByName(metadata, [objectName]) as Array<{ name?: unknown; icon?: unknown } | null | undefined>).find(
? (readObjectsByName(metadata, [objectName]) as Array<{ name?: unknown; icon?: unknown; color?: unknown } | null | undefined>).find(
(o) => o?.name === objectName,
)?.icon
)
: undefined;
const objectIcon = objectDef?.icon;
return {
context:
item.type === 'record' && objectName
? targetLabel({ kind: 'object', objectName }) ?? objectName
: recentItemTypeLabel(t, item.type),
app: app ? appLabel(app) : undefined,
icon: typeof objectIcon === 'string' && objectIcon !== '' ? objectIcon : undefined,
color: typeof objectDef?.color === 'string' ? objectDef.color : undefined,
};
};

Expand Down
29 changes: 20 additions & 9 deletions ui/packages/app-shell/src/console/home/HomeRail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
FileText, Database, LayoutDashboard, File, List, CircleAlert, Rocket, Lock,
} from 'lucide-react';
import { useDisplayLocale } from '@object-ui/i18n';
import { Button, cn } from '@object-ui/components';
import { Button, cn, ObjectIconTile } from '@object-ui/components';
import type { ActivityFeedReading } from '../../hooks/sharedUserFeeds.js';
import type { HomeInboxStatus, HomeNotification, PendingApprovalRequest } from '../../hooks/useHomeInbox.js';
import type { RecentItem } from '../../hooks/useRecentItems.js';
Expand Down Expand Up @@ -484,6 +484,11 @@ export interface RecentItemContext {
app?: string;
/** A record's object icon (a Lucide name), or `undefined` to draw the kind's icon. */
icon?: string;
/**
* A record's object palette colour (`ObjectSchema.color`): with `icon`, the
* row draws the object's tile in that colour (objectstack#35985).
*/
color?: string;
}

/**
Expand Down Expand Up @@ -524,7 +529,7 @@ export function HomeContinue({
) : (
<ul className="overflow-hidden rounded-lg border border-border bg-card">
{items.map((it) => {
const { context, app, icon } = describe(it);
const { context, app, icon, color } = describe(it);
const Icon = icon ? getIcon(icon) : RECENT_ICON[it.type] || FileText;
const trail = [context, app, timeAgo(it.visitedAt, displayLocale)].filter(Boolean).join(' · ');
return (
Expand All @@ -536,13 +541,19 @@ export function HomeContinue({
data-recent-type={it.type}
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"
>
<span
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground"
data-testid="home-recent-icon"
data-icon={icon ?? it.type}
>
<Icon className="h-[13px] w-[13px]" />
</span>
{icon ? (
<span className="inline-flex shrink-0" data-testid="home-recent-icon" data-icon={icon}>
<ObjectIconTile glyph={Icon} color={color} size="md" />
</span>
) : (
<span
className="inline-flex h-6 w-6 shrink-0 items-center justify-center rounded-md bg-muted text-muted-foreground"
data-testid="home-recent-icon"
data-icon={it.type}
>
<Icon className="h-[13px] w-[13px]" />
</span>
)}
<span className="min-w-0 flex-1 truncate">{labelOf(it)}</span>
<span className="shrink-0 text-xs text-muted-foreground" data-testid="home-recent-trail">
{trail}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

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

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

describe('a record row draws its object\'s tile (objectstack#35985)', () => {
it('in the object\'s palette colour; the other kinds keep their muted kind icon', () => {
renderPage();
const tiles = rows().map((row) => row.querySelector('[data-object-icon-tile]')?.getAttribute('data-object-icon-tile') ?? null);
expect(tiles).toEqual(['orange', null, null, null]);
});
});

describe('the activity column gate (objectui#12081, objectui#12604)', () => {
/** The grid that holds the two columns. */
function grid(): HTMLElement {
Expand Down
20 changes: 14 additions & 6 deletions ui/packages/app-shell/src/layout/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,13 @@ export interface ConsolePageHeaderProps {
* the chip will scale child `<svg>` elements to fit.
*/
icon?: React.ReactNode;
/**
* A leading icon that draws its own square — an object's `ObjectIconTile`
* (objectstack#35985), so the page names its object in the colour the menu
* draws it in. Drawn as given, in every posture, in place of `icon`: no
* accent chip around it and no forced glyph size inside it.
*/
iconTile?: React.ReactNode;
/**
* The page's kind chip, drawn right after the title (objectui#12606) — the
* `ManagedByBadge` of a `sys_*` list, a metadata type's writability badge.
Expand Down Expand Up @@ -208,6 +215,7 @@ export function PageHeader({
title,
subtitle,
icon,
iconTile,
badge,
breadcrumb,
refresh,
Expand Down Expand Up @@ -297,14 +305,14 @@ export function PageHeader({

{list ? (
<div className="flex h-full items-center justify-between gap-3 px-4">
{/* One line at 13px: the object's icon in one colour (the object
model carries no colour, objectstack#35547), its name, its kind. */}
{/* One line at 13px: the object's icon (its tile, objectstack#35985),
its name, its kind. */}
<div ref={textRef} className="flex min-w-0 flex-1 items-center gap-2">
{icon && (
{iconTile ?? (icon && (
<span className="flex shrink-0 text-muted-foreground [&_svg]:h-4 [&_svg]:w-4" data-testid="page-header-icon">
{icon}
</span>
)}
))}
<h1 className="min-w-0 max-w-full shrink-0 truncate text-[13px] font-semibold leading-5 text-foreground">
{title}
</h1>
Expand All @@ -315,7 +323,7 @@ export function PageHeader({
) : setup ? (
<div className="flex justify-between items-center gap-3 py-3 px-4 sm:px-6">
<div className="flex items-center gap-3 min-w-0 flex-1">
{icon && <IconTile size="setup">{icon}</IconTile>}
{iconTile ?? (icon && <IconTile size="setup">{icon}</IconTile>)}
<div ref={textRef} className="min-w-0 flex-1">
<div className="flex items-center gap-2 min-w-0">
<h1 className="min-w-0 truncate text-lg font-semibold leading-6 tracking-tight text-foreground">
Expand Down Expand Up @@ -347,7 +355,7 @@ export function PageHeader({
(objectui#12553). It sits here, not on the padded row above: under
`border-box` a min-height there would count that row's padding. */}
<div ref={textRef} className="flex items-center gap-2.5 min-w-0 flex-1 min-h-9">
{icon && <IconTile size="row">{icon}</IconTile>}
{iconTile ?? (icon && <IconTile size="row">{icon}</IconTile>)}
{/* The 60 % cap keeps room for the description beside the title;
the compact form draws none, so its title takes the whole row
(objectstack#35446). */}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/**
* 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#35985 — a page that names an object leads with the object's
* tile (`iconTile`), drawn as given in every posture: no accent chip around it
* and no icon slot forcing its glyph size, and in place of `icon`.
*/
import { describe, it, expect } from 'vitest';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import * as React from 'react';
import { MemoryRouter, Routes, Route } from 'react-router-dom';
import { ObjectIconTile } from '@object-ui/components';
import { PageHeader } from '../PageHeader';

// The row and list postures come from the `posture` prop; Setup's is read off
// the route (`/apps/setup/...`), so that case mounts the header under it.
const postures = [
{ reached: 'row', posture: undefined, app: 'crm' },
{ reached: 'list', posture: 'list', app: 'crm' },
{ reached: 'setup', posture: undefined, app: 'setup' },
] as const;

describe('PageHeader draws an object tile as given (objectstack#35985)', () => {
it.each(postures)('posture $reached: the tile sits directly in the title row, and `icon` is not drawn', ({ reached, posture, app }) => {
const { container } = render(
<MemoryRouter initialEntries={[`/apps/${app}/x`]}>
<Routes>
<Route
path="/apps/:appName/*"
element={
<PageHeader
title="Accounts"
posture={posture}
icon={<svg data-testid="line-icon" />}
iconTile={<ObjectIconTile icon="building" color="orange" />}
/>
}
/>
</Routes>
</MemoryRouter>,
);
expect(container.querySelector('[data-posture]')).toHaveAttribute('data-posture', reached);
const tile = document.querySelector('[data-object-icon-tile]') as HTMLElement;
expect(tile).toHaveAttribute('data-object-icon-tile', 'orange');
expect(screen.queryByTestId('line-icon')).toBeNull();
// Not wrapped: no list icon slot, no accent chip with an inline style.
expect(screen.queryByTestId('page-header-icon')).toBeNull();
expect(tile.parentElement!.getAttribute('style')).toBeNull();
expect(tile.parentElement!.contains(screen.getByRole('heading', { level: 1 }))).toBe(true);
});

it('CONTROL: without `iconTile` the line icon still draws in its slot', () => {
render(<PageHeader title="Accounts" posture="list" icon={<svg data-testid="line-icon" />} />);
expect(screen.getByTestId('page-header-icon')).toContainElement(screen.getByTestId('line-icon'));
});
});
Loading
Loading