Skip to content

Commit 1e8e529

Browse files
fix(ui): the page designer canvas draws an authored record:details select and location the way the record page does (#27253)
<!-- claude-projects-attribution: {"github_login":"os-warren"} --> _Requested by **Warren** · [project thread](https://claude.ai/code/project/chan_01U5RdnAAmkSQmZbqh6FtqZ8?thread=cmsg_01U5RdnAAmkSQmZbqh6FtqZ8FZSndfpnCtDUC82v4JroZg)_ Fixes #27177 Clause-②: no Metadata-protocol: none ## 维护者速读 - 改了什么:Studio 页面设计器的 Design 画布上,作者写明字段名的 `record:details` 现在把 `select` 显示成选项标签、把 `location` 显示成坐标,不再是原始值 `amer` 和 `[Object]`,与运行时记录页一致。 - 为什么改:画布挂的就是运行时的 `record:details`,但 Studio 不给 dataSource,`DetailView` 只能从 dataSource 拿对象定义,于是只写字段名的条目没有类型,画成原始值;对象定义其实已在画布的记录上下文里。 - 风险与回滚:只在 `recordFromHost` 且 dataSource 尚未答复时借用上下文里的对象定义;有 dataSource 时它的答复照旧优先,不新增任何请求,没有上下文或不走 `recordFromHost` 的 `DetailView` 输出不变(测试钉住);回滚即 revert 本 PR。 - 先看:`ui/packages/plugin-detail/src/DetailView.tsx`(`hostObjectSchema` 那三行)、`ui/packages/app-shell/src/views/metadata-admin/previews/PagePreview.authoredDetailsValues-27177.test.tsx`。 - 两分钟验证:`pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/previews/PagePreview.authoredDetailsValues-27177.test.tsx packages/plugin-detail/src/__tests__/DetailView.hostObjectSchema-27177.test.tsx`,预期 5 个测试全绿。 - 需要你做的:无,席位落地。 ## What changes 1. **`DetailView` takes field types from the host's object schema when the host supplies the record.** `DetailView` learned field types only from `dataSource.getObjectSchema`. Under `recordFromHost` (which `record:details` sets) it now reads the record context's `objectSchema` as well, and uses it until a dataSource answer arrives: `objectSchema = dataSourceObjectSchema ?? (recordFromHost ? hostObjectSchema ?? null : null)`. A dataSource answer still wins, nothing new is fetched, no prop is added, and a `DetailView` with no record context, or one that reads its own record, draws as before. 2. **Changeset:** `.changeset/27177-detail-host-object-schema.md`, `patch` for `@object-ui/plugin-detail`. ## Why The card's premise holds: on the Design canvas a `full` record page whose `record:details` names its fields drew a `select` as its stored code and a `location` as `[Object]`. The dispatch order assumed a canvas-side value-render site under `views/metadata-admin/previews/`; measuring disproved that. `PagePreview` wraps `PageBlockCanvas` in `RecordContextProvider` with the bound object's `/meta` schema and no dataSource (as every Studio preview does), and the canvas mounts the runtime `record:details` renderer itself, so the triage ruling ("the canvas reuses the runtime's field renderers; it does not get its own formatter") was already true. What the canvas lacked was the field metadata: the full-create seed writes `sections[].fields` as bare names, a bare-name entry carries no `type`, and `DetailSection` resolves the type from `objectSchema`, which stayed null without a dataSource. The slotted default looked right because its synthesized sections carry typed field objects; the record page looked right because it has a dataSource. The seat ruled the route on the card (order amendment 6468231446): fix it in `DetailView`, no new prop, no stub dataSource. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (`packages/spec` not touched.) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes (ESLint on the three changed source and test files: 0 errors; the repo-wide run is CI's). - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English, except the 维护者速读 section, which the dispatch order requires in Chinese. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. ## Tests - `ui/packages/app-shell/src/views/metadata-admin/previews/PagePreview.authoredDetailsValues-27177.test.tsx` (2): the full-create seed names its detail fields by bare name (premise pin); on the real Design canvas (real `PageBlockCanvas`, record context, `record:details`, `DetailView` and cell renderers; only the two endpoints `PagePreview` reads are doubled) the bound `record:details` body draws `Americas` for `sales_region: 'amer'` and `37.7749, -122.4194` for a `location`, never `amer` or `[Object]`; CONTROL inside it: a plain `text` field reads as stored. - `ui/packages/plugin-detail/src/__tests__/DetailView.hostObjectSchema-27177.test.tsx` (3): with no dataSource, a `recordFromHost` view under a record context draws the option label and the coordinates; CONTROL: with a dataSource, its answer wins over the host schema and is read once (no record read); CONTROL: with no record context, or without `recordFromHost`, the view draws the raw value exactly as before. ## Acceptance notes - The fix lives in `@object-ui/plugin-detail`, outside the order's original file surface; the seat widened the surface to `DetailView.tsx` plus the changeset before the first edit (order amendment 6468231446). - The controls pin that a `DetailView` with no context still draws a bare-name `select` raw. That is the behaviour of a host that hands no object schema at all, unchanged on purpose. ## Verification All readings on head `d8123be0` (branch tip after merging `origin/main`) unless noted. <details><summary>New tests and wider suites</summary> - New files: 2 files, 5 tests, all pass. - `pnpm --dir ui exec vitest run packages/plugin-detail/` under the verify lock: Test Files 325 passed, 1 skipped (326); Tests 2971 passed, 18 skipped; VERDICT command-exit 0. - `pnpm --dir ui exec vitest run packages/app-shell/src/views/metadata-admin/previews/` under the verify lock: Test Files 150 passed (150); Tests 1683 passed (1683); VERDICT command-exit 0. - Type check: `pnpm --filter @object-ui/plugin-detail type-check` and `pnpm --filter @object-ui/app-shell type-check` each exit 0 (after the closure build `--filter '@object-ui/app-shell^...'`, VERDICT command-exit 0, and a `@object-ui/plugin-detail` rebuild after the merge). - ESLint on the three changed files: 0 errors (warnings are the files' existing `any` lines and the test doubles' `as any`, as in the sibling tests). - `pnpm --dir ui run check:new-line-citations`: 0 new citations. </details> <details><summary>Ablation (restored, blob equal to HEAD, git diff HEAD empty)</summary> Run with `node scripts/ablation-replace.mjs` on the committed fix; the anchor hit once and the mutation landed on disk (blob b9030ab to 2d33b607). Both test files resolve `@object-ui/plugin-detail` and `@object-ui/react` to source through the vitest alias, so no dist leg. - `const objectSchema = dataSourceObjectSchema ?? (recordFromHost ? hostObjectSchema ?? null : null);` replaced by `const objectSchema = dataSourceObjectSchema;` turns 2 tests red (the canvas test, the no-dataSource DetailView test); the premise pin and both controls stay green. </details> <details><summary>Gates</summary> `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack` derives 34 families on this change set. Each ran on `d8123be0` with its exit code captured before any pipe: 34 of 34 exit 0. `dispatch-gates --ran`: 34 derived, 34 run, 0 NOT-MEASURED. `dispatch-gates --tier`: no path-derived mandate. </details> 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01JQwxbYUSW5btC4i3GbWXGe --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent c63ce2a commit 1e8e529

4 files changed

Lines changed: 298 additions & 2 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(ui): the page designer canvas draws an authored `record:details` body's `select` and `location` values the way the record page does (#27177)
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On the page designer's Design canvas, a `full` record page whose `record:details` block names its fields drew a `select` value as its stored code (`amer` instead of `Americas`) and a `location` value as the literal `[Object]`. The record page itself was right.
11+
12+
`DetailView` learned field types only from its dataSource (`getObjectSchema`). The canvas mounts the record page's own `record:details` renderer under a record context that holds the bound object's schema but no dataSource, so a field named by bare name had no type and drew raw. Now, when the host supplies the record (`recordFromHost`, which `record:details` sets), `DetailView` takes field types from the record context's object schema until a dataSource answers. A dataSource answer still wins, nothing new is fetched, and a `DetailView` with no record context, or one that reads its own record, draws exactly as before.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The page designer's Design canvas draws an authored `record:details` body's
5+
* values the way the record page does.
6+
*
7+
* A `full` record page names its detail fields (the full-create seed writes
8+
* `sections[].fields` as bare names). The canvas mounts the runtime
9+
* `record:details` renderer under a record context that holds the bound
10+
* object's schema but no dataSource, as every Studio preview does. The field
11+
* types come from that schema: without it a `select` drew its stored code and a
12+
* `location` drew `[Object]`.
13+
*
14+
* Everything here is real: the canvas, the record context, `record:details`,
15+
* `DetailView` and the `@object-ui/fields` cell renderers. Only the two
16+
* endpoints `PagePreview` reads (the object schema and the sample records) are
17+
* answered by a double.
18+
*/
19+
20+
import * as React from 'react';
21+
import { describe, it, expect, vi, afterEach } from 'vitest';
22+
import { render, waitFor, within, cleanup } from '@testing-library/react';
23+
// Registers `record:details`, which the canvas resolves through the registry.
24+
import { buildDefaultPageSchema } from '@object-ui/plugin-detail';
25+
26+
/** Stable stub identity: `PagePreview` carries `perms` in an effect dep list. */
27+
const { permsStub } = vi.hoisted(() => ({
28+
permsStub: {
29+
isLoaded: true,
30+
checkField: () => true,
31+
check: () => ({ allowed: true }),
32+
getFieldPermissions: () => [],
33+
getRowFilter: () => undefined,
34+
getObjectApiOperations: () => undefined,
35+
roles: [],
36+
userId: null,
37+
systemPermissions: undefined,
38+
hasCapabilities: () => true,
39+
can: () => true,
40+
cannot: () => false,
41+
},
42+
}));
43+
44+
vi.mock('@object-ui/permissions', async (importOriginal) => {
45+
const actual = await importOriginal<typeof import('@object-ui/permissions')>();
46+
return { ...actual, usePermissions: () => permsStub as any };
47+
});
48+
49+
import { PagePreview } from './PagePreview';
50+
import {
51+
deriveStudioDetailSections,
52+
toAuthoredDetailSections,
53+
MORE_DETAILS_DEFAULT_LABEL,
54+
} from '../../recordDetailSections';
55+
56+
const OBJECT = 'showcase_account';
57+
const OBJECT_DEF = {
58+
name: OBJECT,
59+
label: 'Account',
60+
// The highlights strip takes this field, so the three below stay in the
61+
// details body: the strip reads the same record context and draws its own.
62+
highlightFields: ['website'],
63+
fields: {
64+
name: { type: 'text', label: 'Account Name' },
65+
website: { type: 'text', label: 'Website' },
66+
account_code: { type: 'text', label: 'Account Code' },
67+
sales_region: {
68+
type: 'select',
69+
label: 'Sales Region',
70+
options: [
71+
{ value: 'amer', label: 'Americas' },
72+
{ value: 'emea', label: 'Europe' },
73+
],
74+
},
75+
headquarters: { type: 'location', label: 'Headquarters' },
76+
},
77+
};
78+
const RECORD = {
79+
id: 'acc_1',
80+
name: 'Northwind',
81+
website: 'northwind.example',
82+
account_code: 'NW-001',
83+
sales_region: 'amer',
84+
headquarters: { latitude: 37.7749, longitude: -122.4194 },
85+
};
86+
87+
/** The page the full-create seed writes for this object: authored, named fields. */
88+
function fullCreateSeed(): Record<string, unknown> {
89+
const sections = toAuthoredDetailSections(
90+
deriveStudioDetailSections(OBJECT_DEF as any, { moreDetails: MORE_DETAILS_DEFAULT_LABEL }),
91+
);
92+
const synth = buildDefaultPageSchema(OBJECT_DEF as any, sections ? { sections: sections as any } : undefined) as {
93+
regions: unknown[];
94+
template?: unknown;
95+
};
96+
return {
97+
name: 'account_page',
98+
label: 'Account page',
99+
type: 'record',
100+
object: OBJECT,
101+
kind: 'full',
102+
regions: synth.regions,
103+
...(synth.template !== undefined ? { template: synth.template } : {}),
104+
};
105+
}
106+
107+
function stubFetch() {
108+
vi.stubGlobal('fetch', vi.fn(async (url: string) => {
109+
if (url.startsWith('/api/v1/meta/object/')) return { ok: true, json: async () => ({ item: OBJECT_DEF }) } as any;
110+
if (url.startsWith(`/api/v1/data/${OBJECT}`)) return { ok: true, json: async () => ({ records: [RECORD] }) } as any;
111+
// The record-edit probe and anything else the real blocks ask for.
112+
return { ok: true, json: async () => ({}) } as any;
113+
}));
114+
}
115+
116+
afterEach(() => {
117+
cleanup();
118+
vi.unstubAllGlobals();
119+
});
120+
121+
describe('PagePreview Design canvas: an authored record:details draws typed values', () => {
122+
it('names its detail fields as bare names (the premise this file pins)', () => {
123+
const seed = JSON.stringify(fullCreateSeed());
124+
expect(seed).toContain('"record:details"');
125+
expect(seed).toContain('"sales_region"');
126+
expect(seed).not.toContain('"type":"select"');
127+
});
128+
129+
it('draws a select by its option label and a location as coordinates, never the raw value', async () => {
130+
stubFetch();
131+
render(
132+
<PagePreview
133+
type="page"
134+
name="account_page"
135+
draft={fullCreateSeed()}
136+
editing
137+
selection={null}
138+
onSelectionChange={() => {}}
139+
onPatch={vi.fn() as any}
140+
locale="en-US"
141+
/>,
142+
);
143+
144+
// The block draws its "bind a record" placeholder until the sample record
145+
// is bound, so wait for the bound body.
146+
const details = await waitFor(() => {
147+
const el = document.querySelector('[data-obj-type="record:details"]:not([data-record-details-placeholder])');
148+
expect(el).not.toBeNull();
149+
// Control: a plain text field reads as stored, before and after the fix.
150+
within(el as HTMLElement).getByText('NW-001');
151+
return el as HTMLElement;
152+
});
153+
const body = within(details);
154+
expect(body.getByText('Americas')).toBeTruthy();
155+
expect(body.getByText(/37\.7749, -122\.4194/)).toBeTruthy();
156+
expect(body.queryByText('amer')).toBeNull();
157+
expect(details.textContent).not.toContain('[Object]');
158+
});
159+
});

‎ui/packages/plugin-detail/src/DetailView.tsx‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import { ActivityTimeline } from './ActivityTimeline';
4545
import { HistoryTimeline } from './HistoryTimeline';
4646
import { RecordMetaFooter } from './RecordMetaFooter';
4747
import { RecordPageProvenanceContext } from './recordPageProvenance';
48-
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage } from '@object-ui/react';
48+
import { SchemaRenderer, SchemaErrorBoundary, toRenderableSchema, useSafeFieldLabel, useDataInvalidation, useInlineEdit, useRowPredicate, resolveApprovalLock, usePrintPage, useRecordContext } from '@object-ui/react';
4949
import { buildExpandFields, declaredNameField, getRecordDisplayName, formatTitleTemplate, recordDisplayValueAt, resolveAffordance, toDisplayDate, userActionPredicates, withoutDeniedFields } from '@object-ui/core';
5050
import { usePermissions } from '@object-ui/permissions';
5151
import { useLocalization, useDisplayLocale, resolveFieldCurrency } from '@object-ui/i18n';
@@ -330,7 +330,19 @@ export const DetailView: React.FC<DetailViewProps> = ({
330330
// Retained local error state for the approval-cancel flow ONLY — the
331331
// inline-edit draft now surfaces its own errors through the save bar.
332332
const [saveError, setSaveError] = React.useState<string | null>(null);
333-
const [objectSchema, setObjectSchema] = React.useState<any>(null);
333+
const [dataSourceObjectSchema, setObjectSchema] = React.useState<any>(null);
334+
// The host's object definition, for a host that supplies the record
335+
// (`recordFromHost`). Field types come from the object schema: without it a
336+
// bare-name section entry has no type, so `DetailSection` draws the raw
337+
// stored value (a `select` code, a `location` object as `[Object]`). The
338+
// dataSource answer below is what supplies it on the record page; a host
339+
// that renders with no dataSource bound (the Studio page designer) never
340+
// gets that answer, though its record context already holds the schema it
341+
// read. So the host's schema stands in until a dataSource answers, and
342+
// nothing is fetched for it. A host with no record context, or one that
343+
// does not supply the record, is unchanged.
344+
const hostObjectSchema = useRecordContext()?.objectSchema;
345+
const objectSchema = dataSourceObjectSchema ?? (recordFromHost ? hostObjectSchema ?? null : null);
334346
const [idCopied, setIdCopied] = React.useState(false);
335347
const [reloadTick, setReloadTick] = React.useState(0);
336348
// #2269 — refetch in place when this record (or its object) is invalidated
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
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+
import * as React from 'react';
10+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
11+
import { render, screen, waitFor } from '@testing-library/react';
12+
import { RecordContextProvider } from '@object-ui/react';
13+
import { DetailView } from '../DetailView';
14+
import { __clearRecordEditableCache } from '../useRecordEditable';
15+
import type { DetailViewSchema } from '@object-ui/types';
16+
17+
/**
18+
* Under `recordFromHost`, field types come from the host's object schema until
19+
* a dataSource answers.
20+
*
21+
* A host that renders a record with no dataSource bound (the Studio page
22+
* designer) holds the object schema in its record context, and `DetailView`
23+
* only ever learned field types from `dataSource.getObjectSchema`. A bare-name
24+
* section entry then had no type: a `select` drew its stored code and a
25+
* `location` drew `[Object]`. The canvas end of this is
26+
* `PagePreview.authoredDetailsValues-27177.test.tsx` in app-shell.
27+
*/
28+
29+
const fieldsWith = (amerLabel: string) => ({
30+
name: { type: 'text', label: 'Name' },
31+
sales_region: {
32+
type: 'select',
33+
label: 'Sales Region',
34+
options: [{ value: 'amer', label: amerLabel }, { value: 'emea', label: 'Europe' }],
35+
},
36+
headquarters: { type: 'location', label: 'Headquarters' },
37+
});
38+
const hostSchema = { name: 'account', fields: fieldsWith('Americas') };
39+
40+
const RECORD = {
41+
id: 'A1',
42+
name: 'Northwind',
43+
sales_region: 'amer',
44+
headquarters: { latitude: 37.7749, longitude: -122.4194 },
45+
};
46+
47+
// Bare-name entries, as `record:details` hands an authored section over.
48+
const schema: DetailViewSchema = {
49+
type: 'detail-view',
50+
objectName: 'account',
51+
resourceId: 'A1',
52+
showHeader: false,
53+
data: RECORD,
54+
sections: [{ title: 'Details', fields: [{ name: 'sales_region' }, { name: 'headquarters' }] }],
55+
};
56+
57+
function makeDataSource(objectSchema: unknown) {
58+
return {
59+
find: vi.fn(async () => ({ data: [] })),
60+
findOne: vi.fn(async () => RECORD),
61+
create: vi.fn(async () => ({})),
62+
update: vi.fn(async () => ({})),
63+
delete: vi.fn(async () => ({})),
64+
getObjectSchema: vi.fn(async () => objectSchema),
65+
};
66+
}
67+
68+
const withHost = (node: React.ReactNode, objectSchema: unknown = hostSchema) => (
69+
<RecordContextProvider objectName="account" recordId="A1" data={RECORD} objectSchema={objectSchema}>
70+
{node}
71+
</RecordContextProvider>
72+
);
73+
74+
const settle = () => new Promise((r) => setTimeout(r, 20));
75+
76+
describe('DetailView: recordFromHost takes field types from the host object schema', () => {
77+
// The edit probe (`POST /security/explain`) rides the global fetch.
78+
beforeEach(() => {
79+
__clearRecordEditableCache();
80+
vi.stubGlobal('fetch', vi.fn(async () => ({ ok: true, json: async () => ({ record: { visible: true } }) })));
81+
});
82+
afterEach(() => { vi.unstubAllGlobals(); });
83+
84+
it('with no dataSource, draws a select by its option label and a location as coordinates', async () => {
85+
const { container } = render(withHost(<DetailView schema={schema} recordFromHost />));
86+
await waitFor(() => expect(screen.getByText('Americas')).toBeInTheDocument());
87+
expect(screen.getByText(/37\.7749, -122\.4194/)).toBeInTheDocument();
88+
expect(screen.queryByText('amer')).toBeNull();
89+
expect(container.textContent).not.toContain('[Object]');
90+
});
91+
92+
it('CONTROL: a dataSource answer still wins over the host schema, and it is the one read', async () => {
93+
const ds = makeDataSource({ name: 'account', fields: fieldsWith('Americas (from the dataSource)') });
94+
render(withHost(<DetailView schema={schema} dataSource={ds as never} recordFromHost />));
95+
await waitFor(() => expect(screen.getByText('Americas (from the dataSource)')).toBeInTheDocument());
96+
expect(screen.queryByText('Americas')).toBeNull();
97+
expect(ds.getObjectSchema).toHaveBeenCalledTimes(1);
98+
expect(ds.findOne).not.toHaveBeenCalled();
99+
});
100+
101+
it('CONTROL: with no record context, or without recordFromHost, it draws what it drew before', async () => {
102+
const bare = render(<DetailView schema={schema} recordFromHost />);
103+
await settle();
104+
expect(bare.getByText('amer')).toBeInTheDocument();
105+
expect(bare.queryByText('Americas')).toBeNull();
106+
bare.unmount();
107+
108+
const notFromHost = render(withHost(<DetailView schema={schema} />));
109+
await settle();
110+
expect(notFromHost.getByText('amer')).toBeInTheDocument();
111+
expect(notFromHost.queryByText('Americas')).toBeNull();
112+
});
113+
});

0 commit comments

Comments
 (0)