Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .changeset/36290-field-history-producers.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
'@object-ui/app-shell': patch
'@object-ui/i18n': patch
'@object-ui/types': patch
'@object-ui/plugin-designer': patch
---

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

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 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.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -334,6 +335,7 @@ describe('objectui#6488 · the mirror — carry-over must NOT resurrect what the
'options',
'externalId',
'trackHistory',
'fieldHistory',
'reference',
] as const;

Expand Down
3 changes: 3 additions & 0 deletions ui/packages/app-shell/src/services/MetadataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down Expand Up @@ -628,6 +630,7 @@ function toFieldPayload(
options: field.options,
externalId: field.externalId,
trackHistory: field.trackHistory,
fieldHistory: field.fieldHistory,
reference: field.referenceTo,
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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) },
];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) }),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<string, unknown>)[m] = m === 'hasPointerCapture' ? () => false : () => {};
}
}
if (!Element.prototype.scrollIntoView) Element.prototype.scrollIntoView = () => {};
});

function renderField(
fields: Record<string, Record<string, unknown>>,
selectedId: string,
object: Record<string, unknown> = {},
) {
const onPatch = vi.fn();
render(
<ObjectFieldInspector
type="object"
name="probe_widget"
draft={{ name: 'probe_widget', ...object, fields }}
selection={{ kind: 'field', id: selectedId }}
onPatch={onPatch}
onClearSelection={vi.fn()}
onSelectionChange={vi.fn()}
readOnly={false}
locale={'en-US'}
/>,
);
const savedField = () =>
(onPatch.mock.calls.at(-1)![0].fields as Record<string, Record<string, unknown>>)[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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ import {
isAggregateCompatibleWithFieldType,
MULTI_OPTION_TYPES,
NUMERIC_VALUE_TYPES,
resolveFieldHistory,
SelectOptionSchema,
SINGLE_OPTION_TYPES,
summaryFunctionReadsField,
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -2004,12 +2015,6 @@ export function ObjectFieldInspector({
onCommit={(v) => patchDef({ hidden: v || undefined })}
disabled={locked}
/>
<InspectorCheckboxField
label={tr('designer.field.trackHistory')}
value={!!def.trackHistory}
onCommit={(v) => 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
Expand All @@ -2026,6 +2031,31 @@ export function ObjectFieldInspector({
{tr('designer.field.showOnCreateRequired')}
</p>
)}
{/* 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. */}
<InspectorSelectField
label={tr('designer.field.fieldHistory')}
value={fieldHistoryChoiceOf(def.fieldHistory)}
options={fieldHistoryOptions(fieldHistoryDefaultOn, locale)}
onCommit={(v) => {
const next = fieldHistoryValueOf(v);
if (next === undefined) unsetDefKey('fieldHistory');
else patchDef({ fieldHistory: next });
}}
disabled={locked}
/>
{objectFieldHistoryOff && (
<p data-testid="field-history-object-off" className="text-[11px] leading-snug text-muted-foreground">
{tr('designer.field.fieldHistoryObjectOff')}
</p>
)}
</DisplayPatchLock>
<InspectorTextField
label={tr('designer.field.placeholder')}
Expand Down
Loading
Loading