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
23 changes: 23 additions & 0 deletions .changeset/36290-field-change-history-card.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
'@object-ui/plugin-detail': patch
'@object-ui/plugin-grid': patch
'@object-ui/components': patch
'@object-ui/types': patch
'@object-ui/i18n': patch
'@objectstack/spec': patch
---

feat(record-page): one field's change history, opened in place from the field or from a list cell's context menu

Clause-②: yes (widening) — three new `detail.*` language-pack keys in every locale `@object-ui/i18n` ships (`fieldHistory`, `fieldHistoryNone`, `fieldHistoryNoneRecent`); new exports from `@object-ui/plugin-detail` (`FieldHistoryButton`, `FieldHistoryCard`, `FieldHistoryPopover`, `useFieldHistory`, `useFieldHistoryOffered`, `fieldHistoryOffered`, the constants `FIELD_HISTORY_PAGE_SIZE`, `FIELD_HISTORY_SCAN_BATCH` and `FIELD_HISTORY_SCAN_BATCHES_PER_LOAD`, and their types); an optional `column` member on the context `data-table` hands a host's `renderRowContextMenu`; `FieldChangeItem` draws no label for `label: ''`; nothing is removed or renamed
Metadata-protocol: none

A reader can now see one field's past changes on one record without reading the whole activity stream.

- On the record page, each field of the object has a history button beside its value, shown on hover and focus like the copy button. In a list, right-clicking a cell of a field the object declares adds 「Change history」 to the row's menu. Both open the same small card in place. Neither is offered on a field whose old → new values are not recorded (`fieldHistory: false` on the field, `enable.fieldHistory: false` on the object, a credential field, or a media or JSON-like type that does not opt in), judged by the same `resolveFieldHistory` the audit writer keeps values by.
- The card lists only that field's changes: who, when, and old → new in the reader's words (an option by its label, an empty side as the pack's word for empty), newest first, ten at a time with 「Load more」.
- A field never changed reads 「No changes recorded」 with who created the record and when.
- The changes are the record's activity rows the server already serves, narrowed to the reader: a change of a field the reader may not read is never sent. A field the reader may not read offers no entry point at all. The full audit log is not read.
- The rows are read by record, newest first, fifty at a time, keeping those that changed the field; a query naming the change columns is refused for a reader withheld any field of the object, so the field is never part of the query. Opening the card reads at most four batches, and each 「Load more」 at most four more; when they hold no change of the field and older rows remain, the card reads 「No changes in the recent activity」 and offers 「Load more」 to read on.

`@objectstack/spec`: the authoring hint for the mistyped field key `tracked` now names what turns one field's change history on or off today (`fieldHistory: false`, `true` for a media or JSON field, `enable.fieldHistory: false` on the object), where it named `trackHistory: true`, which changes nothing for most field types. Wording only; `tracked` stays rejected.
33 changes: 33 additions & 0 deletions content/docs/frontend/plugins/plugin-detail.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,39 @@ draws its own field editor reuses the write by rendering
shortcuts (its dialogs only), and `ref.current(draft)` saves. The default
`face` is `"bar"`.

## A field's change history

Each field of the object on the record page has a history button beside its
value, shown on hover and on keyboard focus like the copy button. In a list,
right-clicking a cell of a field the object declares adds **Change history**
to the row's menu. Both open the same small card in place
(`FieldHistoryButton`, `FieldHistoryPopover`, both drawing `FieldHistoryCard`):

- only that field's changes on that record: who, when, and old → new in the
reader's words (an option by its label, an empty side as the word for empty),
newest first, ten at a time with **Load more**;
- for a field never changed, **No changes recorded** with who created the
record and when.

The card reads the record's activity rows (`sys_activity`), the rows the
activity stream draws, and keeps those that changed the field. The server
serves each row's changes narrowed to the reader, so a value the reader may not
read never reaches the browser, and a field the reader may not read
(`checkField(object, field, 'read')`) offers no history at all. Nor does a
field whose old → new values are not recorded (`resolveFieldHistory` from
`@objectstack/spec/data`: `fieldHistory: false` on the field,
`enable.fieldHistory: false` on the object, a credential field, or a media or
JSON-like type that does not opt in with `fieldHistory: true`), and nor do the
platform's own record columns (`id`, `created_at`, …).

The rows are read by record, fifty at a time: a query naming a change column
is refused for a reader withheld any field of the object, so the field is never
part of the query. Opening the card reads at most four batches
(`FIELD_HISTORY_SCAN_BATCHES_PER_LOAD`), and each **Load more** at most four
more. When they hold no change of the field and older rows remain, the card
says **No changes in the recent activity** and offers **Load more** to read on;
it says **No changes recorded** only once every row has been read.

## The record's comment panel

On the desktop console, a record's comments live in a panel of their own,
Expand Down
12 changes: 12 additions & 0 deletions content/docs/frontend/plugins/plugin-grid.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,18 @@ authored `navigation: { mode: 'none' }` or `navigation.preventNavigation: true`
(whatever its mode, objectstack#33549) and for an object whose data API serves
no single-record read (objectstack#33317).

### A cell's change history

Right-clicking a cell of a field the object declares adds **Change history**
to the row's context menu, when the grid's data source can read activity
(`find`), the field's changes are recorded with their values
(`resolveFieldHistory` from `@objectstack/spec/data`) and the reader may read
the field. Choosing it opens
`@object-ui/plugin-detail`'s `FieldHistoryPopover` at that point: that
record's changes of that field, newest first, ten at a time, or **No changes
recorded** with who created the record. `data-table` names the cell's column to
the host's `renderRowContextMenu` as `context.column`.

### Inline Editing

Enable inline cell editing for quick data updates:
Expand Down
20 changes: 20 additions & 0 deletions packages/spec/src/data/field.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,26 @@ describe('FieldSchema — field-level `currency` key guidance, naming `currencyC
});
});

// objectstack#36615 — the `tracked` answer names the switch a field's change
// history has today (`fieldHistory`), not `trackHistory: true`, which turns
// nothing on for most field types since field history became on by default.
describe('FieldSchema — field-level `tracked` key guidance, naming `fieldHistory`', () => {
const FIELD = { name: 'notes', label: 'Notes', type: 'textarea' } as const;

it('`tracked` stays rejected and names `fieldHistory`, whose off form really parses', () => {
const m = unrecognizedKeyMessage({ ...FIELD, tracked: true });
expect(m).toContain('`tracked` is not a field key');
expect(m).toContain('fieldHistory: false');
expect(m).not.toContain('trackHistory: true');
expect(FieldSchema.safeParse({ ...FIELD, fieldHistory: false }).success).toBe(true);
});

it('a sibling unknown key does NOT get the field-history prescription (anti-vacuity)', () => {
const m = unrecognizedKeyMessage({ ...FIELD, totallyBogusKey: true });
expect(m).not.toContain('fieldHistory');
});
});

describe('FieldSchema', () => {
describe('Basic Field Properties', () => {
it('should accept valid field with minimal properties', () => {
Expand Down
5 changes: 4 additions & 1 deletion packages/spec/src/data/field.zod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1685,7 +1685,10 @@ export const FieldSchema = lazySchema(() => {
// CASE-SENSITIVELY on the authored spelling, so a row per spelling is the
// only way this channel can cover a family, and `not_null` was the spelling
// it would have missed.
tracked: '`tracked` is not a field key — per-field timeline tracking is `trackHistory: true` (ADR-0052 §5b).',
tracked:
'`tracked` is not a field key — a field\'s old → new values show on the record activity timeline '
+ 'by default. Write `fieldHistory: false` to turn them off for this field (`true` opts a media or '
+ 'structured-JSON field in), or `enable.fieldHistory: false` on the object to turn them off for every field.',
// [ADR-0158 L3] The natural spellings of a quantity's unit on the field
// itself, answered in prose because the targets are NESTED keys of
// `unitConfig` — the form the `currency` answer above takes. None of them
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,27 @@ describe('objectstack#28434 · a host renderer decides alone', () => {
// The host's items only — the table's own are not mixed in.
expect(itemIds(menu)).toEqual(['host-item']);
expect(menu).toHaveTextContent('Host item for r2');
expect(renderRowContextMenu).toHaveBeenCalledWith(expect.objectContaining({ id: 'r2' }), { selected: false });
// objectstack#36290 — the context also names the data cell's column.
expect(renderRowContextMenu).toHaveBeenCalledWith(expect.objectContaining({ id: 'r2' }), { selected: false, column: 'name' });
});

it('objectstack#36290 · names the column of the data cell it opened on, and none off a data cell', async () => {
const renderRowContextMenu = vi.fn(() => <DropdownMenuItem data-testid="host-item">Host item</DropdownMenuItem>);
renderTable({
...RELATED_LIST_SCHEMA,
columns: [{ header: 'Name', accessorKey: 'name' }, { header: 'Code', accessorKey: 'code' }],
data: ROWS.map((row) => ({ ...row, code: `C-${row.id}` })),
renderRowContextMenu,
});
act(() => { rightClick(cellOf('C-r1')); });
await screen.findByTestId('row-context-menu');
expect(renderRowContextMenu).toHaveBeenLastCalledWith(expect.objectContaining({ id: 'r1' }), { selected: false, column: 'code' });
await userEvent.keyboard('{Escape}');
await waitFor(() => expect(contextMenu()).toBeNull());
// The row's own "⋮" cell is not a data cell: no column.
act(() => { rightClick(within(rowOf('Open contract')).getByTestId('data-table-row-actions').closest('td') as HTMLElement); });
await screen.findByTestId('row-context-menu');
expect(renderRowContextMenu).toHaveBeenLastCalledWith(expect.objectContaining({ id: 'r1' }), { selected: false });
});

it('a host answering null keeps the browser\'s menu', () => {
Expand Down
17 changes: 11 additions & 6 deletions ui/packages/components/src/renderers/complex/data-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
// objectstack#28434 — the row context menu: which row it is open on, where,
// and the element focus goes back to when it closes (the focused cell for
// the keyboard, the cell under the pointer for a right-click).
const [rowContextMenu, setRowContextMenu] = useState<{ row: any; selected: boolean; x: number; y: number } | null>(null);
const [rowContextMenu, setRowContextMenu] = useState<{ row: any; selected: boolean; column?: string; x: number; y: number } | null>(null);
const rowContextMenuReturnFocusRef = useRef<HTMLElement | null>(null);
// The last pointer that pressed a row: a touch long-press raises
// `contextmenu` too, and touch keeps the row's "⋮" instead.
Expand Down Expand Up @@ -4426,9 +4426,9 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
* selection of two or more — a selection is a bulk act, and this table holds
* no bulk actions to offer it — and never on a row with nothing to offer.
*/
const rowContextMenuItems = (row: any, selected: boolean): React.ReactNode => {
const rowContextMenuItems = (row: any, selected: boolean, column?: string): React.ReactNode => {
if (schema.renderRowContextMenu) {
const items = schema.renderRowContextMenu(row, { selected });
const items = schema.renderRowContextMenu(row, column !== undefined ? { selected, column } : { selected });
return items === false || items === undefined ? null : items;
}
if (!rowActions || rowActionsColumnIsEditOnly) return null;
Expand Down Expand Up @@ -4472,7 +4472,10 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
if (pointerType === 'touch') return;
}
if (keepsBrowserContextMenu(target, rowEl)) return;
const items = rowContextMenuItems(row, selected);
// The data cell the menu opened on (objectstack#36290): its column's
// accessor, for the host's cell-level items.
const column = target.closest<HTMLElement>('[data-cell-column]')?.getAttribute('data-cell-column') ?? undefined;
const items = rowContextMenuItems(row, selected, column);
if (items == null) return;
e.preventDefault();
const pointer = fromKeyboard ? null : (e as React.MouseEvent);
Expand All @@ -4491,11 +4494,11 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
const focusable = fromKeyboard ? target : target.closest<HTMLElement>('[tabindex]');
rowContextMenuReturnFocusRef.current = focusable && rowEl.contains(focusable) ? focusable : null;
rowContextMenuClosedOutsideRef.current = false;
setRowContextMenu({ row, selected, x, y });
setRowContextMenu({ row, selected, column, x, y });
};
// The open menu's items, re-asked each render so they follow the row.
const openRowContextMenuItems = rowContextMenu
? rowContextMenuItems(rowContextMenu.row, rowContextMenu.selected)
? rowContextMenuItems(rowContextMenu.row, rowContextMenu.selected, rowContextMenu.column)
: null;
const showToolbar = searchEnabled || exportable || (showSelectionCount && selectable && selectedRowIds.size > 0) || hasPendingChanges;

Expand Down Expand Up @@ -5431,6 +5434,8 @@ const DataTableRenderer = ({ schema }: { schema: DataTableSchema }) => {
// focus tracking exist only in the first case.
tabIndex={keyboardNavigation ? (rowIndex === rovingRowIndex && colIndex === rovingColIndex && !isSelectedCell ? 0 : -1) : 0}
data-grid-cell={keyboardNavigation ? `${rowIndex}:${colIndex}` : undefined}
// objectstack#36290 — which column a context menu opened on.
data-cell-column={col.accessorKey}
onFocus={keyboardNavigation ? () => rove(rowIndex, colIndex) : undefined}
aria-invalid={cellError !== undefined || undefined}
// objectstack#28434 — a cell in edit mode keeps the
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1707,6 +1707,9 @@ const ar = {
fieldChangeEmpty: "فارغ",
fieldChangeExpand: "عرض الكل",
fieldChangeCollapse: "عرض أقل",
fieldHistory: "سجل التغييرات",
fieldHistoryNone: "لا توجد تغييرات مسجلة",
fieldHistoryNoneRecent: "لا توجد تغييرات في النشاط الأخير",
replyCount: "{{count}} رد",
replyCount_zero: "{{count}} رد",
replyCount_one: "{{count}} رد",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,9 @@ const de = {
fieldChangeEmpty: "Leer",
fieldChangeExpand: "Alles anzeigen",
fieldChangeCollapse: "Weniger anzeigen",
fieldHistory: "Änderungsverlauf",
fieldHistoryNone: "Keine Änderungen erfasst",
fieldHistoryNoneRecent: "Keine Änderungen in den letzten Aktivitäten",
replyCount: "{{count}} Antwort",
replyCount_one: "{{count}} Antwort",
replyCount_other: "{{count}} Antworten",
Expand Down
5 changes: 5 additions & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,11 @@ const en = {
fieldChangeEmpty: 'Empty',
fieldChangeExpand: 'Show all',
fieldChangeCollapse: 'Show less',
// objectstack#36290 — one field's change-history card: its entry point's
// name and what it says for a field never changed.
fieldHistory: 'Change history',
fieldHistoryNone: 'No changes recorded',
fieldHistoryNoneRecent: 'No changes in the recent activity',
// Replies
replyCount: '{{count}} reply',
replyCount_one: '{{count}} reply',
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1571,6 +1571,9 @@ const es = {
fieldChangeEmpty: "Vacío",
fieldChangeExpand: "Ver todo",
fieldChangeCollapse: "Ver menos",
fieldHistory: "Historial de cambios",
fieldHistoryNone: "No hay cambios registrados",
fieldHistoryNoneRecent: "No hay cambios en la actividad reciente",
replyCount: "{{count}} respuesta",
replyCount_one: "{{count}} respuesta",
replyCount_many: "{{count}} de respuestas",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ const fr = {
fieldChangeEmpty: "Vide",
fieldChangeExpand: "Tout afficher",
fieldChangeCollapse: "Afficher moins",
fieldHistory: "Historique des modifications",
fieldHistoryNone: "Aucune modification enregistrée",
fieldHistoryNoneRecent: "Aucune modification dans l'activité récente",
replyCount: "{{count}} réponse",
replyCount_one: "{{count}} réponse",
replyCount_many: "{{count}} de réponses",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1610,6 +1610,9 @@ const ja = {
fieldChangeEmpty: "空",
fieldChangeExpand: "すべて表示",
fieldChangeCollapse: "折りたたむ",
fieldHistory: "変更履歴",
fieldHistoryNone: "変更の記録はありません",
fieldHistoryNoneRecent: "最近のアクティビティに変更はありません",
replyCount: "{{count}} 件の返信",
replyCount_one: "{{count}} 件の返信",
replyCount_other: "{{count}} 件の返信",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,9 @@ const ko = {
fieldChangeEmpty: "비어 있음",
fieldChangeExpand: "모두 보기",
fieldChangeCollapse: "접기",
fieldHistory: "변경 기록",
fieldHistoryNone: "변경 기록이 없습니다",
fieldHistoryNoneRecent: "최근 활동에 변경 내역이 없습니다",
replyCount: "답글 {{count}}개",
replyCount_one: "답글 {{count}}개",
replyCount_other: "답글 {{count}}개",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,9 @@ const pt = {
fieldChangeEmpty: "Vazio",
fieldChangeExpand: "Ver tudo",
fieldChangeCollapse: "Ver menos",
fieldHistory: "Histórico de alterações",
fieldHistoryNone: "Nenhuma alteração registrada",
fieldHistoryNoneRecent: "Nenhuma alteração na atividade recente",
replyCount: "{{count}} resposta",
replyCount_one: "{{count}} resposta",
replyCount_many: "{{count}} de respostas",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1722,6 +1722,9 @@ const ru = {
fieldChangeEmpty: "Пусто",
fieldChangeExpand: "Показать полностью",
fieldChangeCollapse: "Свернуть",
fieldHistory: "История изменений",
fieldHistoryNone: "Изменений не зафиксировано",
fieldHistoryNoneRecent: "Нет изменений в недавней активности",
replyCount: "{{count}} ответ",
replyCount_one: "{{count}} ответ",
replyCount_few: "{{count}} ответа",
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,9 @@ const zh = {
fieldChangeEmpty: '空',
fieldChangeExpand: '展开',
fieldChangeCollapse: '收起',
fieldHistory: '修改历史',
fieldHistoryNone: '没有修改记录',
fieldHistoryNoneRecent: '最近的动态里没有修改记录',
// Replies
replyCount: '{{count}} 条回复',
replyCount_one: '{{count}} 条回复',
Expand Down
3 changes: 3 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,9 @@ const zhHant = {
fieldChangeEmpty: '空',
fieldChangeExpand: '展開',
fieldChangeCollapse: '收起',
fieldHistory: '修改歷史',
fieldHistoryNone: '沒有修改記錄',
fieldHistoryNoneRecent: '最近的動態裡沒有修改記錄',
// Replies
replyCount: '{{count}} 條回覆',
replyCount_one: '{{count}} 條回覆',
Expand Down
Loading
Loading