Skip to content

Commit f9c12f6

Browse files
committed
feat(app-shell): the page designer's add-block picker offers the list view block
The list-view block has had an inspector panel (Object, View, Row limit) but no BLOCK_TYPE_META row, so the add-block picker never offered it. Add the row under the data category with its type label (en + zh, studio namespace), drop the PANEL_WITHOUT_PALETTE exemption the coverage test carried for it, and pin the picker -> canvas -> inspector path in a new test. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jVDGfqqDsAhmZbg6aF
1 parent 6090bb7 commit f9c12f6

6 files changed

Lines changed: 173 additions & 23 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/i18n': patch
4+
---
5+
6+
feat(app-shell): the page designer's add-block picker offers the list view block
7+
8+
Clause-②: no
9+
Metadata-protocol: none
10+
11+
The page designer could edit a `list-view` block a page already carried (its Object, View and Row limit panel), but its add-block picker had no row for it, so a designer could not add one.
12+
13+
- **Offered under Data**, beside Table, Form, Metric and Kanban, named "List view" (Chinese: 列表视图).
14+
- **A fresh block carries no binding.** Picking it writes `{ type: 'list-view' }` and selects it, which opens the Object, View and Row limit panel. Until the Object control writes `dataSource.object`, the list shows its existing hint asking for an object.
15+
- No key is declared anywhere, and nothing an author already wrote changes.
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26794 — the page designer's add-block picker offers `list-view`.
5+
*
6+
* objectstack#26703 gave the `list-view` block an inspector panel (Object, View,
7+
* Row limit), but the picker is built from `BLOCK_TYPE_META` alone and had no
8+
* `list-view` row, so a designer could edit a list block a page already carried
9+
* and never add one. These cases drive the REAL picker in `PageBlockCanvas`:
10+
* the row sits under the Data heading, picking it writes a bare `list-view`
11+
* node and selects it, and that selection, handed to the REAL inspector with
12+
* the draft the canvas wrote, opens the three controls with nothing bound yet.
13+
*/
14+
15+
import * as React from 'react';
16+
import { describe, it, expect, vi, afterEach } from 'vitest';
17+
import { render, screen, fireEvent, cleanup, within } from '@testing-library/react';
18+
import { PageSchema } from '@objectstack/spec/ui';
19+
import { PageBlockCanvas } from './PageBlockCanvas';
20+
import { PageBlockInspector } from '../inspectors/PageBlockInspector';
21+
import { CATEGORY_LABEL_KEY } from './block-types';
22+
import { t } from '../i18n';
23+
import type { MetadataSelection } from '../preview-registry';
24+
25+
vi.mock('./useObjectFields', () => ({
26+
useObjectFields: () => ({ fields: [], loading: false, error: null }),
27+
}));
28+
// No object catalog: the Object picker falls back to its labelled text box.
29+
vi.mock('../useMetadata', () => ({
30+
useMetadataClient: () => ({ get: vi.fn(async () => undefined), list: vi.fn(async () => [] as unknown[]) }),
31+
}));
32+
33+
// The new type label and the inspector rows live in `@object-ui/i18n`'s
34+
// `studio` namespace, whose `zh` catalogue is fetched on demand
35+
// (objectstack#25922). Resident before any case, so zh reads synchronously.
36+
import { loadStudioCatalogue } from '@object-ui/i18n/namespaces/studio';
37+
await loadStudioCatalogue('zh');
38+
39+
afterEach(cleanup);
40+
41+
type Draft = Record<string, unknown>;
42+
43+
const EMPTY_PAGE: Draft = {
44+
name: 'home',
45+
label: 'Home',
46+
type: 'home',
47+
template: 'default',
48+
regions: [{ name: 'main', components: [] }],
49+
};
50+
51+
/** Mounts the canvas over `EMPTY_PAGE` and records the drafts and selections it produces. */
52+
function renderCanvas(locale: string) {
53+
const drafts: Draft[] = [];
54+
const selections: Array<MetadataSelection | null> = [];
55+
function Harness() {
56+
const [draft, setDraft] = React.useState<Draft>(EMPTY_PAGE);
57+
return (
58+
<PageBlockCanvas
59+
draft={draft}
60+
locale={locale}
61+
onPatch={(patch) => {
62+
const next = { ...draft, ...patch };
63+
drafts.push(next);
64+
setDraft(next);
65+
}}
66+
onSelectionChange={(next) => selections.push(next)}
67+
/>
68+
);
69+
}
70+
render(<Harness />);
71+
return { drafts, selections };
72+
}
73+
74+
/** Opens the first region's picker and returns the `list-view` row and the heading of the group it sits in. */
75+
function openPickerAtListView(locale: string): { row: HTMLButtonElement; heading: string } {
76+
const [add] = screen.getAllByRole('button', { name: t('engine.inspector.add.block', locale) });
77+
fireEvent.click(add);
78+
const code = screen.getAllByText('list-view').find((el) => el.tagName === 'CODE');
79+
expect(code, 'the picker offers a `list-view` row').toBeDefined();
80+
const row = code!.closest('button') as HTMLButtonElement;
81+
const group = row.parentElement!;
82+
return { row, heading: group.firstElementChild!.textContent ?? '' };
83+
}
84+
85+
describe('the add-block picker offers list-view (objectstack#26794)', () => {
86+
it('lists it under the Data heading, named in the designer locale', () => {
87+
for (const locale of ['en-US', 'zh-CN']) {
88+
const { row, heading } = openPickerAtListView(locale);
89+
expect(heading).toBe(t(CATEGORY_LABEL_KEY.data, locale));
90+
expect(within(row).getByText(t('engine.pageBlockCanvas.type.listView', locale))).toBeTruthy();
91+
cleanup();
92+
}
93+
// Control: the zh row is a translation, not the en name read through.
94+
expect(t('engine.pageBlockCanvas.type.listView', 'zh-CN')).not.toBe(t('engine.pageBlockCanvas.type.listView', 'en-US'));
95+
});
96+
97+
it('adding it writes a bare list-view node the spec accepts, and selects it', () => {
98+
const { drafts, selections } = renderCanvas('en-US');
99+
fireEvent.click(openPickerAtListView('en-US').row);
100+
101+
const written = drafts.at(-1)!;
102+
expect((written.regions as Array<{ components: unknown[] }>)[0].components).toEqual([{ type: 'list-view' }]);
103+
expect(PageSchema.safeParse(written).success).toBe(true);
104+
expect(selections.at(-1)).toMatchObject({ kind: 'block', id: 'regions[0].components[0]' });
105+
});
106+
107+
it('selecting the added block opens the Object, View and Row limit panel, nothing bound yet', () => {
108+
const { drafts, selections } = renderCanvas('en-US');
109+
fireEvent.click(openPickerAtListView('en-US').row);
110+
const draft = drafts.at(-1)!;
111+
const selection = selections.at(-1)!;
112+
cleanup();
113+
114+
const onPatch = vi.fn();
115+
render(
116+
<PageBlockInspector
117+
type="page"
118+
name="home"
119+
draft={draft}
120+
selection={selection}
121+
onPatch={onPatch}
122+
onClearSelection={() => {}}
123+
readOnly={false}
124+
locale="en-US"
125+
/>,
126+
);
127+
const object = screen.getByLabelText('Object') as HTMLInputElement;
128+
const view = screen.getByLabelText('View') as HTMLInputElement;
129+
const limit = screen.getByLabelText('Row limit') as HTMLInputElement;
130+
expect([object.value, view.value, limit.value]).toEqual(['', '', '']);
131+
expect(limit.placeholder).toBe('5');
132+
133+
// The Object control is how the fresh block gets its object: it writes the
134+
// node-level `dataSource` binding the list reads.
135+
fireEvent.change(object, { target: { value: 'contact' } });
136+
const block = (onPatch.mock.calls.at(-1)![0] as { regions: Array<{ components: Array<Record<string, unknown>> }> })
137+
.regions[0].components[0];
138+
expect(block).toEqual({ type: 'list-view', dataSource: { object: 'contact' } });
139+
});
140+
});

‎ui/packages/app-shell/src/views/metadata-admin/previews/__tests__/block-config.test.ts‎

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -257,11 +257,6 @@ describe('record:details sections ↔ spec section-entry coverage (#3819)', () =
257257
* from the enum instead, so every value must be an explicit decision —
258258
* offered, or excluded with a documented reason.
259259
*/
260-
/** Blocks with a config panel and no palette entry, each with why it is still authorable. */
261-
const PANEL_WITHOUT_PALETTE: Readonly<Record<string, string>> = {
262-
'list-view': 'a public block that published pages place; the panel edits the node a page already carries (objectstack#26703)',
263-
};
264-
265260
describe('page palette ↔ spec PageComponentType coverage', () => {
266261
const specNames: string[] = enumOptions(PageComponentType);
267262

@@ -350,28 +345,13 @@ describe('page palette ↔ spec PageComponentType coverage', () => {
350345
// is the question this case asks, so the palette is the only thing it
351346
// reads — `TYPES_BY_CATEGORY`, the list the page canvas's picker renders.
352347
//
353-
// `PANEL_WITHOUT_PALETTE` names the blocks that are authorable WITHOUT the
354-
// palette, each with the stored documents that carry it, so a panel for one
355-
// is an edit of a real node rather than an advert for an unauthorable one.
356-
// `list-view` (objectstack#26703): a public block (`core/src/registry/
357-
// public-blocks.ts`) that published pages place, such as
358-
// `packages/objectql/src/__fixtures__/hotcrm-4.0.1-published-pages.artifact.json`,
359-
// and whose row cap the designer could otherwise set only in JSON.
348+
// No exemption: `list-view` had a panel and no palette row from
349+
// objectstack#26703 until objectstack#26794 offered it.
360350
const offered = new Set<string>(TYPES_BY_CATEGORY.flatMap((g) => g.types));
361-
const orphanPanels = Object.keys(BLOCK_CONFIG).filter((t) => !offered.has(t) && !(t in PANEL_WITHOUT_PALETTE));
351+
const orphanPanels = Object.keys(BLOCK_CONFIG).filter((t) => !offered.has(t));
362352
expect(orphanPanels, 'these expose a config panel but cannot be authored').toEqual([]);
363353
});
364354

365-
it('every palette-less panel is still palette-less and still has a panel', () => {
366-
// Self-deleting, like the schema-parity EXEMPT rows: the day the palette
367-
// offers the block, or its panel goes, the row must go too.
368-
const offered = new Set<string>(TYPES_BY_CATEGORY.flatMap((g) => g.types));
369-
for (const type of Object.keys(PANEL_WITHOUT_PALETTE)) {
370-
expect(offered.has(type), `'${type}' is offered now — delete its row`).toBe(false);
371-
expect(blockHasConfig(type), `'${type}' has no panel — delete its row`).toBe(true);
372-
}
373-
});
374-
375355
describe("record:quick_actions `location` — the designer's action-location dropdown", () => {
376356
const locationField = () =>
377357
BLOCK_CONFIG['record:quick_actions'].find((f) => f.name === 'location') as

‎ui/packages/app-shell/src/views/metadata-admin/previews/block-types.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@ import {
4444
Gauge,
4545
Columns3,
4646
LayoutGrid,
47+
LayoutList,
4748
type LucideIcon,
4849
} from 'lucide-react';
4950

5051
export type BlockTypeId =
5152
// data — object-bound views & layout grid (the high-traffic app-page blocks)
5253
| 'grid' | 'object-grid' | 'object-form' | 'object-metric' | 'object-kanban'
54+
| 'list-view'
5355
// page:*
5456
| 'page:header' | 'page:footer' | 'page:sidebar' | 'page:tabs'
5557
| 'page:accordion' | 'page:card' | 'page:section'
@@ -91,6 +93,11 @@ export const BLOCK_TYPE_META: Record<BlockTypeId, Omit<BlockTypeMeta, 'id'>> = {
9193
'object-form': { label: 'Form', labelKey: 'engine.pageBlockCanvas.type.objectForm', category: 'data', Icon: FormInput },
9294
'object-metric': { label: 'Metric', labelKey: 'engine.pageBlockCanvas.type.objectMetric', category: 'data', Icon: Gauge },
9395
'object-kanban': { label: 'Kanban', labelKey: 'engine.pageBlockCanvas.type.objectKanban', category: 'data', Icon: Columns3 },
96+
// A public block (`core/src/registry/public-blocks.ts`) whose panel sets its
97+
// object, view and row cap (`BLOCK_CONFIG['list-view']`). A fresh one carries
98+
// no `dataSource`: the list draws a hint asking for its object until the
99+
// panel's Object control writes `dataSource.object` (objectstack#26794).
100+
'list-view': { label: 'List view', labelKey: 'engine.pageBlockCanvas.type.listView', category: 'data', Icon: LayoutList },
94101

95102
// Page layout
96103
'page:header': { label: 'Header', labelKey: 'engine.pageBlockCanvas.type.pageHeader', category: 'layout', Icon: PanelTop },

‎ui/packages/i18n/src/namespaces/studio/en.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -730,6 +730,10 @@ const STUDIO_EN: Record<string, string> = {
730730
'engine.inspector.pageBlock.field.list-view.object': 'Object',
731731
'engine.inspector.pageBlock.field.list-view.view': 'View',
732732
'engine.inspector.pageBlock.field.list-view.limit': 'Row limit',
733+
// The add-block picker's name for the block whose panel the three rows above
734+
// label; its sibling `engine.pageBlockCanvas.type.*` rows are still in the
735+
// designer table, app-shell `views/metadata-admin/i18n.ts` (objectstack#26794).
736+
'engine.pageBlockCanvas.type.listView': 'List view',
733737
'engine.inspector.pageBlock.field.grid.columns': 'Columns',
734738
'engine.inspector.pageBlock.field.grid.gap': 'Gap',
735739
'engine.inspector.pageBlock.field.element:text.content': 'Content',

‎ui/packages/i18n/src/namespaces/studio/zh.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,10 @@ const STUDIO_ZH: Record<string, string> = {
624624
'engine.inspector.pageBlock.field.list-view.object': '对象',
625625
'engine.inspector.pageBlock.field.list-view.view': '视图',
626626
'engine.inspector.pageBlock.field.list-view.limit': '条数上限',
627+
// The add-block picker's name for the block whose panel the three rows above
628+
// label; its sibling `engine.pageBlockCanvas.type.*` rows are still in the
629+
// designer table, app-shell `views/metadata-admin/i18n.ts` (objectstack#26794).
630+
'engine.pageBlockCanvas.type.listView': '列表视图',
627631
'engine.inspector.pageBlock.field.grid.columns': '列数',
628632
'engine.inspector.pageBlock.field.grid.gap': '间距',
629633
'engine.inspector.pageBlock.field.element:text.content': '内容',

0 commit comments

Comments
 (0)