Skip to content

Commit 977ccbb

Browse files
committed
feat(app-shell): a row-table page block lists the rows a page api binding answers
The sixth product-page block: rows from a list (or a whole hole naming one in the bound data), declared columns with path, label and a text, datetime or enum format, every row drawn, an empty label, and the binding's error panel for a list it cannot read. Its strict @object-ui/types arm lands with it, and the cli's known types are regenerated. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTx4LkMSXMTUGZuzQW
1 parent 1ff1d45 commit 977ccbb

17 files changed

Lines changed: 567 additions & 26 deletions
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@object-ui/types': minor
3+
'@object-ui/app-shell': patch
4+
'@object-ui/cli': patch
5+
---
6+
7+
feat(app-shell): a `row-table` page block lists the rows a page `api` binding answers, as a table
8+
9+
Clause-②: yes (widening)
10+
Metadata-protocol: added
11+
12+
- **`@object-ui/app-shell`: the `row-table` block**, the sixth product-page block beside `hero`, `stat`, `usage-bar`, `checklist` and `tile-grid`, registered under the `app-shell` namespace with the bare `row-table` as its authorable key. `rows` is a list, or one whole `${…}` hole naming a list in the bound `data` (`rows: '${data.actors}'`); every row is drawn, with no cap. `columns` declares, in order, `{ path, label, format?, enum? }`: `path` is a dotted path into one row, `label` a string or an inline locale map, and `format` is `text` (the default, drawn as written), `datetime` (an instant in the viewer's display locale and time zone, through the `datetime` field cell's `formatDateTime`) or `enum` (the label `enum: { value: label }` names; a value the map does not name is drawn as written). A field the row lacks, `null` or empty draws `—`. An empty list draws `emptyLabel`, else the bundle's "No rows to display". A `rows` hole that resolves to anything but a list, or a column the block cannot draw, draws the binding's error panel, never the empty state.
13+
- **`@object-ui/types`: its arm**, `RowTableBlockSchema` with `RowTableColumnSchema` (and the TS twins `RowTableBlockSchema`, `RowTableBlockProps`, `RowTableColumn`), a member of `ProductBlockComponentSchema`, so `objectui validate` claims the type. The arm is strict: an unknown `format`, an `enum` column with no label map, a label map on a column that is not `enum`, a `path` that is not a dotted path, an undeclared key and an empty `columns` are refused. The `dataSource` is the spec's `ElementApiDataSourceSchema`, by reference.
14+
- **`@object-ui/cli`:** `known-schema-types.ts` regenerated with `row-table` and `app-shell:row-table`.
15+
16+
No `@objectstack/spec` change: the type parses through `PageComponentSchema.type`'s open string arm, and `component-type-unknown` claims only colon namespaces. The SDUI manifest does not move (`@object-ui/app-shell` is not one of its registry modules).

‎content/docs/frontend/data-source.mdx‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ the same URL make one request, even when the entry's read settled first:
324324
Outside such a scope nothing is kept beyond the request in flight: a page that
325325
mounts again reads again.
326326

327-
The console's product-page blocks — `hero`, `stat`, `usage-bar`, `checklist` and
328-
`tile-grid` — accept this binding in their arms; see the `@object-ui/app-shell`
329-
README.
327+
The console's product-page blocks — `hero`, `stat`, `usage-bar`, `checklist`,
328+
`tile-grid` and `row-table` — accept this binding in their arms; see the
329+
`@object-ui/app-shell` README. `row-table` draws every row of a list in the
330+
answer as a table: `rows: '${data.actors}'` names the list, and each column
331+
declares a `path` into one row, a `label`, and a `format` of `text`, `datetime`
332+
or `enum`.

‎content/docs/ui/pages.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ The API binding's rules:
399399
- **Same-origin only.** `read.url` must open with a single `/`. An absolute URL of any scheme (`https:`, `mailto:`, `javascript:`, …), a protocol-relative `//host`, a backslash the browser reads as a slash, a space or control character, and a relative path such as `./home` are all refused when the page is parsed (`definePage()`, `os validate`, `os build`), with the reason.
400400
- **No credentials in metadata.** The console reads the endpoint with its own signed-in fetch, so the read block has no `headers`, and a credential key such as `headers`, `credentials` or `token` is refused.
401401
- **Reads only.** `read.method` is optional and accepts `GET` alone; there is no `write` block.
402-
- **Rendered by the console.** The console reads the binding on every page element and binds the selected value as `data`: in the element's expression holes (`${data.used}`), in its `visibleWhen`, and in every element nested inside it. The console's generic `hero`, `stat`, `usage-bar`, `checklist` and `tile-grid` blocks are built to take it as their `dataSource`. While the read is in flight the element shows a loading panel, and a refused binding or a failed read shows an error panel instead.
402+
- **Rendered by the console.** The console reads the binding on every page element and binds the selected value as `data`: in the element's expression holes (`${data.used}`), in its `visibleWhen`, and in every element nested inside it. The console's generic `hero`, `stat`, `usage-bar`, `checklist`, `tile-grid` and `row-table` blocks are built to take it as their `dataSource`; `row-table` lists the rows of an array in the answer as a table, with declared columns (`path`, `label`, and a `format` of `text`, `datetime` or `enum`). While the read is in flight the element shows a loading panel, and a refused binding or a failed read shows an error panel instead.
403403

404404
#### Saved views and the object binding
405405

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

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ See the full table in [ADR-0059](../../docs/adr/0059-action-params-shared-field-
503503

504504
## Product-page blocks
505505

506-
Five generic blocks for the pages a product composes as metadata (a product's
506+
Six generic blocks for the pages a product composes as metadata (a product's
507507
welcome page, a CRM's sales home), registered by this package and named for
508508
what they draw. Each reads its props from the node's `properties`; copy is a
509509
string or an inline translation map (`{ en, "zh-CN" }`), resolved in the
@@ -516,6 +516,7 @@ viewer's language.
516516
| `usage-bar` | how much of a limit is used | `label`, `used`, `limit?` (absent or `0` = unlimited: no bar), `unit?` |
517517
| `checklist` | steps that tick as they are done | `items: [{ label, done, action? }]`, `collapsedWhenDone?` (draw nothing once every step is done) |
518518
| `tile-grid` | the console home's launcher tiles | `items: [{ label, href, icon?, caption? }]`, `addTile?: { label, href }` |
519+
| `row-table` | the rows a bound list holds, as a table | `rows` (a list, or a `${…}` hole naming one), `columns: [{ path, label, format?, enum? }]`, `emptyLabel?` |
519520

520521
Any of them can carry the spec's API binding, and then read values from the
521522
answer through `${…}` holes:
@@ -528,6 +529,32 @@ answer through `${…}` holes:
528529
}
529530
```
530531

532+
`row-table` draws every row, its columns in the order written. A column's
533+
`path` is a dotted path into one row (`owner.name`), its `label` the heading,
534+
and its `format` one of `text` (the default, drawn as written), `datetime` (an
535+
instant in the viewer's display locale and time zone, the `datetime` field
536+
cell's face) or `enum` (the label `enum: { value: label }` names; a value the
537+
map does not name is drawn as written). A field the row lacks, `null` or empty
538+
draws `—`; an empty list draws `emptyLabel` ("No rows to display" when
539+
omitted). A `rows` hole that resolves to anything but a list, or a column the
540+
block cannot draw, draws the binding's error panel instead of an empty table:
541+
542+
```json
543+
{
544+
"type": "row-table",
545+
"dataSource": { "provider": "api", "read": { "url": "/api/v1/ai/actors" }, "path": "data" },
546+
"properties": {
547+
"rows": "${data.actors}",
548+
"columns": [
549+
{ "path": "name", "label": { "en": "Name", "zh-CN": "名称" } },
550+
{ "path": "status", "label": "Status", "format": "enum", "enum": { "active": "Active", "paused": "Paused" } },
551+
{ "path": "lastRun.at", "label": "Last run", "format": "datetime" }
552+
],
553+
"emptyLabel": { "en": "No agents yet" }
554+
}
555+
}
556+
```
557+
531558
The read, its loading and error states, and the `data` root are
532559
`SchemaRenderer`'s (see "Binding a page element to an API endpoint" in the data
533560
source guide). `ConnectedShell` keeps one open's reads (`ElementApiOpenScope`,

‎ui/packages/app-shell/src/console/blocks/__tests__/productBlocks-namespace-13301.test.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ const warnings = vi.hoisted(() => {
3939

4040
import '../productBlocks';
4141

42-
const HOME_BLOCKS = ['hero', 'stat', 'usage-bar', 'checklist', 'tile-grid'] as const;
42+
// `row-table` (#31856) joined the five, registered the same way.
43+
const HOME_BLOCKS = ['hero', 'stat', 'usage-bar', 'checklist', 'tile-grid', 'row-table'] as const;
4344

4445
const DEPRECATED = /Registering component "([^"]+)" without a namespace is deprecated/;
4546

@@ -49,7 +50,7 @@ afterAll(() => {
4950
});
5051

5152
describe('console home blocks register under `app-shell` (objectui#13301)', () => {
52-
it('logs no deprecation line for the five blocks when the module loads', () => {
53+
it('logs no deprecation line for the blocks when the module loads', () => {
5354
const named = warnings.seen
5455
.map((line) => DEPRECATED.exec(line)?.[1])
5556
.filter((type): type is string => Boolean(type));
@@ -94,6 +95,7 @@ describe('a page authoring the bare key still draws each block (objectui#13301)'
9495
['usage-bar', { type: 'usage-bar', properties: { label: 'Storage', used: 256, limit: 1024 } }, 'Storage'],
9596
['checklist', { type: 'checklist', properties: { items: [{ label: 'Create an environment', done: false }] } }, 'Create an environment'],
9697
['tile-grid', { type: 'tile-grid', properties: { items: [{ label: 'CRM', href: '/apps/crm' }] } }, 'CRM'],
98+
['row-table', { type: 'row-table', properties: { rows: [{ name: 'Ada' }], columns: [{ path: 'name', label: 'Name' }] } }, 'Ada'],
9799
];
98100

99101
it.each(pages)('`%s`', (_block, schema, text) => {
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
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+
* `row-table` (#31856): the rows a page `api` binding answers, as a table,
11+
* rendered through the real `SchemaRenderer` with the binding read through the
12+
* host fetch on `SchemaRendererContext.apiFetch`.
13+
*/
14+
15+
import { afterEach, describe, expect, it, vi } from 'vitest';
16+
import { cleanup, render, screen, waitFor, within } from '@testing-library/react';
17+
import React from 'react';
18+
import { MemoryRouter } from 'react-router-dom';
19+
import { ComponentRegistry, formatDateTime, setDisplayTimeZone } from '@object-ui/core';
20+
import { I18nProvider } from '@object-ui/i18n';
21+
import { SchemaRenderer, SchemaRendererContext } from '@object-ui/react';
22+
import type { DeclaredNode } from '@object-ui/types';
23+
import '../productBlocks';
24+
25+
const ACTORS = {
26+
success: true,
27+
data: {
28+
actors: [
29+
{ name: 'Ada', status: 'active', lastRun: { at: '2026-11-09T08:30:00Z' } },
30+
{ name: 'Grace', status: 'paused', lastRun: null },
31+
{ name: 'Linus', status: 'retired' },
32+
],
33+
none: [],
34+
summary: { count: 3 },
35+
},
36+
};
37+
38+
const BINDING = { provider: 'api', read: { url: '/api/v1/ai/actors' }, path: 'data' } as const;
39+
40+
const COLUMNS = [
41+
{ path: 'name', label: { en: 'Name', 'zh-CN': '名称' } },
42+
{ path: 'status', label: 'Status', format: 'enum', enum: { active: { en: 'Active' }, paused: 'Paused' } },
43+
{ path: 'lastRun.at', label: 'Last run', format: 'datetime' },
44+
];
45+
46+
function renderTable(properties: Record<string, unknown>, bound = true) {
47+
const apiFetch = vi.fn(async () => new Response(JSON.stringify(ACTORS), { status: 200 }));
48+
const schema = { type: 'row-table', ...(bound ? { dataSource: BINDING } : {}), properties } as unknown as DeclaredNode;
49+
render(
50+
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }}>
51+
<MemoryRouter>
52+
<SchemaRendererContext.Provider value={{ dataSource: null, apiFetch }}>
53+
<SchemaRenderer schema={schema} />
54+
</SchemaRendererContext.Provider>
55+
</MemoryRouter>
56+
</I18nProvider>,
57+
);
58+
return apiFetch;
59+
}
60+
61+
/** The cell texts of one body row. */
62+
function cells(row: number): string[] {
63+
return within(screen.getByTestId(`row-table-row-${row}`))
64+
.getAllByRole('cell')
65+
.map((cell) => cell.textContent ?? '');
66+
}
67+
68+
afterEach(() => {
69+
cleanup();
70+
setDisplayTimeZone(undefined);
71+
});
72+
73+
describe('row-table (#31856)', () => {
74+
it('registers with declared inputs and the API binding input', () => {
75+
const config = ComponentRegistry.getConfig('row-table');
76+
const names = (config?.inputs ?? []).map((input) => input.name);
77+
expect(names).toEqual(['rows', 'columns', 'emptyLabel', 'dataSource']);
78+
for (const input of config?.inputs ?? []) expect(input.description, input.name).toBeTruthy();
79+
});
80+
81+
it('draws every row the binding answers, its columns in authored order', async () => {
82+
const apiFetch = renderTable({ rows: '${data.actors}', columns: COLUMNS });
83+
await waitFor(() => expect(screen.getByTestId('row-table-row-2')).toBeInTheDocument());
84+
expect(apiFetch).toHaveBeenCalledTimes(1);
85+
expect(screen.getAllByRole('columnheader').map((head) => head.textContent)).toEqual(['Name', 'Status', 'Last run']);
86+
expect(cells(0)[0]).toBe('Ada');
87+
expect(cells(1)[0]).toBe('Grace');
88+
expect(cells(2)[0]).toBe('Linus');
89+
});
90+
91+
it('draws an enum value through its label map, and a value the map does not name as written', async () => {
92+
renderTable({ rows: '${data.actors}', columns: COLUMNS });
93+
await waitFor(() => expect(screen.getByTestId('row-table-row-2')).toBeInTheDocument());
94+
expect(cells(0)[1]).toBe('Active');
95+
expect(cells(1)[1]).toBe('Paused');
96+
expect(cells(2)[1]).toBe('retired');
97+
});
98+
99+
it('draws a datetime as an instant in the display time zone', async () => {
100+
setDisplayTimeZone('Asia/Tokyo');
101+
renderTable({ rows: '${data.actors}', columns: COLUMNS });
102+
await waitFor(() => expect(screen.getByTestId('row-table-row-0')).toBeInTheDocument());
103+
const shown = cells(0)[2];
104+
// The one date-display path, in the declared zone: 08:30Z is 17:30 in Tokyo.
105+
expect(shown).toBe(formatDateTime('2026-11-09T08:30:00Z', { locale: 'en', style: 'compact' }));
106+
expect(shown).toMatch(/17:30|5:30/);
107+
expect(shown).not.toMatch(/08:30|8:30/);
108+
});
109+
110+
it('draws "—" for a field the row lacks or holds null', async () => {
111+
renderTable({ rows: '${data.actors}', columns: COLUMNS });
112+
await waitFor(() => expect(screen.getByTestId('row-table-row-2')).toBeInTheDocument());
113+
expect(cells(1)[2]).toBe('—');
114+
expect(cells(2)[2]).toBe('—');
115+
});
116+
117+
it('draws the authored empty label for an empty list, else the bundle\'s', async () => {
118+
renderTable({ rows: '${data.none}', columns: COLUMNS, emptyLabel: { en: 'No agents yet' } });
119+
expect((await screen.findByTestId('row-table-empty')).textContent).toBe('No agents yet');
120+
cleanup();
121+
renderTable({ rows: [], columns: COLUMNS }, false);
122+
expect(screen.getByTestId('row-table-empty').textContent).toBe('No rows to display');
123+
});
124+
125+
it('refuses a hole that resolves to a non-list with the error panel, never the empty state', async () => {
126+
renderTable({ rows: '${data.summary}', columns: COLUMNS, emptyLabel: 'No agents yet' });
127+
const panel = await screen.findByTestId('row-table-datasource-error');
128+
expect(panel).toHaveAttribute('role', 'alert');
129+
expect(panel.textContent).toContain('rows resolved to an object');
130+
expect(screen.queryByTestId('row-table-empty')).toBeNull();
131+
});
132+
133+
it('refuses a column format it does not draw with the error panel', () => {
134+
renderTable({ rows: [{ name: 'Ada' }], columns: [{ path: 'name', label: 'Name', format: 'currency' }] }, false);
135+
const panel = screen.getByTestId('row-table-datasource-error');
136+
expect(panel.textContent).toContain('columns[0].format "currency"');
137+
expect(screen.queryByTestId('row-table-block')).toBeNull();
138+
});
139+
});

0 commit comments

Comments
 (0)