Skip to content

Commit e8cba8f

Browse files
fix(console): the public form prints a form entry's own label, not the app bundle's object-field translation (#34390)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9BtJbyfcjefHVT9XXSMDFVR)_ Fixes #34375 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:公开表单页(console `FormPage`)里,表单项自己声明了 `label` 的行,直接显示表单接口返回的标签(已按访客语言本地化);只有标签来自对象字段的行,才继续用应用翻译包的 `fields.对象.字段` 覆盖。必填提示和 `visibleWhen` 故障提示按同一规则点名字段。 - **为什么改**:浏览器里只要加载了应用翻译包(比如访客在同一 console 已登录),对象字段的坐席侧译名就会盖掉表单项的访客侧标签。HotCRM 公开支持表单因此显示「提交人姓名」而不是「您的姓名」,冷启动的匿名访问却显示正确,同一版本两种结果。 - **风险与回滚**:只改 console 一个组件的标签取值;行在构建时记下标签来源(`labelSource`),不比较字符串。没有表单项标签的行行为不变。无服务端、契约或 `@object-ui/i18n` 改动。回滚即 revert 本 PR。 - **先看**:`ui/apps/console/src/components/FormPage.tsx` 的 `rowLabel`(组件内)与 `buildSections` 里新增的 `labelSource` 一行;其次 `FormPage.sectionLabelI18n.test.tsx` 末尾新增的一组测试。 - **两分钟验证**:`pnpm --dir ui exec vitest run apps/console/src/components/FormPage.sectionLabelI18n.test.tsx`,预期 9 个测试全过(其中 3 个为本卡新增)。 - **需要你做的**:无,席位落地。 ## What changes - **The row records where its label came from.** `RenderableField` gains `labelSource: 'entry' | 'object'`, set in `buildSections` from the same `??` that picks the label: `'entry'` when the form entry declared its own `label`, `'object'` when the row fell back to the object field's label (or its name). Nothing compares strings. - **One naming rule for the row.** A component-local `rowLabel(object, f)` prints an `'entry'` label as served (the form endpoint already localized it from `_sections.SECTION.fields.FIELD.label`) and keeps `fieldLabel(object, f.name, f.label)`, the bundle overlay with the served label as fallback, for an `'object'` row. It replaces all four call sites: the row label on screen, the `visibleWhen`-fault banner, the required banner/toast and the per-row required message. So a refusal names a field by the label the visitor sees. - **`fieldLabel` in `@object-ui/i18n` is unchanged.** Every other surface keeps bundle-first resolution for object fields. ## Why The form endpoint serves the entry label correctly. The page then looked up `fields.OBJECT.FIELD` first, which translates the object field's agent-side label, and printed it whenever the browser held the app bundle. A signed-in visitor (or any visit with the bundle loaded) read the agent-side label; a cold anonymous visit (no bundle, see `FormPage.signedOutSectionI18n-12333.test.tsx`) read the entry label. ## Tests New top-level `describe` in the existing public-form i18n harness `FormPage.sectionLabelI18n.test.tsx` (the file that already seeds an app bundle on the unwrapped `/f/:slug` route). The fixture's bundle translates both object fields (`supplied_name` → 提交人姓名, `supplied_email` → 提交人邮箱); the form entry for `supplied_name` declares `label: 您的姓名`, the entry for `supplied_email` declares none. Every leg asserts both strings. - (a) `ENTRY_LABEL_RENDERS_AS_SERVED`: the row reads 您的姓名, 提交人姓名 is nowhere on the page, and the input is named by 您的姓名. - (b) `REQUIRED_REFUSAL_NAMES_THE_VISIBLE_LABELS`: an empty submit's toast/banner message contains 您的姓名 and 提交人邮箱, not 提交人姓名; the per-row message the name input points at (`aria-describedby`) names 您的姓名. - (c) CONTROL `OBJECT_LABEL_TAKES_THE_BUNDLE`: the row with no entry label reads 提交人邮箱, not the object's authored "Submitter email". The `visibleWhen`-fault message goes through the same `rowLabel` call; it has no new pin of its own (the card asked for (a)–(c)). **Forced test edits** (type only, no assertion changed): `RenderableField.labelSource` is required, so the hand-built row fixtures gain `labelSource: 'object'`: `FormPage.test.ts` (the `readPrefill` fields and the `remind_at` row), `FormPage.omitBlanksRebind.test.ts` (`row()`), `FormPage.optionDefault-13049.test.tsx` (the `priority` row). Without it `@object-ui/console` `type-check` reds (28 TS errors measured before the edit). ## Acceptance notes - The internal in-app form route (`?form=ID`) renders through the same `buildSections` and the same `rowLabel`, so it follows the same rule. Whether that route's form view arrives with its entry labels already localized was not measured here; an entry label that is a plain string is printed as authored there, as it was whenever the bundle missed. - An entry whose `label` happens to equal the object field's label is still an entry label and is printed as served (no string comparison, by the card's instruction). ## Verification Readings taken on head `f29f7093` (base `6cc3f974`). <details><summary>Ablations (each leg via scripts/ablation-replace.mjs, restored blob == HEAD, git diff HEAD empty)</summary> - A1 `rowLabel` ignores provenance (`/* ablated */ fieldLabel(object, f.name, f.label)`): (a) and (b) red, (c) green. `expected '提交人姓名' to be '您的姓名'`; `expected '必填项:提交人姓名、提交人邮箱' to contain '您的姓名'`. 2 failed, 7 passed. - A2 `buildSections` always `labelSource: 'object'`: the same two legs red with the same messages. 2 failed, 7 passed. - A3 no overlay at all (`/* ablated */ f.label`): (c) red (`expected 'Submitter email' to be '提交人邮箱'`), (b) red on its 提交人邮箱 half, and the existing `FIELD_LABEL_IS_TRANSLATED` red. 3 failed, 6 passed. The console test imports `FormPage` from source, so no dist rebuild sits between mutation and run. </details> <details><summary>Local runs</summary> - `pnpm --dir ui exec vitest run apps/console/src/components/FormPage.sectionLabelI18n.test.tsx`: 9/9. - Every console test file that names `FormPage` or `buildSections` (62 files): `Test Files 62 passed (62)`, `Tests 557 passed (557)`. - `pnpm --filter @object-ui/console run type-check`: exit 0. - `pnpm exec eslint` on the five touched files: 0 errors; warning counts equal to base for `FormPage.tsx` (26) and `FormPage.test.ts` (2). - `pnpm --dir ui check:new-line-citations`: 0 new citations. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 37 commands, each run on the final head, all exit 0 (list in the os-dev-report on the card). </details> ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes. - [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: its generated artifacts are regenerated and committed. (Not touched.) - [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. - [x] The *Before Submitting* list in CONTRIBUTING.md is done. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmTMdcLKvrzHvpYZ3gn)_ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 046c224 commit e8cba8f

6 files changed

Lines changed: 166 additions & 10 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/console': patch
3+
---
4+
5+
fix(console): the public form prints a form entry's own label as served, not the app bundle's object-field translation
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
A form entry that declares its own `label` is the form's visitor-facing copy, and the form endpoint already serves it localized (from `_sections.SECTION.fields.FIELD.label` in the app's translations). The public form page then looked the field up in the app bundle as `fields.OBJECT.FIELD` first and printed that whenever the browser held the bundle, which translates the object field's label, the one agents see. So a visitor who was signed in to the same console, or any visit with the bundle loaded, read the agent-side label (for example "Submitter name" where the form says "Your name"), while a cold anonymous visit read the form's own label.
11+
12+
Each row now records where its label came from. A row whose entry declared a `label` prints it as served; only a row whose label came from the object field takes the bundle translation, as before. The required-field and `visibleWhen` refusal messages name each field by the same rule, so they use the label the visitor sees.

‎ui/apps/console/src/components/FormPage.omitBlanksRebind.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ function row(name: string, defaultValue?: unknown): Row {
5959
return {
6060
name,
6161
label: name,
62+
labelSource: 'object',
6263
type: 'text',
6364
required: false,
6465
readonly: false,

‎ui/apps/console/src/components/FormPage.optionDefault-13049.test.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ describe('objectui#13049 — `readPrefill` keeps the stored record first', () =>
205205
const field = {
206206
name: 'priority',
207207
label: 'Priority',
208+
labelSource: 'object' as const,
208209
type: 'select',
209210
required: true,
210211
readonly: false,

‎ui/apps/console/src/components/FormPage.sectionLabelI18n.test.tsx‎

Lines changed: 110 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ import { describe, expect, it, vi, beforeEach, afterEach } from 'vitest';
8181
import { render, screen, waitFor, cleanup } from '@testing-library/react';
8282
import { MemoryRouter, Route, Routes } from 'react-router-dom';
8383
import { createI18n } from '@object-ui/i18n';
84+
import userEvent from '@testing-library/user-event';
85+
import { toast } from 'sonner';
8486
import { FormPage } from './FormPage';
8587

8688
vi.mock('sonner', () => ({ toast: { success: vi.fn(), error: vi.fn() } }));
@@ -119,6 +121,17 @@ const NAMELESS_AUTHORED = 'Attachments';
119121
*/
120122
const DECOY = '⛔ keyed by the authored label';
121123

124+
/**
125+
* The entry-label fixture's two object fields: what the object declares, and
126+
* what the app bundle translates that OBJECT label to — the agent-side copy.
127+
*/
128+
const AGENT_NAME_AUTHORED = 'Submitter name';
129+
const AGENT_NAME_TRANSLATED = '提交人姓名';
130+
const AGENT_EMAIL_AUTHORED = 'Submitter email';
131+
const AGENT_EMAIL_TRANSLATED = '提交人邮箱';
132+
/** The form ENTRY's own label, as the form endpoint serves it (already localized). */
133+
const ENTRY_NAME_SERVED = '您的姓名';
134+
122135
const BUNDLE = {
123136
[NS]: {
124137
objects: {
@@ -132,6 +145,10 @@ const BUNDLE = {
132145
fields: {
133146
[API_NAME]: {
134147
full_name: FIELD_TRANSLATED,
148+
// The OBJECT fields' agent-side translations — see the entry-label
149+
// describe below. No entry in this file's first fixture names them.
150+
supplied_name: AGENT_NAME_TRANSLATED,
151+
supplied_email: AGENT_EMAIL_TRANSLATED,
135152
},
136153
},
137154
},
@@ -195,8 +212,8 @@ function stubFetch(body: unknown) {
195212
* around it would move this file off the route and onto a harness — see the
196213
* header.
197214
*/
198-
function renderPublicRoute() {
199-
vi.stubGlobal('fetch', stubFetch(SERVED));
215+
function renderPublicRoute(served: unknown = SERVED) {
216+
vi.stubGlobal('fetch', stubFetch(served));
200217
return render(
201218
<MemoryRouter initialEntries={['/f/apply']}>
202219
<Routes>
@@ -331,3 +348,94 @@ describe('objectui#8813 — public form i18n on the /f/:slug route', () => {
331348
await expect(liveSections()).rejects.toThrow();
332349
});
333350
});
351+
352+
/**
353+
* A form ENTRY that declares its own `label` is the form's visitor-facing copy,
354+
* served already localized by the form endpoint
355+
* (`_sections.{section}.fields.{field}.label`). The bundle's
356+
* `fields.{object}.{field}` translates a different text — the OBJECT field's,
357+
* the agent-side label — so it may only overlay a row whose label came from
358+
* the object field. Every leg asserts both strings, so an overlay that wins
359+
* and an entry label that wins can never read alike.
360+
*/
361+
describe('a form entry\'s own label wins over the bundle\'s object-field translation', () => {
362+
const ENTRY_FORM = {
363+
type: 'simple',
364+
columns: 1,
365+
title: 'Support',
366+
sections: [
367+
{
368+
name: 'how_can_we_help',
369+
fields: [
370+
// Entry-declared label — printed as served.
371+
{ field: 'supplied_name', label: ENTRY_NAME_SERVED, required: true },
372+
// No entry label — the object field's label, and its bundle overlay.
373+
{ field: 'supplied_email', required: true },
374+
],
375+
},
376+
],
377+
};
378+
const ENTRY_SERVED = {
379+
slug: 'apply',
380+
object: API_NAME,
381+
form: ENTRY_FORM,
382+
objectSchema: {
383+
name: API_NAME,
384+
label: 'Inquiry',
385+
fields: {
386+
supplied_name: { type: 'text', label: AGENT_NAME_AUTHORED },
387+
supplied_email: { type: 'text', label: AGENT_EMAIL_AUTHORED },
388+
},
389+
},
390+
};
391+
392+
/** The two row labels, in order, once the form has drawn both. */
393+
async function rowLabels(): Promise<string[]> {
394+
await waitFor(() => expect(document.body.querySelectorAll('form label').length).toBe(2));
395+
return Array.from(document.body.querySelectorAll('form label')).map(
396+
// The visual-only required `*` sits inside the label.
397+
(l) => (l.textContent ?? '').replace(/\*$/, ''),
398+
);
399+
}
400+
401+
it('ENTRY_LABEL_RENDERS_AS_SERVED — the entry label, not the object field\'s translation', async () => {
402+
renderPublicRoute(ENTRY_SERVED);
403+
const [name] = await rowLabels();
404+
405+
expect(name).toBe(ENTRY_NAME_SERVED);
406+
expect(document.body.textContent).not.toContain(AGENT_NAME_TRANSLATED);
407+
expect(screen.getByLabelText(new RegExp(ENTRY_NAME_SERVED))).toBeInTheDocument();
408+
});
409+
410+
it('CONTROL OBJECT_LABEL_TAKES_THE_BUNDLE — a row with no entry label still reads the translation', async () => {
411+
renderPublicRoute(ENTRY_SERVED);
412+
const [, email] = await rowLabels();
413+
414+
expect(email).toBe(AGENT_EMAIL_TRANSLATED);
415+
expect(document.body.textContent).not.toContain(AGENT_EMAIL_AUTHORED);
416+
});
417+
418+
it('REQUIRED_REFUSAL_NAMES_THE_VISIBLE_LABELS — the entry label, and the overlay for the object row', async () => {
419+
renderPublicRoute(ENTRY_SERVED);
420+
await rowLabels();
421+
await userEvent.click(document.body.querySelector('button[type="submit"]') as HTMLButtonElement);
422+
423+
// The banner/toast frame names every refused row by the label on screen.
424+
await waitFor(() => expect(vi.mocked(toast.error)).toHaveBeenCalled());
425+
const calls = vi.mocked(toast.error).mock.calls;
426+
const msg = String(calls[calls.length - 1]?.[0]);
427+
expect(msg).toContain(ENTRY_NAME_SERVED);
428+
expect(msg).not.toContain(AGENT_NAME_TRANSLATED);
429+
expect(msg).toContain(AGENT_EMAIL_TRANSLATED);
430+
431+
// The per-row message the name input points at says the same.
432+
const input = screen.getByLabelText(new RegExp(ENTRY_NAME_SERVED));
433+
await waitFor(() => expect(input.getAttribute('aria-describedby')).toBeTruthy());
434+
const rowMsg = (input.getAttribute('aria-describedby') ?? '')
435+
.split(/\s+/)
436+
.map((id) => document.getElementById(id)?.textContent ?? '')
437+
.join(' ');
438+
expect(rowMsg).toContain(ENTRY_NAME_SERVED);
439+
expect(rowMsg).not.toContain(AGENT_NAME_TRANSLATED);
440+
});
441+
});

‎ui/apps/console/src/components/FormPage.test.ts‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,9 @@ describe('buildSections', () => {
224224

225225
describe('readPrefill', () => {
226226
const fields = [
227-
{ name: 'first_name', label: 'First name', type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const },
228-
{ name: 'company', label: 'Company', type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const, defaultValue: 'Acme' },
229-
{ name: 'phone', label: 'Phone', type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const },
227+
{ name: 'first_name', label: 'First name', labelSource: 'object' as const, type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const },
228+
{ name: 'company', label: 'Company', labelSource: 'object' as const, type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const, defaultValue: 'Acme' },
229+
{ name: 'phone', label: 'Phone', labelSource: 'object' as const, type: 'text', required: false, readonly: false, hidden: false, colSpan: 1 as const },
230230
];
231231

232232
it('applies defaultValue from the field definition', () => {
@@ -327,6 +327,7 @@ describe('readPrefill', () => {
327327
{
328328
name: 'remind_at',
329329
label: 'Remind at',
330+
labelSource: 'object' as const,
330331
type: 'datetime',
331332
required: false,
332333
readonly: false,

‎ui/apps/console/src/components/FormPage.tsx‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,20 @@ type EffectiveSubmitBehavior = SubmitBehavior | { kind: 'created-record' };
496496
interface RenderableField {
497497
name: string;
498498
label: string;
499+
/**
500+
* Where {@link RenderableField.label} came from, decided where the row is
501+
* built and never re-guessed from the string: `'entry'` when the form
502+
* view's field entry declared its own `label`, `'object'` when the row fell
503+
* back to the object field's label (or its name).
504+
*
505+
* The two are different texts. An entry label is the visitor-facing copy
506+
* the author wrote for THIS form, served already localized by the form
507+
* endpoint (`_sections.{section}.fields.{field}.label`); the app bundle's
508+
* `fields.{object}.{field}` translates the OBJECT field, the agent-side
509+
* label. So only an `'object'` row takes the bundle overlay — see
510+
* `rowLabel` in {@link FormPage}.
511+
*/
512+
labelSource: 'entry' | 'object';
499513
type: string;
500514
required: boolean;
501515
readonly: boolean;
@@ -853,6 +867,10 @@ export function buildSections(
853867
// objectui#13380 — the three `I18nLabel` keys, collapsed to the
854868
// visitor's language before they reach a `string` slot.
855869
label: localized(override.label ?? def.label) ?? override.field,
870+
// The same `??` as the line above, read once more for its branch: an
871+
// entry that declared a label is the visitor's copy, never overlaid
872+
// by the object field's bundle translation at render.
873+
labelSource: override.label != null ? 'entry' : 'object',
856874
type: def.type ?? 'text',
857875
required: override.required ?? def.required ?? false,
858876
readonly: override.readonly ?? false,
@@ -2529,6 +2547,19 @@ export function FormPage({ mode, recordPath, cancelPath }: FormPageProps) {
25292547
* and NO in the same position with the wrapper removed.
25302548
*/
25312549
const { sectionLabel, fieldLabel, objectLabel } = useSafeFieldLabel();
2550+
/**
2551+
* The label a row is NAMED by, on screen and in every refusal that names
2552+
* it — one rule for all of them, so a message never calls a field something
2553+
* the visitor cannot see.
2554+
*
2555+
* An entry-declared label (`labelSource: 'entry'`) is printed as served: it
2556+
* is this form's own copy, already localized by the form endpoint, and the
2557+
* bundle's `fields.{object}.{field}` translates a different text — the
2558+
* object field's. Only a row whose label came from the object field takes
2559+
* that overlay, falling back to the served label on a miss.
2560+
*/
2561+
const rowLabel = (object: string, f: Pick<RenderableField, 'name' | 'label' | 'labelSource'>): string =>
2562+
f.labelSource === 'entry' ? f.label : fieldLabel(object, f.name, f.label);
25322563
// The page's own chrome — the loading line, the success toast, the
25332564
// thank-you panel's defaults, and (objectui#11071) the submit button, the
25342565
// pending-redirect line and the required refusal's frame — through the same
@@ -2817,7 +2848,7 @@ export function FormPage({ mode, recordPath, cancelPath }: FormPageProps) {
28172848
if (faultedVisibleWhen.length > 0) {
28182849
const msg = t('form.visibleWhenFaulted', {
28192850
fields: faultedVisibleWhen
2820-
.map((f) => fieldLabel(object, f.name, f.label))
2851+
.map((f) => rowLabel(object, f))
28212852
.join(t('validation.formInvalidJoiner')),
28222853
});
28232854
setError(msg);
@@ -2835,15 +2866,15 @@ export function FormPage({ mode, recordPath, cancelPath }: FormPageProps) {
28352866
// the words are the locale's, not a concatenation of English.
28362867
const msg = t('publicForm.requiredFields', {
28372868
fields: missing
2838-
.map((f) => fieldLabel(object, f.name, f.label))
2869+
.map((f) => rowLabel(object, f))
28392870
.join(t('validation.formInvalidJoiner')),
28402871
});
28412872
setError(msg);
28422873
toast.error(msg, { id: outcomeToastId });
28432874
// The record form's message for an empty required field, per row.
28442875
setFieldErrors(Object.fromEntries(missing.map((f) => [
28452876
f.name,
2846-
t('validation.required', { field: fieldLabel(object, f.name, f.label) }),
2877+
t('validation.required', { field: rowLabel(object, f) }),
28472878
])));
28482879
return true;
28492880
}
@@ -3297,9 +3328,11 @@ export function FormPage({ mode, recordPath, cancelPath }: FormPageProps) {
32973328
* payload, which is why the symptom looked like "field
32983329
* labels translate, section headings do not"; the client
32993330
* lookup is the overlay an app bundle can put on top,
3300-
* not a replacement for that server value.
3331+
* not a replacement for that server value — and only for
3332+
* a row whose label IS the object field's (`rowLabel`):
3333+
* an entry-declared label is printed as served.
33013334
*/}
3302-
{fieldLabel(loaded.object, f.name, f.label)}
3335+
{rowLabel(loaded.object, f)}
33033336
{/* Visual-only (objectui#3299): the control's `required` /
33043337
`aria-required` is the announced channel; hiding the `*`
33053338
keeps it out of the control's accessible name. */}

0 commit comments

Comments
 (0)