From 3fa510bba4c9c2d0f4977f254ae852c1b7cc3437 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 03:37:07 +0000 Subject: [PATCH 1/4] feat(studio): the field inspector and object settings write Field change values (#36290 part 1) The field inspector's Track history box becomes a Field change values choice (Default / On / Off over the field's fieldHistory, Default resolved by resolveFieldHistory against the object in hand); the object settings' Features card gains an enable.fieldHistory switch that writes false to turn values off and removes the key to turn them back on. The choice, the value each choice writes and its wording move to fieldHistoryChoice.ts, shared with the metadata form's field-history widget. Claude-Session: https://claude.ai/code/session_01ADHkmPq6z7KER4Sr6Uu7Ht Co-authored-by: Claude --- .changeset/36290-field-history-producers.md | 16 +++ .../metadata-admin/fieldHistoryChoice.ts | 57 ++++++++ ...nspector.displayPatchReason-28986.test.tsx | 5 +- ...FieldInspector.fieldHistory-36290.test.tsx | 128 ++++++++++++++++++ .../inspectors/ObjectFieldInspector.tsx | 42 +++++- .../src/views/metadata-admin/widgets.tsx | 27 ++-- ...ttingsPanel.businessWording-36512.test.tsx | 1 + .../ObjectSettingsPanel.test.tsx | 41 +++++- .../studio-design/ObjectSettingsPanel.tsx | 24 +++- ui/packages/i18n/src/namespaces/studio/en.ts | 9 +- ui/packages/i18n/src/namespaces/studio/zh.ts | 8 +- 11 files changed, 327 insertions(+), 31 deletions(-) create mode 100644 .changeset/36290-field-history-producers.md create mode 100644 ui/packages/app-shell/src/views/metadata-admin/fieldHistoryChoice.ts create mode 100644 ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.fieldHistory-36290.test.tsx diff --git a/.changeset/36290-field-history-producers.md b/.changeset/36290-field-history-producers.md new file mode 100644 index 00000000000..4e39ada45fd --- /dev/null +++ b/.changeset/36290-field-history-producers.md @@ -0,0 +1,16 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(studio): the field inspector and the object's settings write Field change values instead of Track history + +Clause-②: yes (widening) +Metadata-protocol: none + +Old → new values show on the record activity by default, and an object or a single field can turn them off. The Studio now writes that setting where an author looks for it: + +- **Field inspector.** The "Track history" box is gone. In its place, "Field change values" offers Default, On and Off. Default leaves the field's `fieldHistory` unset and names what it means for this field on this object: "Default (On)" for most types, "Default (Off)" for a media, JSON or credential field, and "Default (Off)" for every field when the object turns values off, with a note saying so. On and Off write `fieldHistory: true` and `false`; choosing Default after Off removes the key. A stored `trackHistory` is kept as it is and never written. +- **Object settings.** The Features card gains "Field change values" (`enable.fieldHistory`). Unticking it writes `false`; ticking it again removes the key rather than writing `true`, since unset already means on. Sibling `enable` keys are kept. + +The three choices, what each writes and their wording are shared with the metadata form's Field History control, so the two surfaces cannot drift. New Studio strings `designer.field.fieldHistory`, `designer.field.fieldHistoryObjectOff`, `engine.studio.settings.capFieldHistory` and `engine.studio.settings.capFieldHistoryDesc` (en, zh); `designer.field.trackHistory` is removed with the box it labelled. diff --git a/ui/packages/app-shell/src/views/metadata-admin/fieldHistoryChoice.ts b/ui/packages/app-shell/src/views/metadata-admin/fieldHistoryChoice.ts new file mode 100644 index 00000000000..0fac515a738 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/fieldHistoryChoice.ts @@ -0,0 +1,57 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * The three choices of a `fieldHistory` key — follow the default, on, off — + * declared once for every Studio surface that writes the key (#36290 ruling + * 7076513167 point 1, #36482). + * + * The key has no default on purpose: unset follows the platform, and only an + * author who chose writes `true` or `false`. So "Default" is a state of its + * own, it REMOVES the key, and its label names what it resolves to for the row + * in front of it — the caller asks `resolveFieldHistory` from + * `@objectstack/spec/data`, the predicate the activity writer keeps or drops + * values with, and hands the answer in as `defaultOn`. + * + * Two surfaces draw it: the metadata form's `field-history` widget + * (`widgets.tsx`, a `WidgetProps` renderer that sees one row and no object) + * and the object field inspector (an `InspectorSelectField` row, which holds + * the whole object document and so resolves Default against the object's own + * `enable.fieldHistory` too). Their controls differ; the choice, the value + * each choice writes and the wording live here. + */ + +import { t, tFormat, type SupportedLocale } from './i18n.js'; + +export type FieldHistoryChoice = 'default' | 'on' | 'off'; + +/** + * A stored value as a choice. Only a literal boolean is On or Off: the writer + * reads any other stored value as unset, so it draws as Default. + */ +export function fieldHistoryChoiceOf(value: unknown): FieldHistoryChoice { + return value === true ? 'on' : value === false ? 'off' : 'default'; +} + +/** The value a choice writes — `undefined` means remove the key. */ +export function fieldHistoryValueOf(choice: string): boolean | undefined { + return choice === 'on' ? true : choice === 'off' ? false : undefined; +} + +/** The label of the Default choice: `Default (On)` / `Default (Off)`. */ +export function fieldHistoryDefaultLabel(defaultOn: boolean, locale: SupportedLocale | string | undefined): string { + return tFormat('engine.form.fieldHistoryDefault', locale, { + state: t(defaultOn ? 'engine.form.fieldHistoryOn' : 'engine.form.fieldHistoryOff', locale), + }); +} + +/** The three choices in display order, Default naming what it resolves to. */ +export function fieldHistoryOptions( + defaultOn: boolean, + locale: SupportedLocale | string | undefined, +): Array<{ value: FieldHistoryChoice; label: string }> { + return [ + { value: 'default', label: fieldHistoryDefaultLabel(defaultOn, locale) }, + { value: 'on', label: t('engine.form.fieldHistoryOn', locale) }, + { value: 'off', label: t('engine.form.fieldHistoryOff', locale) }, + ]; +} diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.displayPatchReason-28986.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.displayPatchReason-28986.test.tsx index a93453c2a0c..cd39d2175a2 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.displayPatchReason-28986.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.displayPatchReason-28986.test.tsx @@ -153,13 +153,14 @@ describe('ObjectFieldInspector — display-patch mode explains every locked cont } }); - it('the named locks of the card: API name, Type, Required, Track history, a rule editor, Move up/down and Remove', () => { + it('the named locks of the card: API name, Type, Required, Field change values, a rule editor, Move up/down and Remove', () => { const rail = mount('industry'); const sentence = within(rail).getByTestId('field-base-patch-only'); const named = [ within(rail).getByTestId('field-apiname-input'), within(rail).getByRole('checkbox', { name: t('designer.field.required', LOCALE) }), - within(rail).getByRole('checkbox', { name: t('designer.field.trackHistory', LOCALE) }), + // objectstack#36290 — the Track history box became the Field change values choice. + within(rail).getByRole('combobox', { name: t('designer.field.fieldHistory', LOCALE) }), within(rail).getByLabelText(t('designer.field.visibleWhen', LOCALE)), // The header's pair and each option row's. ...within(rail).getAllByRole('button', { name: t('engine.inspector.reorder.up', LOCALE) }), diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.fieldHistory-36290.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.fieldHistory-36290.test.tsx new file mode 100644 index 00000000000..492e33b5f34 --- /dev/null +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.fieldHistory-36290.test.tsx @@ -0,0 +1,128 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * objectstack-ai/objectstack#36290 (ruling 7076513167 point 1) — the field + * inspector writes a field's `fieldHistory`: Default (removes the key, and + * says what it resolves to for this field on this object), On, Off. It used to + * draw a "Track history" box over `trackHistory`, which no longer turns values + * off; that box is gone, and a stored `trackHistory` is kept, never written. + */ + +import * as React from 'react'; +import { describe, it, expect, vi, afterEach, beforeAll } from 'vitest'; +import { render, screen, fireEvent, cleanup } from '@testing-library/react'; + +vi.mock('../useMetadata', () => ({ + useMetadataClient: () => ({ + list: vi.fn().mockResolvedValue([]), + listDrafts: vi.fn().mockResolvedValue([]), + }), +})); + +vi.mock('../previews/useObjectFields', () => ({ + useObjectFields: () => ({ fields: [], loading: false, error: null }), +})); + +// Paid at collection, not inside a case's clock (check:test-source-alias). +import '@objectstack/formula'; +import '@objectstack/lint'; +import { ObjectFieldInspector } from './ObjectFieldInspector'; + +afterEach(cleanup); + +beforeAll(() => { + // Radix Select reads pointer capture and scrolls the open item into view; jsdom has neither. + for (const m of ['hasPointerCapture', 'setPointerCapture', 'releasePointerCapture'] as const) { + if (!(m in Element.prototype)) { + (Element.prototype as unknown as Record)[m] = m === 'hasPointerCapture' ? () => false : () => {}; + } + } + if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = () => {}; +}); + +function renderField( + fields: Record>, + selectedId: string, + object: Record = {}, +) { + const onPatch = vi.fn(); + render( + , + ); + const savedField = () => + (onPatch.mock.calls.at(-1)![0].fields as Record>)[selectedId]; + return { onPatch, savedField }; +} + +const choice = () => screen.getByRole('combobox', { name: 'Field change values' }); + +async function pick(name: string) { + fireEvent.keyDown(choice(), { key: 'ArrowDown' }); + fireEvent.click(await screen.findByRole('option', { name })); +} + +describe('ObjectFieldInspector · Field change values (#36290)', () => { + it('draws an unset key as Default, naming what it resolves to for a one-line type', () => { + renderField({ notes: { type: 'textarea', label: 'Notes' } }, 'notes'); + expect(choice()).toHaveTextContent('Default (On)'); + }); + + it('names Default (Off) for a media, JSON or credential type, and Default (On) once trackHistory opts one in', () => { + for (const type of ['image', 'json', 'password']) { + renderField({ f: { type, label: 'F' } }, 'f'); + expect(choice(), type).toHaveTextContent('Default (Off)'); + cleanup(); + } + renderField({ f: { type: 'json', label: 'F', trackHistory: true } }, 'f'); + expect(choice()).toHaveTextContent('Default (On)'); + }); + + it('Off writes fieldHistory: false and On writes true', async () => { + const first = renderField({ notes: { type: 'textarea', label: 'Notes' } }, 'notes'); + await pick('Off'); + expect(first.savedField()).toMatchObject({ fieldHistory: false }); + cleanup(); + const second = renderField({ photo: { type: 'image', label: 'Photo' } }, 'photo'); + await pick('On'); + expect(second.savedField()).toMatchObject({ fieldHistory: true }); + }); + + it('a stored false goes back to Default: the key is removed, not written', async () => { + const { savedField } = renderField({ notes: { type: 'textarea', label: 'Notes', fieldHistory: false } }, 'notes'); + expect(choice()).toHaveTextContent(/^Off$/); + await pick('Default (On)'); + expect(savedField()).not.toHaveProperty('fieldHistory'); + }); + + it('draws no Track history box, writes no trackHistory, and keeps a stored one', async () => { + const { savedField } = renderField({ doc: { type: 'json', label: 'Doc', trackHistory: true } }, 'doc'); + expect(screen.queryByRole('checkbox', { name: /track history/i })).toBeNull(); + await pick('Off'); + expect(savedField()).toEqual({ type: 'json', label: 'Doc', trackHistory: true, fieldHistory: false }); + cleanup(); + const plain = renderField({ notes: { type: 'textarea', label: 'Notes' } }, 'notes'); + await pick('On'); + expect(plain.savedField()).not.toHaveProperty('trackHistory'); + }); + + it("resolves Default against the object: the object's own off makes it Default (Off), and says so", () => { + renderField({ notes: { type: 'textarea', label: 'Notes' } }, 'notes', { enable: { fieldHistory: false } }); + expect(choice()).toHaveTextContent('Default (Off)'); + expect(screen.getByTestId('field-history-object-off')).toHaveTextContent(/turns field change values off for every field/); + }); + + it('CONTROL: an object that leaves it unset shows no object-off note', () => { + renderField({ notes: { type: 'textarea', label: 'Notes' } }, 'notes', { enable: { feeds: false } }); + expect(screen.queryByTestId('field-history-object-off')).toBeNull(); + }); +}); diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx index 044dd821e91..6963d10f3d4 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.tsx @@ -55,6 +55,7 @@ import { isAggregateCompatibleWithFieldType, MULTI_OPTION_TYPES, NUMERIC_VALUE_TYPES, + resolveFieldHistory, SelectOptionSchema, SINGLE_OPTION_TYPES, summaryFunctionReadsField, @@ -156,6 +157,7 @@ import { type FormulaReturnVerdict, } from '../celAuthoring.js'; import { t, tFormat, type SupportedLocale } from '../i18n.js'; +import { fieldHistoryChoiceOf, fieldHistoryOptions, fieldHistoryValueOf } from '../fieldHistoryChoice.js'; import { FilterConditionField } from './FilterConditionField.js'; import type { FilterCondition } from './datasetFilterCondition.js'; import { usePickerLoad, type LoadState } from '../loadState.js'; @@ -1554,6 +1556,15 @@ export function ObjectFieldInspector({ // A stored field computed from its `expression` (a formula is computed by // its type, and keeps its own readings). const computedByExpression = type !== 'formula' && isExpressionComputedField(def); + // objectstack#36290 — what an unset `fieldHistory` resolves to for this + // field ON THIS OBJECT: the predicate the activity writer uses, asked with + // the field's own `fieldHistory` left out and the object document in hand. + const objectEnable = draft.enable && typeof draft.enable === 'object' ? (draft.enable as { fieldHistory?: unknown }) : undefined; + const objectFieldHistoryOff = objectEnable?.fieldHistory === false; + const fieldHistoryDefaultOn = resolveFieldHistory( + { type: def.type, trackHistory: def.trackHistory }, + { managedBy: draft.managedBy, enable: objectEnable }, + ); // The siblings an expression may read: every field but this one (a field // computed from itself is circular), named as every other surface names it. const siblingFieldNames = view.entries.map((e) => e.name).filter((n) => n !== entry.name); @@ -2004,12 +2015,6 @@ export function ObjectFieldInspector({ onCommit={(v) => patchDef({ hidden: v || undefined })} disabled={locked} /> - patchDef({ trackHistory: v || undefined })} - disabled={locked} - /> {/* objectstack-ai/objectstack#36425 — whether a create asks for the field. On is the default and is written as no key (removed, not set to `undefined`); off writes `showOnCreate: false`. A required field is always asked for (the @@ -2026,6 +2031,31 @@ export function ObjectFieldInspector({ {tr('designer.field.showOnCreateRequired')}

)} + {/* objectstack#36290 — whether a change to this field shows its + old → new values on the record activity: Default (removes the + key) / On / Off, the same three choices as the metadata form's + `field-history` widget (`fieldHistoryChoice.ts`). This rail holds + the whole object, so Default is resolved against it too: the + object's own off wins, and the row says so. There is no Track + history box beside it any more: a field's `trackHistory: false` + reads like absent, and `true` only does what On does for a media + or JSON field; a stored value is kept, never written here. */} + { + const next = fieldHistoryValueOf(v); + if (next === undefined) unsetDefKey('fieldHistory'); + else patchDef({ fieldHistory: next }); + }} + disabled={locked} + /> + {objectFieldHistoryOff && ( +

+ {tr('designer.field.fieldHistoryObjectOff')} +

+ )} onChange(next === 'on' ? true : next === 'off' ? false : undefined)} + value={fieldHistoryChoiceOf(value)} + onValueChange={(next) => onChange(fieldHistoryValueOf(next))} disabled={readOnly} > - {defaultLabel} - {t('engine.form.fieldHistoryOn', locale)} - {t('engine.form.fieldHistoryOff', locale)} + {fieldHistoryOptions(defaultOn, locale).map((o) => ( + + {o.label} + + ))} ); diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.businessWording-36512.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.businessWording-36512.test.tsx index ea824e7eb9b..9eab20d5f09 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.businessWording-36512.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.businessWording-36512.test.tsx @@ -79,6 +79,7 @@ const SETTING_KEYS = [ 'highlightFields', 'relatedLists', 'enable.trackHistory', + 'enable.fieldHistory', 'enable.files', 'enable.feeds', 'enable.activities', diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.test.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.test.tsx index 09786d041a2..b74274f24d7 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.test.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.test.tsx @@ -6,7 +6,7 @@ * LICENSE file in the root directory of this source tree. */ import { describe, it, expect, vi } from 'vitest'; -import { render, screen, fireEvent, within } from '@testing-library/react'; +import { render, screen, fireEvent, within, cleanup } from '@testing-library/react'; import React from 'react'; import { t } from '../metadata-admin/i18n'; import { ObjectSettingsPanel } from './ObjectSettingsPanel'; @@ -160,3 +160,42 @@ describe('ObjectSettingsPanel — capabilities (enable.*, framework#2707/#2727)' expect(onPatch).toHaveBeenCalledWith({ enable: { trackHistory: true } }); }); }); + +/** + * objectstack-ai/objectstack#36290 (ruling 7076513167 point 1) — field change + * values show by default and an object can turn them off. `enable.fieldHistory` + * has no default: unset is on, so the switch writes `false` to turn values off + * and removes the key to turn them back on. + */ +describe('ObjectSettingsPanel — field change values (enable.fieldHistory, #36290)', () => { + const box = () => screen.getByTestId('cap-fieldHistory') as HTMLInputElement; + + it('is on when the key is unset or true, off only on a literal false', () => { + renderPanel(baseDraft); + expect(box().checked).toBe(true); + cleanup(); + renderPanel({ ...baseDraft, enable: { fieldHistory: true } }); + expect(box().checked).toBe(true); + cleanup(); + renderPanel({ ...baseDraft, enable: { fieldHistory: false } }); + expect(box().checked).toBe(false); + }); + + it('turning it off writes enable.fieldHistory: false, preserving sibling keys', () => { + const onPatch = renderPanel({ ...baseDraft, enable: { trackHistory: true, files: true } }); + fireEvent.click(box()); + expect(onPatch.mock.calls).toEqual([[{ enable: { trackHistory: true, files: true, fieldHistory: false } }]]); + }); + + it('turning it back on removes the key rather than writing true, preserving sibling keys', () => { + const onPatch = renderPanel({ ...baseDraft, enable: { fieldHistory: false, feeds: false } }); + fireEvent.click(box()); + expect(onPatch.mock.calls).toEqual([[{ enable: { feeds: false } }]]); + }); + + it('is labelled by its title, separate from Field change history', () => { + renderPanel(baseDraft); + expect(screen.getByLabelText(t('engine.studio.settings.capFieldHistory', 'en-US'))).toBe(box()); + expect(t('engine.studio.settings.capFieldHistory', 'en-US')).not.toBe(t('engine.studio.settings.capTrackHistory', 'en-US')); + }); +}); diff --git a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.tsx b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.tsx index eea3582520b..52a1dc2a5a7 100644 --- a/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.tsx +++ b/ui/packages/app-shell/src/views/studio-design/ObjectSettingsPanel.tsx @@ -40,7 +40,10 @@ * switches. Only LIVE flags are exposed (every toggle is enforced at * runtime — writer gates, 403s, or UI surfaces): trackHistory & files * are opt-IN (spec default false), feeds/activities/clone are opt-OUT - * (spec default true, explicit false disables). `trash`/`mru` were + * (spec default true, explicit false disables). fieldHistory + * (objectstack#36290) has NO default: unset shows values, so its switch + * writes `false` to turn them off and REMOVES the key to turn them back + * on — never a `true` the author did not need. `trash`/`mru` were * REMOVED from the spec (framework#2377 — ObjectCapabilities is now * .strict(), authoring them is a parse error). * 5. Developer options — the same inspector's developer half: the internal @@ -312,11 +315,20 @@ export function ObjectSettingsPanel({ // EFFECTIVE runtime value; toggling writes an explicit boolean into the // enable block (preserving sibling keys). trackHistory/files are opt-in // (=== true enables); searchable/feeds/activities/clone are opt-out (only - // an explicit false disables). + // an explicit false disables). fieldHistory is opt-out with no default + // (objectstack#36290): on is the key ABSENT, so turning it on removes it. const enable = (draft.enable && typeof draft.enable === 'object' ? draft.enable : {}) as Record; - const patchEnable = (key: string, value: boolean) => onPatch({ enable: { ...enable, [key]: value } }); - const CAPABILITIES: Array<{ key: string; optIn: boolean; labelKey: string; descKey: string }> = [ + const patchEnable = (key: string, value: boolean, unsetWhenOn = false) => { + if (value && unsetWhenOn) { + const { [key]: _removed, ...rest } = enable; + onPatch({ enable: rest }); + return; + } + onPatch({ enable: { ...enable, [key]: value } }); + }; + const CAPABILITIES: Array<{ key: string; optIn: boolean; unsetWhenOn?: boolean; labelKey: string; descKey: string }> = [ { key: 'trackHistory', optIn: true, labelKey: 'engine.studio.settings.capTrackHistory', descKey: 'engine.studio.settings.capTrackHistoryDesc' }, + { key: 'fieldHistory', optIn: false, unsetWhenOn: true, labelKey: 'engine.studio.settings.capFieldHistory', descKey: 'engine.studio.settings.capFieldHistoryDesc' }, { key: 'files', optIn: true, labelKey: 'engine.studio.settings.capFiles', descKey: 'engine.studio.settings.capFilesDesc' }, { key: 'feeds', optIn: false, labelKey: 'engine.studio.settings.capFeeds', descKey: 'engine.studio.settings.capFeedsDesc' }, { key: 'activities', optIn: false, labelKey: 'engine.studio.settings.capActivities', descKey: 'engine.studio.settings.capActivitiesDesc' }, @@ -514,7 +526,7 @@ export function ObjectSettingsPanel({
- {CAPABILITIES.map(({ key, optIn, labelKey, descKey }) => { + {CAPABILITIES.map(({ key, optIn, unsetWhenOn, labelKey, descKey }) => { const raw = enable[key]; const checked = optIn ? raw === true : raw !== false; // The title and the description both label the switch; the key @@ -528,7 +540,7 @@ export function ObjectSettingsPanel({ checked={checked} disabled={disabled} data-testid={`cap-${key}`} - onChange={(e) => patchEnable(key, e.target.checked)} + onChange={(e) => patchEnable(key, e.target.checked, unsetWhenOn)} className="mt-0.5" /> diff --git a/ui/packages/i18n/src/namespaces/studio/en.ts b/ui/packages/i18n/src/namespaces/studio/en.ts index 053bda57eaf..4d22e553e63 100644 --- a/ui/packages/i18n/src/namespaces/studio/en.ts +++ b/ui/packages/i18n/src/namespaces/studio/en.ts @@ -393,7 +393,9 @@ const STUDIO_EN: Record = { 'designer.field.description': 'Description', 'designer.field.readonly': 'Read-only', 'designer.field.hidden': 'Hidden', - 'designer.field.trackHistory': 'Track history', + 'designer.field.fieldHistory': 'Field change values', + 'designer.field.fieldHistoryObjectOff': + 'This object turns field change values off for every field, so changes to this field name the field only, whatever is chosen here.', 'designer.field.showOnCreate': 'Show on create', 'designer.field.showOnCreateRequired': 'A required field is always asked for when a record is created, so Show on create stays on.', 'designer.field.placeholder': 'Placeholder', @@ -2448,7 +2450,10 @@ const STUDIO_EN: Record = { 'engine.studio.settings.capabilitiesHint': 'Turn record-page features on or off for this object; every switch really takes effect', 'engine.studio.settings.capTrackHistory': 'Field change history', 'engine.studio.settings.capTrackHistoryDesc': - "Shows the record's field changes: on the default record page they join the record's one timeline stream, under its Changes filter. Pair with per-field history tracking to pick which field diffs are summarized; audit capture itself is always on for compliance.", + "Shows the record's field changes: on the default record page they join the record's one timeline stream, under its Changes filter. Whether a change shows its old → new values is Field change values, below; audit capture itself is always on for compliance.", + 'engine.studio.settings.capFieldHistory': 'Field change values', + 'engine.studio.settings.capFieldHistoryDesc': + "Shows each changed field's old → new values in the record's activity. On by default, and a single field can turn its own off. Off = a change names its fields only, for every field of this object.", 'engine.studio.settings.capFiles': 'Attachments', 'engine.studio.settings.capFilesDesc': 'Generic Attachments panel on record pages (upload/download/delete). Off = the server also rejects new attachments targeting this object.', diff --git a/ui/packages/i18n/src/namespaces/studio/zh.ts b/ui/packages/i18n/src/namespaces/studio/zh.ts index 5a79059a897..d71c00eae63 100644 --- a/ui/packages/i18n/src/namespaces/studio/zh.ts +++ b/ui/packages/i18n/src/namespaces/studio/zh.ts @@ -315,7 +315,8 @@ const STUDIO_ZH: Record = { 'designer.field.description': '描述', 'designer.field.readonly': '只读', 'designer.field.hidden': '隐藏', - 'designer.field.trackHistory': '记录历史', + 'designer.field.fieldHistory': '字段修改值', + 'designer.field.fieldHistoryObjectOff': '该对象已对所有字段关闭修改值,所以无论这里怎么选,该字段的修改都只写出字段名。', 'designer.field.showOnCreate': '新建时显示', 'designer.field.showOnCreateRequired': '必填字段新建时总要填写,所以「新建时显示」保持开启。', 'designer.field.placeholder': '占位符', @@ -2229,7 +2230,10 @@ const STUDIO_ZH: Record = { 'engine.studio.settings.capabilitiesHint': '为本对象打开或关闭记录页上的功能;每个开关都会真正生效', 'engine.studio.settings.capTrackHistory': '字段变更历史', 'engine.studio.settings.capTrackHistoryDesc': - '显示记录的字段变更:在默认记录页上,它们并入记录唯一的时间线,归在「变更」筛选下。配合字段级历史跟踪可选择汇总哪些字段的差异;审计采集本身始终开启(合规要求)。', + '显示记录的字段变更:在默认记录页上,它们并入记录唯一的时间线,归在「变更」筛选下。变更是否显示旧值 → 新值由下方的「字段修改值」决定;审计采集本身始终开启(合规要求)。', + 'engine.studio.settings.capFieldHistory': '字段修改值', + 'engine.studio.settings.capFieldHistoryDesc': + '在记录的动态里显示每个被修改字段的旧值 → 新值。默认开启,单个字段可以自行关闭。关闭后,该对象所有字段的修改都只写出字段名。', 'engine.studio.settings.capFiles': '附件', 'engine.studio.settings.capFilesDesc': '记录页通用附件面板(上传/下载/删除)。关闭后服务端同时拒绝指向该对象的新附件。', From 58cef60a1c55b69573aed85f52c5503d831e0c0a Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 04:51:01 +0000 Subject: [PATCH 2/4] test(studio): two inspector sibling pins name Field change values, not Track history (#36290) The Advanced row's Track history box became the Field change values choice; the External ID and Indexed retirement pins listed it among the siblings that still render. Both files now pay the formula and lint loads at collection (check:test-source-alias judges a file a change edits). Claude-Session: https://claude.ai/code/session_01ADHkmPq6z7KER4Sr6Uu7Ht Co-authored-by: Claude --- ...ObjectFieldInspector.externalIdNotOffered-26674.test.tsx | 6 +++++- .../inspectors/ObjectFieldInspector.retiredIndexed.test.tsx | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.externalIdNotOffered-26674.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.externalIdNotOffered-26674.test.tsx index d981cee70f7..9d739e1fc64 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.externalIdNotOffered-26674.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.externalIdNotOffered-26674.test.tsx @@ -26,6 +26,9 @@ vi.mock('../previews/useObjectFields', () => ({ useObjectFields: () => ({ fields: [], loading: false, error: null }), })); +// Paid at collection, not inside a case's clock (check:test-source-alias). +import '@objectstack/formula'; +import '@objectstack/lint'; import { ObjectFieldInspector } from './ObjectFieldInspector'; afterEach(cleanup); @@ -58,7 +61,8 @@ describe('ObjectFieldInspector · no External ID switch (objectstack#26674)', () expect(screen.queryByText('External ID')).toBeNull(); expect(screen.getByText('Read-only')).toBeInTheDocument(); expect(screen.getByText('Hidden')).toBeInTheDocument(); - expect(screen.getByText('Track history')).toBeInTheDocument(); + // objectstack#36290 — the Track history box became the Field change values choice. + expect(screen.getByText('Field change values')).toBeInTheDocument(); }); it('a stored externalId does not resurrect the control', () => { diff --git a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.retiredIndexed.test.tsx b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.retiredIndexed.test.tsx index c82db2054c8..5661ab337b2 100644 --- a/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.retiredIndexed.test.tsx +++ b/ui/packages/app-shell/src/views/metadata-admin/inspectors/ObjectFieldInspector.retiredIndexed.test.tsx @@ -38,6 +38,9 @@ vi.mock('../previews/useObjectFields', () => ({ useObjectFields: () => ({ fields: [], loading: false, error: null }), })); +// Paid at collection, not inside a case's clock (check:test-source-alias). +import '@objectstack/formula'; +import '@objectstack/lint'; import { ObjectFieldInspector } from './ObjectFieldInspector'; afterEach(cleanup); @@ -72,7 +75,8 @@ describe('ObjectFieldInspector · the Indexed toggle is retired (objectui#4644)' // targeted retirement, not a section that failed to render. expect(screen.getByText('Read-only')).toBeInTheDocument(); expect(screen.getByText('Hidden')).toBeInTheDocument(); - expect(screen.getByText('Track history')).toBeInTheDocument(); + // objectstack#36290 — the Track history box became the Field change values choice. + expect(screen.getByText('Field change values')).toBeInTheDocument(); }); it('renders no Indexed control even on a draft that already carries the key', () => { From ffa608defd6fa8e6ff7f82c4bbcb28db97158c96 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 05:35:26 +0000 Subject: [PATCH 3/4] feat(studio): the field designer writes Field Change Values, not Track History (#36290 part 1) The FieldDesigner drawer's Track History switch wrote trackHistory: false on every save. It becomes Field Change Values (Default / On / Off over the field's fieldHistory), drawn as two rows shown by visibleWhen for the types whose Default resolves on or off (resolveFieldHistory), so Default names the right state after a type change; the save reads the row shown for the saved type. A stored trackHistory rides the edit spread and is never written. DesignerFieldDefinition and its zod mirror gain fieldHistory; MetadataFieldsPage and MetadataService.toFieldPayload carry it. The eleven language packs swap appDesigner.fieldDesigner.trackHistory for the four fieldHistory keys. Claude-Session: https://claude.ai/code/session_01ADHkmPq6z7KER4Sr6Uu7Ht Co-authored-by: Claude --- .changeset/36290-field-history-producers.md | 7 +- .../MetadataService.fieldKeyCarryOver.test.ts | 2 + .../app-shell/src/services/MetadataService.ts | 3 + ui/packages/i18n/src/locales/ar.ts | 5 +- ui/packages/i18n/src/locales/de.ts | 5 +- ui/packages/i18n/src/locales/en.ts | 5 +- ui/packages/i18n/src/locales/es.ts | 5 +- ui/packages/i18n/src/locales/fr.ts | 5 +- ui/packages/i18n/src/locales/ja.ts | 5 +- ui/packages/i18n/src/locales/ko.ts | 5 +- ui/packages/i18n/src/locales/pt-BR.ts | 5 +- ui/packages/i18n/src/locales/ru.ts | 5 +- ui/packages/i18n/src/locales/zh-Hans.ts | 5 +- ui/packages/i18n/src/locales/zh-Hant.ts | 5 +- .../plugin-designer/src/FieldDesigner.tsx | 98 +++++++++- ...ldsPage.externalIdRoundTrip-26674.test.tsx | 2 +- ...dataFieldsPage.fieldHistory-36290.test.tsx | 142 ++++++++++++++ .../src/MetadataFieldsPage.tsx | 4 + ...signer.externalIdNotOffered-26674.test.tsx | 7 +- .../FieldDesigner.fieldHistory-36290.test.tsx | 175 ++++++++++++++++++ .../src/hooks/useDesignerTranslation.ts | 5 +- .../__tests__/designer-zod-arms-10859.test.ts | 2 +- ui/packages/types/src/designer.ts | 14 +- ui/packages/types/src/zod/designer.zod.ts | 1 + 24 files changed, 489 insertions(+), 28 deletions(-) create mode 100644 ui/packages/plugin-designer/src/MetadataFieldsPage.fieldHistory-36290.test.tsx create mode 100644 ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx diff --git a/.changeset/36290-field-history-producers.md b/.changeset/36290-field-history-producers.md index 4e39ada45fd..17f763cd110 100644 --- a/.changeset/36290-field-history-producers.md +++ b/.changeset/36290-field-history-producers.md @@ -1,9 +1,11 @@ --- '@object-ui/app-shell': patch '@object-ui/i18n': patch +'@object-ui/types': patch +'@object-ui/plugin-designer': patch --- -feat(studio): the field inspector and the object's settings write Field change values instead of Track history +feat(studio): the field inspector, the field designer and the object's settings write Field change values instead of Track history Clause-②: yes (widening) Metadata-protocol: none @@ -11,6 +13,7 @@ Metadata-protocol: none Old → new values show on the record activity by default, and an object or a single field can turn them off. The Studio now writes that setting where an author looks for it: - **Field inspector.** The "Track history" box is gone. In its place, "Field change values" offers Default, On and Off. Default leaves the field's `fieldHistory` unset and names what it means for this field on this object: "Default (On)" for most types, "Default (Off)" for a media, JSON or credential field, and "Default (Off)" for every field when the object turns values off, with a note saying so. On and Off write `fieldHistory: true` and `false`; choosing Default after Off removes the key. A stored `trackHistory` is kept as it is and never written. +- **Field designer** (`@object-ui/plugin-designer`). The drawer's "Track History" switch, which wrote `trackHistory: false` on every save, is replaced by "Field Change Values" with the same three choices: Default (named "Default (On)" or "Default (Off)" for the type in the drawer, and it follows a type change), On, Off. A stored `trackHistory` is carried through an edit and never written. `DesignerFieldDefinition` (`@object-ui/types`, with its zod mirror) gains an optional `fieldHistory`, and both designer save paths (`MetadataFieldsPage`, `MetadataService.saveFields`) carry it; Default sends no key, which removes a stored one. - **Object settings.** The Features card gains "Field change values" (`enable.fieldHistory`). Unticking it writes `false`; ticking it again removes the key rather than writing `true`, since unset already means on. Sibling `enable` keys are kept. -The three choices, what each writes and their wording are shared with the metadata form's Field History control, so the two surfaces cannot drift. New Studio strings `designer.field.fieldHistory`, `designer.field.fieldHistoryObjectOff`, `engine.studio.settings.capFieldHistory` and `engine.studio.settings.capFieldHistoryDesc` (en, zh); `designer.field.trackHistory` is removed with the box it labelled. +The inspector and the metadata form's Field History control share one module for the three choices, what each writes and their wording; the field designer cannot import it (the app shell depends on the designer) and shares the rule itself, `resolveFieldHistory` from `@objectstack/spec/data`. New Studio strings `designer.field.fieldHistory`, `designer.field.fieldHistoryObjectOff`, `engine.studio.settings.capFieldHistory` and `engine.studio.settings.capFieldHistoryDesc` (en, zh); `designer.field.trackHistory` is removed with the box it labelled. In the language packs, `appDesigner.fieldDesigner.trackHistory` is replaced by `appDesigner.fieldDesigner.fieldHistory`, `fieldHistoryDefault`, `fieldHistoryOn` and `fieldHistoryOff`, in all eleven locales. diff --git a/ui/packages/app-shell/src/services/MetadataService.fieldKeyCarryOver.test.ts b/ui/packages/app-shell/src/services/MetadataService.fieldKeyCarryOver.test.ts index e99d95eaa58..dce1fb64553 100644 --- a/ui/packages/app-shell/src/services/MetadataService.fieldKeyCarryOver.test.ts +++ b/ui/packages/app-shell/src/services/MetadataService.fieldKeyCarryOver.test.ts @@ -314,6 +314,7 @@ describe('objectui#6488 · the mirror — carry-over must NOT resurrect what the options: [{ label: 'One', value: '1' }], externalId: true, trackHistory: true, + fieldHistory: false, reference: 'opportunity', // …and one key the designer does not model, as the positive control. expression: 'price * quantity', @@ -334,6 +335,7 @@ describe('objectui#6488 · the mirror — carry-over must NOT resurrect what the 'options', 'externalId', 'trackHistory', + 'fieldHistory', 'reference', ] as const; diff --git a/ui/packages/app-shell/src/services/MetadataService.ts b/ui/packages/app-shell/src/services/MetadataService.ts index 34314eae79e..3afcc2ff998 100644 --- a/ui/packages/app-shell/src/services/MetadataService.ts +++ b/ui/packages/app-shell/src/services/MetadataService.ts @@ -119,6 +119,8 @@ export interface FieldMetadataPayload { options?: Array<{ label: string; value: string; color?: string }>; externalId?: boolean; trackHistory?: boolean; + /** objectstack#36290 — the field's own old → new values switch; absent follows the platform. */ + fieldHistory?: boolean; // No `indexed` (objectui#4644): the spec has no field-level index flag — // `FieldSchema.safeParse` rejects the key by name, so writing it made // `PUT /api/v1/meta/object/:name` fail with 422 `INVALID_METADATA`. @@ -628,6 +630,7 @@ function toFieldPayload( options: field.options, externalId: field.externalId, trackHistory: field.trackHistory, + fieldHistory: field.fieldHistory, reference: field.referenceTo, }; } diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 42698752b5b..2f3b25cbf6d 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -2295,7 +2295,10 @@ const ar = { unique: "فريد", readOnly: "للقراءة فقط", hidden: "مخفي", - trackHistory: "تتبع السجل", + fieldHistory: "قيم تغيير الحقل", + fieldHistoryDefault: "افتراضي ({{state}})", + fieldHistoryOn: "تشغيل", + fieldHistoryOff: "إيقاف", defaultValue: "القيمة الافتراضية", placeholder: "نص تلميحي", referenceTo: "مرجع إلى", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 46f852c42d9..1ee33a02cc7 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -2063,7 +2063,10 @@ const de = { unique: "Eindeutig", readOnly: "Nur lesen", hidden: "Ausgeblendet", - trackHistory: "Verlauf verfolgen", + fieldHistory: "Feldänderungswerte", + fieldHistoryDefault: "Standard ({{state}})", + fieldHistoryOn: "Ein", + fieldHistoryOff: "Aus", defaultValue: "Standardwert", placeholder: "Platzhalter", referenceTo: "Verweis auf", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 7ce40ffee43..95de4df8a0f 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -2495,7 +2495,10 @@ const en = { unique: 'Unique', readOnly: 'Read Only', hidden: 'Hidden', - trackHistory: 'Track History', + fieldHistory: 'Field Change Values', + fieldHistoryDefault: 'Default ({{state}})', + fieldHistoryOn: 'On', + fieldHistoryOff: 'Off', defaultValue: 'Default Value', placeholder: 'Placeholder', referenceTo: 'Reference To', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 58fc7d00002..532d850e851 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -2123,7 +2123,10 @@ const es = { unique: "Único", readOnly: "Solo lectura", hidden: "Oculto", - trackHistory: "Rastrear historial", + fieldHistory: "Valores de cambio del campo", + fieldHistoryDefault: "Predeterminado ({{state}})", + fieldHistoryOn: "Activado", + fieldHistoryOff: "Desactivado", defaultValue: "Valor predeterminado", placeholder: "Marcador de posición", referenceTo: "Referencia a", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index e7ba839f101..5668bfc868d 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -2119,7 +2119,10 @@ const fr = { unique: "Unique", readOnly: "Lecture seule", hidden: "Masqué", - trackHistory: "Suivre l'historique", + fieldHistory: "Valeurs de modification du champ", + fieldHistoryDefault: "Par défaut ({{state}})", + fieldHistoryOn: "Activé", + fieldHistoryOff: "Désactivé", defaultValue: "Valeur par défaut", placeholder: "Espace réservé", referenceTo: "Référence à", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 9bfb56a969e..50b2ce1e6e9 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -2063,7 +2063,10 @@ const ja = { unique: "ユニーク", readOnly: "読み取り専用", hidden: "非表示", - trackHistory: "履歴追跡", + fieldHistory: "項目の変更値", + fieldHistoryDefault: "デフォルト({{state}})", + fieldHistoryOn: "オン", + fieldHistoryOff: "オフ", defaultValue: "デフォルト値", placeholder: "プレースホルダー", referenceTo: "参照先", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index ee1e1927a95..d953289df13 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -2063,7 +2063,10 @@ const ko = { unique: "고유", readOnly: "읽기 전용", hidden: "숨김", - trackHistory: "기록 추적", + fieldHistory: "필드 변경 값", + fieldHistoryDefault: "기본값({{state}})", + fieldHistoryOn: "켜기", + fieldHistoryOff: "끄기", defaultValue: "기본값", placeholder: "자리 표시자", referenceTo: "참조 대상", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 85980e3ed3e..e704d856c52 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -2118,7 +2118,10 @@ const pt = { unique: "Único", readOnly: "Somente leitura", hidden: "Oculto", - trackHistory: "Rastrear histórico", + fieldHistory: "Valores de alteração do campo", + fieldHistoryDefault: "Padrão ({{state}})", + fieldHistoryOn: "Ativado", + fieldHistoryOff: "Desativado", defaultValue: "Valor padrão", placeholder: "Espaço reservado", referenceTo: "Referência a", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 0e6567aab77..bb42be32d60 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -2183,7 +2183,10 @@ const ru = { unique: "Уникальное", readOnly: "Только чтение", hidden: "Скрытое", - trackHistory: "Отслеживать историю", + fieldHistory: "Значения изменений поля", + fieldHistoryDefault: "По умолчанию ({{state}})", + fieldHistoryOn: "Вкл.", + fieldHistoryOff: "Выкл.", defaultValue: "Значение по умолчанию", placeholder: "Заполнитель", referenceTo: "Ссылка на", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index fb62845eb0e..e2a8c48c4d2 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -2130,7 +2130,10 @@ const zh = { unique: '唯一', readOnly: '只读', hidden: '隐藏', - trackHistory: '追踪历史', + fieldHistory: '字段修改值', + fieldHistoryDefault: '默认({{state}})', + fieldHistoryOn: '开', + fieldHistoryOff: '关', defaultValue: '默认值', placeholder: '占位文本', referenceTo: '引用对象', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index 51de8ac5dfc..45f34a9d232 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -2130,7 +2130,10 @@ const zhHant = { unique: '唯一', readOnly: '只讀', hidden: '隱藏', - trackHistory: '追蹤歷史', + fieldHistory: '欄位修改值', + fieldHistoryDefault: '預設({{state}})', + fieldHistoryOn: '開', + fieldHistoryOff: '關', defaultValue: '預設值', placeholder: '佔位文本', referenceTo: '引用物件', diff --git a/ui/packages/plugin-designer/src/FieldDesigner.tsx b/ui/packages/plugin-designer/src/FieldDesigner.tsx index a0985e1770f..2b8b36c34c7 100644 --- a/ui/packages/plugin-designer/src/FieldDesigner.tsx +++ b/ui/packages/plugin-designer/src/FieldDesigner.tsx @@ -15,7 +15,8 @@ */ import React, { useState, useCallback, useMemo } from 'react'; -import type { DesignerFieldDefinition, DesignerFieldType } from '@object-ui/types'; +import { DESIGNER_FIELD_TYPES, type DesignerFieldDefinition, type DesignerFieldType } from '@object-ui/types'; +import { resolveFieldHistory } from '@objectstack/spec/data'; import type { ObjectGridSchema, ListColumn } from '@object-ui/types'; import { ObjectGrid } from '@object-ui/plugin-grid'; import { DrawerForm } from '@object-ui/plugin-form'; @@ -173,6 +174,49 @@ interface TypeFilterGroup { * - It stays enabled in read-only mode, as the native control did: it filters * the list and writes nothing. */ +// ============================================================================ +// Field change values (`fieldHistory`, objectstack#36290) +// ============================================================================ + +/** + * The drawer's Field Change Values row offers the same three choices as the + * Studio's other `fieldHistory` controls (`fieldHistoryChoice.ts` in + * `@object-ui/app-shell`): Default removes the key and names what it resolves + * to for the field's type, On writes `true`, Off writes `false`. That module + * cannot be imported here — app-shell depends on this package — so what is + * shared is the rule itself, `resolveFieldHistory` from `@objectstack/spec/data`, + * the predicate the activity writer keeps or drops values with; the three-way + * mapping below is the same two lines. + * + * Default's label depends on the TYPE, which the author can change in the same + * drawer, and a select's options are static. So the row is drawn twice under + * two form-local names, one per resolved default, each shown by `visibleWhen` + * for the types it covers; the save reads the row visible for the saved type, + * which is the one on screen at the click. Neither name is ever written. + */ +type FieldHistoryChoice = 'default' | 'on' | 'off'; +const FIELD_HISTORY_ROW_DEFAULT_ON = 'fieldHistoryDefaultOn'; +const FIELD_HISTORY_ROW_DEFAULT_OFF = 'fieldHistoryDefaultOff'; + +function fieldHistoryChoiceOf(value: unknown): FieldHistoryChoice { + return value === true ? 'on' : value === false ? 'off' : 'default'; +} + +function fieldHistoryValueOf(choice: unknown): boolean | undefined { + return choice === 'on' ? true : choice === 'off' ? false : undefined; +} + +/** Whether Default resolves to on for `type`, given the field's stored `trackHistory`. */ +function fieldHistoryDefaultOn(type: unknown, trackHistory: unknown): boolean { + return resolveFieldHistory({ type, trackHistory }, undefined); +} + +/** The `fieldHistory` the drawer's submitted values choose, read from the row shown for the saved type. */ +function fieldHistoryFromForm(data: Record, type: unknown, trackHistory: unknown): boolean | undefined { + const row = fieldHistoryDefaultOn(type, trackHistory) ? FIELD_HISTORY_ROW_DEFAULT_ON : FIELD_HISTORY_ROW_DEFAULT_OFF; + return fieldHistoryValueOf(data[row]); +} + function TypeFilterPicker({ value, allLabel, @@ -342,8 +386,13 @@ export function FieldDesigner({ hidden: data.hidden === true, // No `externalId` here (objectstack#26674): the drawer no longer // offers it, so the spread above carries a stored value through an - // edit untouched. - trackHistory: data.trackHistory === true, + // edit untouched. Nor `trackHistory` (objectstack#36290): the spread + // carries a stored one, and the drawer writes `fieldHistory` instead. + fieldHistory: fieldHistoryFromForm( + data, + (data.type as DesignerFieldType) || editingField.type, + editingField.trackHistory, + ), defaultValue: data.defaultValue ? String(data.defaultValue) : undefined, placeholder: data.placeholder ? String(data.placeholder) : undefined, referenceTo: data.referenceTo ? String(data.referenceTo) : undefined, @@ -362,7 +411,7 @@ export function FieldDesigner({ unique: data.unique === true, readonly: data.readonly === true, hidden: data.hidden === true, - trackHistory: data.trackHistory === true, + fieldHistory: fieldHistoryFromForm(data, (data.type as DesignerFieldType) || 'text', undefined), defaultValue: data.defaultValue ? String(data.defaultValue) : undefined, placeholder: data.placeholder ? String(data.placeholder) : undefined, referenceTo: data.referenceTo ? String(data.referenceTo) : undefined, @@ -407,6 +456,29 @@ export function FieldDesigner({ [typeOptionsByCategory, editingField], ); + // objectstack#36290 — the two Field Change Values rows (see + // `fieldHistoryFromForm`): which types each covers, and their options. + const fieldHistoryRows = useMemo(() => { + const storedTrackHistory = editingField?.trackHistory; + const offTypes = DESIGNER_FIELD_TYPES.filter((ft) => !fieldHistoryDefaultOn(ft, storedTrackHistory)); + const inOff = `record.type in [${offTypes.map((ft) => `'${ft}'`).join(', ')}]`; + const options = (defaultOn: boolean) => [ + { + label: t('appDesigner.fieldDesigner.fieldHistoryDefault', { + state: t(defaultOn ? 'appDesigner.fieldDesigner.fieldHistoryOn' : 'appDesigner.fieldDesigner.fieldHistoryOff'), + }), + value: 'default', + }, + { label: t('appDesigner.fieldDesigner.fieldHistoryOn'), value: 'on' }, + { label: t('appDesigner.fieldDesigner.fieldHistoryOff'), value: 'off' }, + ]; + const label = t('appDesigner.fieldDesigner.fieldHistory'); + return [ + { name: FIELD_HISTORY_ROW_DEFAULT_ON, label, type: 'select' as const, options: options(true), disabled: readOnly, visibleWhen: `!(${inOff})` }, + { name: FIELD_HISTORY_ROW_DEFAULT_OFF, label, type: 'select' as const, options: options(false), disabled: readOnly, visibleWhen: inOff }, + ]; + }, [editingField, readOnly, t]); + // DrawerForm schema — right-side panel with Basic / Type-specific / Advanced sections const drawerSchema = useMemo(() => ({ type: 'object-form', @@ -479,7 +551,10 @@ export function FieldDesigner({ // the switch only invited an author to rely on it. A stored value // is carried through an edit by `handleFormSuccess`'s spread, never // stripped. - { name: 'trackHistory', label: t('appDesigner.fieldDesigner.trackHistory'), type: 'boolean', disabled: readOnly }, + // objectstack#36290 — Field Change Values (`fieldHistory`) in + // place of the old Track History switch, whose `false` no longer + // turns values off; a stored `trackHistory` rides the edit spread. + ...fieldHistoryRows, { name: 'readonly', label: t('appDesigner.fieldDesigner.readOnly'), type: 'boolean', disabled: readOnly }, { name: 'hidden', label: t('appDesigner.fieldDesigner.hidden'), type: 'boolean', disabled: readOnly }, ], @@ -496,16 +571,23 @@ export function FieldDesigner({ unique: editingField.unique || false, readonly: editingField.readonly || false, hidden: editingField.hidden || false, - trackHistory: editingField.trackHistory || false, + [FIELD_HISTORY_ROW_DEFAULT_ON]: fieldHistoryChoiceOf(editingField.fieldHistory), + [FIELD_HISTORY_ROW_DEFAULT_OFF]: fieldHistoryChoiceOf(editingField.fieldHistory), defaultValue: editingField.defaultValue != null ? String(editingField.defaultValue) : '', placeholder: editingField.placeholder || '', referenceTo: editingField.referenceTo || '', } - : { type: 'text', required: false, unique: false }, + : { + type: 'text', + required: false, + unique: false, + [FIELD_HISTORY_ROW_DEFAULT_ON]: 'default', + [FIELD_HISTORY_ROW_DEFAULT_OFF]: 'default', + }, onSuccess: handleFormSuccess, onCancel: () => handleFormClose(false), readOnly, - }), [editingField, formOpen, handleFormClose, handleFormSuccess, flatTypeOptions, readOnly, t]); + }), [editingField, formOpen, handleFormClose, handleFormSuccess, flatTypeOptions, fieldHistoryRows, readOnly, t]); return (
expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); // The drawer no longer offers the switch it would otherwise have reset. - expect(screen.getByTestId('drawer-field-trackHistory')).toBeTruthy(); + expect(screen.getByTestId('drawer-field-fieldHistoryDefaultOn')).toBeTruthy(); expect(screen.queryByTestId('drawer-field-externalId')).toBeNull(); fireEvent.click(screen.getByTestId('drawer-submit')); diff --git a/ui/packages/plugin-designer/src/MetadataFieldsPage.fieldHistory-36290.test.tsx b/ui/packages/plugin-designer/src/MetadataFieldsPage.fieldHistory-36290.test.tsx new file mode 100644 index 00000000000..d1d945640cc --- /dev/null +++ b/ui/packages/plugin-designer/src/MetadataFieldsPage.fieldHistory-36290.test.tsx @@ -0,0 +1,142 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack-ai/objectstack#36290 — an edit-and-save through this page + * carries the field's `fieldHistory` both ways and never writes + * `trackHistory`. Before this card the drawer's update path wrote + * `trackHistory: data.trackHistory === true`, so every saved field gained an + * explicit `false`, and the page had no `fieldHistory` to carry. + * + * The REAL `FieldDesigner` (only the grid and form renderers are mocked; the + * form mock submits the drawer's initial values) over a REAL `MetadataClient` + * and a fetch double: the assertions are on the PUT bytes. + */ + +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; +import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react'; +import { FieldSchema } from '@objectstack/spec/data'; +import { MetadataClient } from '@object-ui/data-objectstack'; + +vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({ + ...(await importOriginal>()), + ...(await import('./__tests__/__mocks__/plugin-grid')), +})); +vi.mock('@object-ui/plugin-form', async (importOriginal) => ({ + ...(await importOriginal>()), + ...(await import('./__tests__/__mocks__/plugin-form')), +})); + +import { MetadataFieldsPage } from './MetadataFieldsPage'; + +/** + * objectstack#30786 — the page takes its edit base off the layered read + * (`GET …/layers`, `overlay ?? code`), not the served item read, so this double + * answers that read: the item it used to serve becomes the `code` layer (and + * `effective`), beside the same envelope carriers. + */ +function servedAsLayers({ item, ...carriers }: { item: unknown } & Record) { + return { ...carriers, code: item, overlay: null, effective: item }; +} + +/** + * `muted` turns its values off; `photo` opts a media field in through the + * older key; `title` carries neither. + */ +const OBJECT_BODY = { + name: 'probe_widget', + label: 'Widget', + fields: { + muted: { type: 'text', label: 'Muted', fieldHistory: false }, + photo: { type: 'image', label: 'Photo', trackHistory: true }, + title: { type: 'text', label: 'Title' }, + }, +}; + +const OBJECT_ENVELOPE = { + type: 'object', + name: 'probe_widget', + item: OBJECT_BODY, + lock: 'none', + provenance: 'org', + editable: true, +}; + +let puts: Array> = []; + +function json(body: unknown, status = 200): Response { + return new Response(JSON.stringify(body), { + status, + headers: { 'content-type': 'application/json' }, + }); +} + +function realClient(): MetadataClient { + return new MetadataClient({ + baseUrl: 'http://localhost:3000', + fetch: (async (input: RequestInfo | URL, init?: RequestInit) => { + const url = String(input); + const method = (init?.method ?? 'GET').toUpperCase(); + if (method === 'PUT') { + puts.push(JSON.parse(String(init?.body ?? '{}')) as Record); + return json({ success: true, name: 'probe_widget' }); + } + if (/\/meta\/object\/probe_widget\/layers(\?|$)/.test(url)) return json(servedAsLayers(OBJECT_ENVELOPE)); + return json({ items: [] }); + }) as unknown as typeof fetch, + }); +} + +/** The fields map exactly as it went over the wire on the last PUT. */ +function savedFields(): Record> { + return puts[puts.length - 1].fields as Record>; +} + +beforeEach(() => { + puts = []; +}); + +afterEach(cleanup); + +async function editAndSave(name: string) { + render(); + fireEvent.click(await screen.findByTestId(`grid-edit-${name}`)); + await waitFor(() => expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); + fireEvent.click(screen.getByTestId('drawer-submit')); + await waitFor(() => expect(puts).toHaveLength(1)); + return savedFields(); +} + +describe('objectstack#36290 · fieldHistory round-trips, trackHistory is never written', () => { + it('keeps a stored fieldHistory: false on the edited field, and writes no trackHistory', async () => { + const fields = await editAndSave('muted'); + expect(fields.muted.fieldHistory).toBe(false); + expect(fields.muted).not.toHaveProperty('trackHistory'); + // Falsification: the save re-serialised the edited field intact. + expect(fields.muted.label).toBe('Muted'); + }); + + it('keeps a stored trackHistory: true through an edit, and adds no fieldHistory', async () => { + const fields = await editAndSave('photo'); + expect(fields.photo.trackHistory).toBe(true); + expect(fields.photo).not.toHaveProperty('fieldHistory'); + }); + + it('CONTROL: a field with neither key gains neither', async () => { + const fields = await editAndSave('title'); + expect(fields.title).not.toHaveProperty('trackHistory'); + expect(fields.title).not.toHaveProperty('fieldHistory'); + }); + + it('every field it PUTs parses through the real FieldSchema', async () => { + const fields = await editAndSave('muted'); + for (const [name, def] of Object.entries(fields)) { + expect(FieldSchema.safeParse(def).success, `field \`${name}\` did not parse`).toBe(true); + } + }); +}); diff --git a/ui/packages/plugin-designer/src/MetadataFieldsPage.tsx b/ui/packages/plugin-designer/src/MetadataFieldsPage.tsx index 4077c9ea6b3..f11a2cd8226 100644 --- a/ui/packages/plugin-designer/src/MetadataFieldsPage.tsx +++ b/ui/packages/plugin-designer/src/MetadataFieldsPage.tsx @@ -72,6 +72,8 @@ interface ServerFieldSchema { group?: string; externalId?: boolean; trackHistory?: boolean; + /** objectstack#36290 — the field's own old → new values switch; absent follows the platform. */ + fieldHistory?: boolean; /** * Relationship target object name. The spec spells it `reference` * (objectui#6041) — `referenceTo` is refused BY NAME by `FieldSchema`, so @@ -252,6 +254,7 @@ function toDesignerField(name: string, raw: ServerFieldSchema): DesignerFieldDef isSystem: raw.system, externalId: raw.externalId, trackHistory: raw.trackHistory, + fieldHistory: raw.fieldHistory, referenceTo: storedRelationshipTarget(raw), }; } @@ -467,6 +470,7 @@ function fromDesignerField( group: designed.group, externalId: designed.externalId, trackHistory: designed.trackHistory, + fieldHistory: designed.fieldHistory, reference: designed.referenceTo, }; } diff --git a/ui/packages/plugin-designer/src/__tests__/FieldDesigner.externalIdNotOffered-26674.test.tsx b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.externalIdNotOffered-26674.test.tsx index 2879bc4bcd8..287e91be91e 100644 --- a/ui/packages/plugin-designer/src/__tests__/FieldDesigner.externalIdNotOffered-26674.test.tsx +++ b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.externalIdNotOffered-26674.test.tsx @@ -59,8 +59,9 @@ describe('objectstack#26674 · the drawer offers no External ID switch', () => { fireEvent.click(screen.getByTestId('grid-add-btn')); await waitFor(() => expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); - // POSITIVE CONTROL: a sibling of the same ADVANCED section. - expect(screen.getByTestId('drawer-field-trackHistory')).toBeTruthy(); + // POSITIVE CONTROL: a sibling of the same ADVANCED section (Field Change + // Values, objectstack#36290, in place of the old Track History switch). + expect(screen.getByTestId('drawer-field-fieldHistoryDefaultOn')).toBeTruthy(); expect(screen.queryByTestId('drawer-field-externalId')).toBeNull(); }); @@ -69,7 +70,7 @@ describe('objectstack#26674 · the drawer offers no External ID switch', () => { await openEditDrawer('code'); expect(screen.getByTestId('drawer-mode').textContent).toBe('edit'); - expect(screen.getByTestId('drawer-field-trackHistory')).toBeTruthy(); + expect(screen.getByTestId('drawer-field-fieldHistoryDefaultOn')).toBeTruthy(); expect(screen.queryByTestId('drawer-field-externalId')).toBeNull(); }); }); diff --git a/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx new file mode 100644 index 00000000000..7715fd0b001 --- /dev/null +++ b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx @@ -0,0 +1,175 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +/** + * objectstack-ai/objectstack#36290 (ruling 7076513167 point 1) — the Field + * Designer drawer writes a field's `fieldHistory` with the Studio's three + * choices (Default removes the key and names what it resolves to for the + * type; On; Off) and never writes `trackHistory`, which it used to set to + * `data.trackHistory === true` on every save. + * + * The drawer draws the choice twice, one row per resolved default, each shown + * by `visibleWhen` for its types; the save reads the row shown for the saved + * type. This captures the schema the real `FieldDesigner` hands its drawer and + * calls its own `onSuccess` with the values a form would submit. + */ + +import React from 'react'; +import { describe, it, expect, vi, afterEach } from 'vitest'; +import { render, screen, fireEvent, waitFor, cleanup, act } from '@testing-library/react'; +import { DESIGNER_FIELD_TYPES, type DesignerFieldDefinition } from '@object-ui/types'; +import { evalFieldPredicate } from '@object-ui/core'; +import { resolveFieldHistory } from '@objectstack/spec/data'; +import { FieldDesigner } from '../FieldDesigner'; + +const drawer = vi.hoisted(() => ({ schema: undefined as undefined | Record })); + +vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({ + ...(await importOriginal>()), + ...(await import('./__mocks__/plugin-grid')), +})); +vi.mock('@object-ui/plugin-form', async (importOriginal) => ({ + ...(await importOriginal>()), + DrawerForm: ({ schema }: { schema: Record }) => { + drawer.schema = schema; + return schema.open === false ? null :
; + }, +})); + +const ON_ROW = 'fieldHistoryDefaultOn'; +const OFF_ROW = 'fieldHistoryDefaultOff'; + +const FIELDS: DesignerFieldDefinition[] = [ + { id: 'notes', name: 'notes', label: 'Notes', type: 'textarea' }, + { id: 'photo', name: 'photo', label: 'Photo', type: 'image', trackHistory: true }, + { id: 'muted', name: 'muted', label: 'Muted', type: 'text', fieldHistory: false }, +]; + +afterEach(() => { + cleanup(); + drawer.schema = undefined; +}); + +function renderDesigner() { + const changed = vi.fn(); + render(); + return changed; +} + +async function openEdit(name: string) { + fireEvent.click(await screen.findByTestId(`grid-edit-${name}`)); + await waitFor(() => expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); +} + +async function openCreate() { + fireEvent.click(screen.getByTestId('grid-add-btn')); + await waitFor(() => expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); +} + +function advancedRows(): Array> { + return drawer.schema!.sections.find((s: { name: string }) => s.name === 'advanced').fields; +} + +function row(name: string): Record { + return advancedRows().find((f) => f.name === name)!; +} + +/** Submit the drawer with its initial values, overridden by `values`; the field the save emitted. */ +function submit(changed: ReturnType, name: string, values: Record = {}) { + act(() => { + drawer.schema!.onSuccess({ ...drawer.schema!.initialValues, ...values }); + }); + const emitted: DesignerFieldDefinition[] = changed.mock.calls.at(-1)![0]; + return emitted.find((f) => f.name === name)!; +} + +describe('FieldDesigner · Field Change Values rows (#36290)', () => { + it('draws two Field Change Values rows in Advanced and no Track History row', async () => { + renderDesigner(); + await openCreate(); + const names = advancedRows().map((f) => f.name); + expect(names).toEqual(expect.arrayContaining([ON_ROW, OFF_ROW])); + expect(names).not.toContain('trackHistory'); + expect(row(ON_ROW).label).toBe('Field Change Values'); + expect(row(ON_ROW).options.map((o: { label: string }) => o.label)).toEqual(['Default (On)', 'On', 'Off']); + expect(row(OFF_ROW).options.map((o: { label: string }) => o.label)).toEqual(['Default (Off)', 'On', 'Off']); + }); + + it('for every designer type exactly one row shows, and it is the one resolveFieldHistory names', async () => { + renderDesigner(); + await openCreate(); + for (const type of DESIGNER_FIELD_TYPES) { + const defaultOn = resolveFieldHistory({ type }, undefined); + const onShown = evalFieldPredicate(row(ON_ROW).visibleWhen, { type }, false); + const offShown = evalFieldPredicate(row(OFF_ROW).visibleWhen, { type }, true); + expect([type, onShown, offShown]).toEqual([type, defaultOn, !defaultOn]); + } + }); + + it("a field's stored trackHistory: true moves a media type to the Default (On) row", async () => { + renderDesigner(); + await openEdit('photo'); + expect(evalFieldPredicate(row(ON_ROW).visibleWhen, { type: 'image' }, false)).toBe(true); + expect(evalFieldPredicate(row(OFF_ROW).visibleWhen, { type: 'image' }, true)).toBe(false); + }); +}); + +describe('FieldDesigner · what a save writes (#36290)', () => { + it('an untouched edit writes no fieldHistory and no trackHistory', async () => { + const changed = renderDesigner(); + await openEdit('notes'); + const saved = submit(changed, 'notes'); + expect(saved.fieldHistory).toBeUndefined(); + expect(saved).not.toHaveProperty('trackHistory'); + expect(saved.label).toBe('Notes'); + }); + + it('Off on a one-line type writes fieldHistory: false; On on a media type writes true', async () => { + const changed = renderDesigner(); + await openEdit('notes'); + expect(submit(changed, 'notes', { [ON_ROW]: 'off' }).fieldHistory).toBe(false); + cleanup(); + const again = renderDesigner(); + await openCreate(); + const created = submit(again, 'new_field_4', { name: 'new_field_4', type: 'file', [OFF_ROW]: 'on' }); + expect(created.fieldHistory).toBe(true); + expect(created).not.toHaveProperty('trackHistory'); + }); + + it('a stored false opens as Off, and Default removes it', async () => { + const changed = renderDesigner(); + await openEdit('muted'); + expect(drawer.schema!.initialValues[ON_ROW]).toBe('off'); + expect(submit(changed, 'muted').fieldHistory).toBe(false); + expect(submit(changed, 'muted', { [ON_ROW]: 'default' }).fieldHistory).toBeUndefined(); + }); + + it('keeps a stored trackHistory through an edit', async () => { + const changed = renderDesigner(); + await openEdit('photo'); + expect(submit(changed, 'photo').trackHistory).toBe(true); + }); + + it('reads the row shown for the SAVED type: a type changed in the drawer saves what is on screen', async () => { + const changed = renderDesigner(); + await openEdit('notes'); + // Off was picked while the type was textarea, then the type became file: + // the row on screen is now the Default (Off) one, still at Default. + const saved = submit(changed, 'notes', { [ON_ROW]: 'off', type: 'file' }); + expect(saved.type).toBe('file'); + expect(saved.fieldHistory).toBeUndefined(); + }); + + it('a created field at Default carries neither key', async () => { + const changed = renderDesigner(); + await openCreate(); + const created = submit(changed, 'new_field_4', { name: 'new_field_4' }); + expect(created.fieldHistory).toBeUndefined(); + expect(created).not.toHaveProperty('trackHistory'); + }); +}); diff --git a/ui/packages/plugin-designer/src/hooks/useDesignerTranslation.ts b/ui/packages/plugin-designer/src/hooks/useDesignerTranslation.ts index 4a0efe59bcb..9359cd8b223 100644 --- a/ui/packages/plugin-designer/src/hooks/useDesignerTranslation.ts +++ b/ui/packages/plugin-designer/src/hooks/useDesignerTranslation.ts @@ -182,7 +182,10 @@ export const DESIGNER_DEFAULT_TRANSLATIONS: Record = { 'appDesigner.fieldDesigner.unique': 'Unique', 'appDesigner.fieldDesigner.readOnly': 'Read Only', 'appDesigner.fieldDesigner.hidden': 'Hidden', - 'appDesigner.fieldDesigner.trackHistory': 'Track History', + 'appDesigner.fieldDesigner.fieldHistory': 'Field Change Values', + 'appDesigner.fieldDesigner.fieldHistoryDefault': 'Default ({{state}})', + 'appDesigner.fieldDesigner.fieldHistoryOn': 'On', + 'appDesigner.fieldDesigner.fieldHistoryOff': 'Off', 'appDesigner.fieldDesigner.defaultValue': 'Default Value', 'appDesigner.fieldDesigner.placeholder': 'Placeholder', 'appDesigner.fieldDesigner.referenceTo': 'Reference To', diff --git a/ui/packages/types/src/__tests__/designer-zod-arms-10859.test.ts b/ui/packages/types/src/__tests__/designer-zod-arms-10859.test.ts index eea7e1f1afd..14e3359a0a8 100644 --- a/ui/packages/types/src/__tests__/designer-zod-arms-10859.test.ts +++ b/ui/packages/types/src/__tests__/designer-zod-arms-10859.test.ts @@ -310,7 +310,7 @@ const FULL = [ id: 'f1', name: 'rating', label: 'Rating', type: 'select', group: 'General', description: 'How hot', required: false, unique: false, readonly: false, hidden: false, defaultValue: 'warm', placeholder: 'Pick', options: [{ label: 'Warm', value: 'warm', color: 'orange' }], - isSystem: false, externalId: false, trackHistory: true, referenceTo: 'account', + isSystem: false, externalId: false, trackHistory: true, fieldHistory: false, referenceTo: 'account', }, ], readOnly: false, diff --git a/ui/packages/types/src/designer.ts b/ui/packages/types/src/designer.ts index 7a21dcf653c..44cc71d0932 100644 --- a/ui/packages/types/src/designer.ts +++ b/ui/packages/types/src/designer.ts @@ -1266,8 +1266,20 @@ export interface DesignerFieldDefinition { isSystem?: boolean; /** External ID flag */ externalId?: boolean; - /** Track field history */ + /** + * Track field history — the spec's `trackHistory`: `true` opts a media or + * JSON field into old → new values on the record activity; `false` reads + * like absent. Carried through an edit as stored; `FieldDesigner` offers no + * control for it (objectstack#36290). + */ trackHistory?: boolean; + /** + * The spec's `fieldHistory` (objectstack#36290): this field's old → new + * values on the record activity. Absent follows the platform default + * (`resolveFieldHistory` in `@objectstack/spec/data`); `false` turns them + * off; `true` turns them on, a media or JSON field included. + */ + fieldHistory?: boolean; /* * There is deliberately no `indexed` here (objectui#4644). The ObjectStack * spec has no field-level index flag: it built no index (objectstack#2377 diff --git a/ui/packages/types/src/zod/designer.zod.ts b/ui/packages/types/src/zod/designer.zod.ts index d36fdc02d9a..1b5f06afe4d 100644 --- a/ui/packages/types/src/zod/designer.zod.ts +++ b/ui/packages/types/src/zod/designer.zod.ts @@ -643,6 +643,7 @@ export const DesignerFieldDefinitionSchema = z.looseObject({ isSystem: z.boolean().optional().describe('Whether this is a system field'), externalId: z.boolean().optional().describe('External ID flag'), trackHistory: z.boolean().optional().describe('Track field history'), + fieldHistory: z.boolean().optional().describe("This field's old → new values on the record activity; absent follows the platform default"), referenceTo: z.string().optional().describe('Lookup reference object (for lookup type)'), }); From 3b5b130c032826c165b7cfe6796bc7c4a09eff23 Mon Sep 17 00:00:00 2001 From: Claude Date: Mon, 23 Nov 2026 05:58:47 +0000 Subject: [PATCH 4/4] test(studio): the designer field-history pin types its drawer double (#36290) Claude-Session: https://claude.ai/code/session_01ADHkmPq6z7KER4Sr6Uu7Ht Co-authored-by: Claude --- .../FieldDesigner.fieldHistory-36290.test.tsx | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx index 7715fd0b001..1fa4538524d 100644 --- a/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx +++ b/ui/packages/plugin-designer/src/__tests__/FieldDesigner.fieldHistory-36290.test.tsx @@ -27,7 +27,21 @@ import { evalFieldPredicate } from '@object-ui/core'; import { resolveFieldHistory } from '@objectstack/spec/data'; import { FieldDesigner } from '../FieldDesigner'; -const drawer = vi.hoisted(() => ({ schema: undefined as undefined | Record })); +/** The parts of the drawer schema this file reads. */ +interface DrawerRow { + name: string; + label?: string; + options?: Array<{ label: string; value: string }>; + visibleWhen?: string; +} +interface SeenDrawerSchema { + open?: boolean; + initialValues: Record; + onSuccess: (values: Record) => void; + sections: Array<{ name: string; fields: DrawerRow[] }>; +} + +const drawer = vi.hoisted(() => ({ schema: undefined as undefined | SeenDrawerSchema })); vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({ ...(await importOriginal>()), @@ -35,7 +49,7 @@ vi.mock('@object-ui/plugin-grid', async (importOriginal) => ({ })); vi.mock('@object-ui/plugin-form', async (importOriginal) => ({ ...(await importOriginal>()), - DrawerForm: ({ schema }: { schema: Record }) => { + DrawerForm: ({ schema }: { schema: SeenDrawerSchema }) => { drawer.schema = schema; return schema.open === false ? null :
; }, @@ -71,11 +85,11 @@ async function openCreate() { await waitFor(() => expect(screen.getByTestId('mock-drawer-form')).toBeTruthy()); } -function advancedRows(): Array> { - return drawer.schema!.sections.find((s: { name: string }) => s.name === 'advanced').fields; +function advancedRows(): DrawerRow[] { + return drawer.schema!.sections.find((s) => s.name === 'advanced')!.fields; } -function row(name: string): Record { +function row(name: string): DrawerRow { return advancedRows().find((f) => f.name === name)!; } @@ -96,8 +110,8 @@ describe('FieldDesigner · Field Change Values rows (#36290)', () => { expect(names).toEqual(expect.arrayContaining([ON_ROW, OFF_ROW])); expect(names).not.toContain('trackHistory'); expect(row(ON_ROW).label).toBe('Field Change Values'); - expect(row(ON_ROW).options.map((o: { label: string }) => o.label)).toEqual(['Default (On)', 'On', 'Off']); - expect(row(OFF_ROW).options.map((o: { label: string }) => o.label)).toEqual(['Default (Off)', 'On', 'Off']); + expect(row(ON_ROW).options!.map((o) => o.label)).toEqual(['Default (On)', 'On', 'Off']); + expect(row(OFF_ROW).options!.map((o) => o.label)).toEqual(['Default (Off)', 'On', 'Off']); }); it('for every designer type exactly one row shows, and it is the one resolveFieldHistory names', async () => {