Skip to content

Commit 42add54

Browse files
committed
feat(app-shell): the page designer can set a list block's object, view and row cap
A list-view block had no BLOCK_CONFIG entry, so its inspector showed no typed fields and its row cap (dataSource.limit) could be set only in JSON. Add Object, View and Row limit controls that write the node-level dataSource binding, with en and zh labels. Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jTqu1ZbUqjnAJufZ8m
1 parent 74db43e commit 42add54

6 files changed

Lines changed: 160 additions & 5 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
---
4+
5+
feat(app-shell): the page designer can set a list block's object, view and row cap
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
Selecting a `list-view` block in the page designer used to open an inspector with no typed fields. Its row cap, the number of rows a list block in a wide page region draws (5 when none is stated), could be set only by editing the page's JSON, because the "Advanced" section lists only keys the block already has.
11+
12+
- **Three controls.** Object, View and Row limit. They write the block's `dataSource` binding (`dataSource.object`, `dataSource.view`, `dataSource.limit`), the keys the list block already reads. The Row limit box hints `5` when empty.
13+
- **Labels in both designer locales**, English and Chinese.
14+
- No new key is declared anywhere, and nothing an author already wrote changes. The palette still does not offer `list-view`: the controls edit list blocks a page already carries.

‎ui/packages/app-shell/src/views/metadata-admin/i18n.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -896,6 +896,9 @@ const ENGINE_STRINGS_EN: Record<string, string> = {
896896
'engine.inspector.pageBlock.field.object-kanban.titleField': 'Title field',
897897
'engine.inspector.pageBlock.field.object-kanban.cardFields': 'Card fields',
898898
'engine.inspector.pageBlock.field.object-kanban.limit': 'Limit',
899+
'engine.inspector.pageBlock.field.list-view.object': 'Object',
900+
'engine.inspector.pageBlock.field.list-view.view': 'View',
901+
'engine.inspector.pageBlock.field.list-view.limit': 'Row limit',
899902
'engine.inspector.pageBlock.field.grid.columns': 'Columns',
900903
'engine.inspector.pageBlock.field.grid.gap': 'Gap',
901904
'engine.inspector.pageBlock.field.element:text.content': 'Content',
@@ -4182,6 +4185,9 @@ const ENGINE_STRINGS_ZH: Record<string, string> = {
41824185
'engine.inspector.pageBlock.field.object-kanban.titleField': '标题字段',
41834186
'engine.inspector.pageBlock.field.object-kanban.cardFields': '卡片字段',
41844187
'engine.inspector.pageBlock.field.object-kanban.limit': '条数上限',
4188+
'engine.inspector.pageBlock.field.list-view.object': '对象',
4189+
'engine.inspector.pageBlock.field.list-view.view': '视图',
4190+
'engine.inspector.pageBlock.field.list-view.limit': '条数上限',
41854191
'engine.inspector.pageBlock.field.grid.columns': '列数',
41864192
'engine.inspector.pageBlock.field.grid.gap': '间距',
41874193
'engine.inspector.pageBlock.field.element:text.content': '内容',
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* objectstack#26703 — the page designer can set a `list-view` block's row cap.
5+
*
6+
* A list block in a wide page region draws its first `dataSource.limit` rows,
7+
* 5 when none is stated (objectstack#26613). `BLOCK_CONFIG` had no `list-view`
8+
* entry, so selecting one opened an inspector with no typed fields, and the
9+
* "Advanced" section lists only keys the block already has: the cap could be
10+
* set only in JSON. These rows drive the REAL inspector and assert the patch
11+
* it hands the editor: the Object, View and Row limit controls write the
12+
* node-level `dataSource` binding `ListViewBlock` reads, never `properties`.
13+
*/
14+
15+
import { describe, it, expect, vi, afterEach, type Mock } from 'vitest';
16+
import { render, screen, fireEvent, cleanup } from '@testing-library/react';
17+
import { PageSchema } from '@objectstack/spec/ui';
18+
import { PageBlockInspector } from './PageBlockInspector';
19+
import type { MetadataInspectorProps } from '../inspector-registry';
20+
21+
vi.mock('../previews/useObjectFields', () => ({
22+
useObjectFields: () => ({ fields: [], loading: false, error: null }),
23+
}));
24+
// No object catalog: the Object picker falls back to its labelled text box.
25+
vi.mock('../useMetadata', () => ({
26+
useMetadataClient: () => ({ get: vi.fn(async () => undefined), list: vi.fn(async () => [] as unknown[]) }),
27+
}));
28+
29+
afterEach(cleanup);
30+
31+
const BLOCK_PATH = 'regions[0].components[0]';
32+
33+
/** Author a page the way a user does, parse it with the spec, and hand the RESULT to the inspector. */
34+
function pageDraft(block: Record<string, unknown>): Record<string, unknown> {
35+
return PageSchema.parse({
36+
name: 'home',
37+
label: 'Home',
38+
type: 'home',
39+
template: 'default',
40+
regions: [{ name: 'main', components: [{ id: 'b1', ...block }] }],
41+
}) as unknown as Record<string, unknown>;
42+
}
43+
44+
function renderInspector(draft: Record<string, unknown>, locale = 'en-US'): Mock<MetadataInspectorProps['onPatch']> {
45+
const onPatch: Mock<MetadataInspectorProps['onPatch']> = vi.fn();
46+
render(
47+
<PageBlockInspector
48+
type="page"
49+
name="home"
50+
draft={draft}
51+
selection={{ kind: 'block', id: BLOCK_PATH }}
52+
onPatch={onPatch}
53+
onClearSelection={() => {}}
54+
readOnly={false}
55+
locale={locale}
56+
/>,
57+
);
58+
return onPatch;
59+
}
60+
61+
/** The block as the inspector last wrote it (the patch is shallow: `{ regions }`). */
62+
const committedBlock = (onPatch: Mock<MetadataInspectorProps['onPatch']>): Record<string, unknown> =>
63+
(onPatch.mock.calls.at(-1)![0] as { regions: Array<{ components: Array<Record<string, unknown>> }> }).regions[0]
64+
.components[0];
65+
66+
describe('the designer sets a list-view block’s row cap (objectstack#26703)', () => {
67+
it('shows an editable Row limit box, hinting the capped list’s own 5 when empty', () => {
68+
renderInspector(pageDraft({ type: 'list-view', dataSource: { object: 'contact' } }));
69+
const limit = screen.getByLabelText('Row limit') as HTMLInputElement;
70+
expect(limit.type).toBe('number');
71+
expect(limit.value).toBe('');
72+
expect(limit.placeholder).toBe('5');
73+
expect(limit.disabled).toBe(false);
74+
});
75+
76+
it('editing the box writes `dataSource.limit` beside the bound object, not `properties.limit`', () => {
77+
const onPatch = renderInspector(pageDraft({ type: 'list-view', dataSource: { object: 'contact', view: 'mine' }, properties: {} }));
78+
fireEvent.change(screen.getByLabelText('Row limit'), { target: { value: '12' } });
79+
const block = committedBlock(onPatch);
80+
expect(block.dataSource).toEqual({ object: 'contact', view: 'mine', limit: 12 });
81+
expect(block.properties).toEqual({});
82+
});
83+
84+
it('the box shows a stored cap, and the Object and View controls show and write the binding', () => {
85+
const onPatch = renderInspector(pageDraft({ type: 'list-view', dataSource: { object: 'contact', view: 'mine', limit: 8 } }));
86+
expect((screen.getByLabelText('Row limit') as HTMLInputElement).value).toBe('8');
87+
expect((screen.getByLabelText('Object') as HTMLInputElement).value).toBe('contact');
88+
expect((screen.getByLabelText('View') as HTMLInputElement).value).toBe('mine');
89+
fireEvent.change(screen.getByLabelText('View'), { target: { value: 'all_open' } });
90+
expect(committedBlock(onPatch).dataSource).toEqual({ object: 'contact', view: 'all_open', limit: 8 });
91+
});
92+
93+
it('labels the controls in the designer locale', () => {
94+
renderInspector(pageDraft({ type: 'list-view', dataSource: { object: 'contact' } }), 'zh-CN');
95+
expect(screen.getByLabelText('条数上限')).toBeTruthy();
96+
expect(screen.getByLabelText('视图')).toBeTruthy();
97+
});
98+
});

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,10 @@ describe('placeholders that must NOT be translated (#3979)', () => {
392392
because: "a row limit — DEFAULT_KANBAN_FETCH_BATCH_SIZE, the board's fetch batch when the box is empty",
393393
},
394394
'record:details.sections.columns': { literal: '2', because: 'a column count' },
395+
'list-view.limit': { literal: '5', because: "a row limit — the capped list's row count when the box is empty" },
395396
};
396397

397-
it('collects all 17 placeholders — 6 keyed, 11 literal', () => {
398+
it('collects all 18 placeholders — 6 keyed, 12 literal', () => {
398399
// Guards the walk: if placeholder collection silently found nothing, every
399400
// assertion here would pass over an empty list.
400401
//
@@ -406,10 +407,12 @@ describe('placeholders that must NOT be translated (#3979)', () => {
406407
// `DEFAULT_KANBAN_FETCH_BATCH_SIZE`), so it lands on the literal side and the keyed
407408
// half is what stays untouched this time. Then 18 / 7 / 11 until
408409
// objectui#8280 removed the `ai:input` panel, whose `agentName` box was a
409-
// KEYED placeholder — the palette never offered that block.
410-
expect(PLACEHOLDERS.length).toBe(17);
410+
// KEYED placeholder — the palette never offered that block. Then 17 / 6 / 11
411+
// until objectstack#26703 gave `list-view` its row-cap box, a VALUE
412+
// placeholder (`5`, the capped list's own count).
413+
expect(PLACEHOLDERS.length).toBe(18);
411414
expect(PLACEHOLDERS.filter((p) => p.spec.key !== undefined).length).toBe(6);
412-
expect(PLACEHOLDERS.filter((p) => p.spec.literal !== undefined).length).toBe(11);
415+
expect(PLACEHOLDERS.filter((p) => p.spec.literal !== undefined).length).toBe(12);
413416
});
414417

415418
it('every placeholder declares exactly one of key / literal', () => {

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

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,11 @@ describe('record:details sections ↔ spec section-entry coverage (#3819)', () =
252252
* from the enum instead, so every value must be an explicit decision —
253253
* offered, or excluded with a documented reason.
254254
*/
255+
/** Blocks with a config panel and no palette entry, each with why it is still authorable. */
256+
const PANEL_WITHOUT_PALETTE: Readonly<Record<string, string>> = {
257+
'list-view': 'a public block that published pages place; the panel edits the node a page already carries (objectstack#26703)',
258+
};
259+
255260
describe('page palette ↔ spec PageComponentType coverage', () => {
256261
const specNames: string[] = enumOptions(PageComponentType);
257262

@@ -339,11 +344,29 @@ describe('page palette ↔ spec PageComponentType coverage', () => {
339344
// curated panel and no way to author it (objectui#8280). Palette membership
340345
// is the question this case asks, so the palette is the only thing it
341346
// reads — `TYPES_BY_CATEGORY`, the list the page canvas's picker renders.
347+
//
348+
// `PANEL_WITHOUT_PALETTE` names the blocks that are authorable WITHOUT the
349+
// palette, each with the stored documents that carry it, so a panel for one
350+
// is an edit of a real node rather than an advert for an unauthorable one.
351+
// `list-view` (objectstack#26703): a public block (`core/src/registry/
352+
// public-blocks.ts`) that published pages place, such as
353+
// `packages/objectql/src/__fixtures__/hotcrm-4.0.1-published-pages.artifact.json`,
354+
// and whose row cap the designer could otherwise set only in JSON.
342355
const offered = new Set<string>(TYPES_BY_CATEGORY.flatMap((g) => g.types));
343-
const orphanPanels = Object.keys(BLOCK_CONFIG).filter((t) => !offered.has(t));
356+
const orphanPanels = Object.keys(BLOCK_CONFIG).filter((t) => !offered.has(t) && !(t in PANEL_WITHOUT_PALETTE));
344357
expect(orphanPanels, 'these expose a config panel but cannot be authored').toEqual([]);
345358
});
346359

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,17 @@ export const BLOCK_CONFIG: Record<string, BlockPropField[]> = {
257257
// `DEFAULT_KANBAN_FETCH_BATCH_SIZE`, the value that applies when the box is empty.
258258
{ name: 'limit', label: 'engine.inspector.pageBlock.field.object-kanban.limit', kind: 'number', placeholder: { literal: '100' } },
259259
],
260+
// The page `list-view` block reads its query from the node-level `dataSource`
261+
// binding (`ListViewBlock`, plugin-list): `object` lands on `objectName`,
262+
// `view` names the saved view, and `limit` is its row cap, which a list in a
263+
// wide page region draws as its first rows (objectstack#26613). So all three
264+
// controls write `dataSource.*`, the way `element:repeater`'s do below.
265+
// `{ literal: '5' }` is the capped list's own count when no limit is stated.
266+
'list-view': [
267+
{ name: 'object', label: 'engine.inspector.pageBlock.field.list-view.object', kind: 'object-picker', at: 'dataSource' },
268+
{ name: 'view', label: 'engine.inspector.pageBlock.field.list-view.view', kind: 'text', at: 'dataSource' },
269+
{ name: 'limit', label: 'engine.inspector.pageBlock.field.list-view.limit', kind: 'number', placeholder: { literal: '5' }, at: 'dataSource' },
270+
],
260271

261272
// ── Layout grid ───────────────────────────────────────────────────────────
262273
grid: [

0 commit comments

Comments
 (0)