Skip to content
Merged
20 changes: 20 additions & 0 deletions .changeset/36290-activity-field-change-lines.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
'@object-ui/plugin-detail': patch
'@object-ui/i18n': patch
---

feat(record-page): each changed field is its own line under an activity entry, `Label: old → new`

Clause-②: yes (widening) — four new `detail.*` language-pack keys in every locale `@object-ui/i18n` ships (`fieldChangeLabel`, `fieldChangeEmpty`, `fieldChangeExpand`, `fieldChangeCollapse`), and six new optional props on the exported `FieldChangeItem` (`label`, `oldText` / `newText`, `emptyLabel`, `expandLabel` / `collapseLabel`); nothing is removed or renamed
Metadata-protocol: none

The record page's activity named a saved change by its fields only (「更新了 客户备注」), or carried every value on one cut line. An activity entry now reads as the fields it changed, with one line per changed field under it: `Customer notes: Old words → New words`. A save that changed the phone and the email is one entry with two lines.

- The values come from the field-change code the server already serves on each `sys_activity` row (`metadata.summary_message`), narrowed per reader by plugin-audit: a field the reader may not read has no change in it, so it draws no line. Nothing new is read, and nothing is filtered in the browser.
- An empty side reads as the language pack's word for empty (`Empty`, `空`), never the stored `∅`.
- A select side reads as the field's option label in the reader's language; a lookup or user side reads as the record's name the server served; a yes/no reads as the pack's Yes / No.
- Each side is cut to its line. A side that does not fit, or holds more than one line, offers a control that shows both sides in full and one that cuts them again.
- An audit-log entry (objects with `enable.trackHistory`) draws its changes the same way, and an activity row paired with its audit entry keeps its own summary with the audit's lines under it. The record's creation is unchanged: one row with its values beside the summary.
- The compact one-line text of a change (the activity panel's peek rows) now reads `Label: old → new` with the same words, where it read `Label old → new` with `—` for empty.

What does not change: which entries the activity shows, how consecutive edits by one person on one day fold into one row, the activity filters, and no metadata key, value or default.
31 changes: 15 additions & 16 deletions ui/packages/app-shell/src/views/RecordDetailView.harness.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -711,14 +711,14 @@ describe('RecordDetailView.auditDisplayLocale-10442', () => {
/**
* The rendered diff line for `close_date`, under an ENGLISH UI with `locale` as
* the display locale. Since objectstack#27055 the record page draws the audit
* entries in the one 动态 stream, each change as one compact line
* (`data-stream-change`).
* entries in the one 动态 stream; since objectstack#36290 each changed field
* is its own line under the entry (`data-field-change`).
*/
async function diffLine(locale: string): Promise<string> {
renderHistory(locale);
let text = '';
await waitFor(() => {
const line = Array.from(document.querySelectorAll('[data-stream-change]')).find((el) =>
const line = Array.from(document.querySelectorAll('[data-field-change]')).find((el) =>
(el.textContent ?? '').startsWith('Close date'),
);
expect(line).toBeTruthy();
Expand All @@ -729,7 +729,7 @@ describe('RecordDetailView.auditDisplayLocale-10442', () => {
}

const expected = (locale: string) =>
`Close date ${new Date(`${FROM_DATE}T00:00:00Z`).toLocaleDateString(locale)} → ${new Date(`${TO_DATE}T00:00:00Z`).toLocaleDateString(locale)}`;
`Close date: ${new Date(`${FROM_DATE}T00:00:00Z`).toLocaleDateString(locale)} → ${new Date(`${TO_DATE}T00:00:00Z`).toLocaleDateString(locale)}`;

beforeEach(() => {
// Unrelated chrome on this view reaches for the platform API; answering it
Expand All @@ -754,13 +754,13 @@ describe('RecordDetailView.auditDisplayLocale-10442', () => {
describe('RecordDetailView — the audit history dates follow the display locale (objectui#10442)', () => {
it('formats the date diff as de-CH under an English UI with a de-CH display locale', async () => {
const text = await diffLine('de-CH');
expect(text, `got: ${text}`).toBe('Close date 3.3.2020 → 4.3.2020');
expect(text, `got: ${text}`).toBe('Close date: 3.3.2020 → 4.3.2020');
expect(text).toBe(expected('de-CH'));
});

it('control: formats the date diff as en-US under an en-US display locale', async () => {
const text = await diffLine('en-US');
expect(text, `got: ${text}`).toBe('Close date 3/3/2020 → 3/4/2020');
expect(text, `got: ${text}`).toBe('Close date: 3/3/2020 → 3/4/2020');
expect(text).toBe(expected('en-US'));
});

Expand Down Expand Up @@ -892,17 +892,16 @@ describe('RecordDetailView.auditTenantCurrency-27640', () => {
</LocalizationProvider>
</I18nProvider>,
);
// One audit entry draws its changes as one compact line (`data-stream-change`),
// joined with `; `, so each field's part is split out and keyed by label.
// One audit entry draws each changed field as its own line under the entry
// (`data-field-change`, objectstack#36290), keyed here by label.
const lines: Record<string, string> = {};
await waitFor(() => {
const line = Array.from(document.querySelectorAll('[data-stream-change]')).find((el) =>
(el.textContent ?? '').includes('Amount'),
const parts = Array.from(document.querySelectorAll('[data-field-change]')).map((el) =>
(el.textContent ?? '').replace(/\s+/g, ' ').trim(),
);
expect(line, 'no History diff line').toBeTruthy();
const parts = (line!.textContent ?? '').replace(/\s+/g, ' ').trim().split('; ');
expect(parts.length, 'no History diff line').toBeGreaterThan(0);
for (const label of ['Amount', 'List price']) {
const part = parts.find((p) => p.startsWith(`${label} `));
const part = parts.find((p) => p.startsWith(`${label}: `));
expect(part, `no change for ${label} in: ${parts.join(' | ')}`).toBeTruthy();
lines[label] = part!;
}
Expand Down Expand Up @@ -934,17 +933,17 @@ describe('RecordDetailView.auditTenantCurrency-27640', () => {
describe('RecordDetailView — a dynamic currency diff reads in the tenant currency (objectstack#27640)', () => {
it('formats a dynamic-mode change from 1500 to 2500 with the EUR face under an EUR tenant', async () => {
const lines = await diffLines('EUR');
expect(lines['Amount'], `got: ${lines['Amount']}`).toBe('Amount €1,500.00 → €2,500.00');
expect(lines['Amount'], `got: ${lines['Amount']}`).toBe('Amount: €1,500.00 → €2,500.00');
});

it('keeps a record-mode change a plain number: the tenant currency is not its fallback', async () => {
const lines = await diffLines('EUR');
expect(lines['List price'], `got: ${lines['List price']}`).toBe('List price 1,500.00 → 2,500.00');
expect(lines['List price'], `got: ${lines['List price']}`).toBe('List price: 1,500.00 → 2,500.00');
});

it('control: with no tenant currency, the dynamic change reads as a plain number', async () => {
const lines = await diffLines(undefined);
expect(lines['Amount'], `got: ${lines['Amount']}`).toBe('Amount 1,500.00 → 2,500.00');
expect(lines['Amount'], `got: ${lines['Amount']}`).toBe('Amount: 1,500.00 → 2,500.00');
});
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ const LEGITIMATE_IDENTITIES: Record<string, string> = {
// value is the hole alone — a fit decision held by app-shell's
// `appTileOpenedLine-12601.test.ts`, not an omission.
'home.appOpened': 'Tile last-opened line — the bare `{{time}}` hole where no verb fits the tile.',
'detail.fieldChangeLabel': 'Activity field-change line label — the field hole and a separator, no prose; zh-Hans, zh-Hant and ja set a fullwidth colon, fr its space-before-colon, ko/ru/ar keep `:` as their punctuation (objectstack#36290).',
'console.changeOwner.failure': 'Change Owner report row — the row id and the server\'s own sentence joined by a colon, a format string with no word to translate; zh-Hans and fr use their own colon (objectstack#35403).',

// Loanwords these packs have adopted as their OWN vocabulary (checked against
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1685,6 +1685,10 @@ const ar = {
foldedMoreFields_other: "{{count}} أخرى",
expandFolded: "عرض كل تحديث",
collapseFolded: "إخفاء التحديثات",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "فارغ",
fieldChangeExpand: "عرض الكل",
fieldChangeCollapse: "عرض أقل",
replyCount: "{{count}} رد",
replyCount_zero: "{{count}} رد",
replyCount_one: "{{count}} رد",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@ const de = {
foldedMoreFields_other: "{{count}} weitere",
expandFolded: "Jede Aktualisierung anzeigen",
collapseFolded: "Aktualisierungen ausblenden",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "Leer",
fieldChangeExpand: "Alles anzeigen",
fieldChangeCollapse: "Weniger anzeigen",
replyCount: "{{count}} Antwort",
replyCount_one: "{{count}} Antwort",
replyCount_other: "{{count}} Antworten",
Expand Down
7 changes: 7 additions & 0 deletions ui/packages/i18n/src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,13 @@ const en = {
foldedMoreFields_other: '{{count}} more',
expandFolded: 'Show each update',
collapseFolded: 'Hide updates',
// objectstack#36290 — one line per changed field under an activity entry:
// the field's label before its values, the word for an empty side, and
// the control that shows a long value in full and clamps it again.
fieldChangeLabel: '{{field}}:',
fieldChangeEmpty: 'Empty',
fieldChangeExpand: 'Show all',
fieldChangeCollapse: 'Show less',
// Replies
replyCount: '{{count}} reply',
replyCount_one: '{{count}} reply',
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,10 @@ const es = {
foldedMoreFields_other: "{{count}} más",
expandFolded: "Mostrar cada actualización",
collapseFolded: "Ocultar actualizaciones",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "Vacío",
fieldChangeExpand: "Ver todo",
fieldChangeCollapse: "Ver menos",
replyCount: "{{count}} respuesta",
replyCount_one: "{{count}} respuesta",
replyCount_many: "{{count}} de respuestas",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,10 @@ const fr = {
foldedMoreFields_other: "{{count}} autres",
expandFolded: "Afficher chaque mise à jour",
collapseFolded: "Masquer les mises à jour",
fieldChangeLabel: "{{field}} :",
fieldChangeEmpty: "Vide",
fieldChangeExpand: "Tout afficher",
fieldChangeCollapse: "Afficher moins",
replyCount: "{{count}} réponse",
replyCount_one: "{{count}} réponse",
replyCount_many: "{{count}} de réponses",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1588,6 +1588,10 @@ const ja = {
foldedMoreFields_other: "他 {{count}} 件",
expandFolded: "各更新を表示",
collapseFolded: "更新を隠す",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "空",
fieldChangeExpand: "すべて表示",
fieldChangeCollapse: "折りたたむ",
replyCount: "{{count}} 件の返信",
replyCount_one: "{{count}} 件の返信",
replyCount_other: "{{count}} 件の返信",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/ko.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,10 @@ const ko = {
foldedMoreFields_other: "외 {{count}}개",
expandFolded: "각 업데이트 보기",
collapseFolded: "업데이트 숨기기",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "비어 있음",
fieldChangeExpand: "모두 보기",
fieldChangeCollapse: "접기",
replyCount: "답글 {{count}}개",
replyCount_one: "답글 {{count}}개",
replyCount_other: "답글 {{count}}개",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1553,6 +1553,10 @@ const pt = {
foldedMoreFields_other: "mais {{count}}",
expandFolded: "Mostrar cada atualização",
collapseFolded: "Ocultar atualizações",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "Vazio",
fieldChangeExpand: "Ver tudo",
fieldChangeCollapse: "Ver menos",
replyCount: "{{count}} resposta",
replyCount_one: "{{count}} resposta",
replyCount_many: "{{count}} de respostas",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,10 @@ const ru = {
foldedMoreFields_other: "ещё {{count}}",
expandFolded: "Показать каждое обновление",
collapseFolded: "Скрыть обновления",
fieldChangeLabel: "{{field}}:",
fieldChangeEmpty: "Пусто",
fieldChangeExpand: "Показать полностью",
fieldChangeCollapse: "Свернуть",
replyCount: "{{count}} ответ",
replyCount_one: "{{count}} ответ",
replyCount_few: "{{count}} ответа",
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,10 @@ const zh = {
foldedMoreFields_other: '其他 {{count}} 项',
expandFolded: '展开每次更新',
collapseFolded: '收起更新',
fieldChangeLabel: '{{field}}:',
fieldChangeEmpty: '空',
fieldChangeExpand: '展开',
fieldChangeCollapse: '收起',
// Replies
replyCount: '{{count}} 条回复',
replyCount_one: '{{count}} 条回复',
Expand Down
4 changes: 4 additions & 0 deletions ui/packages/i18n/src/locales/zh-Hant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1733,6 +1733,10 @@ const zhHant = {
foldedMoreFields_other: '其他 {{count}} 項',
expandFolded: '展開每次更新',
collapseFolded: '收起更新',
fieldChangeLabel: '{{field}}:',
fieldChangeEmpty: '空',
fieldChangeExpand: '展開',
fieldChangeCollapse: '收起',
// Replies
replyCount: '{{count}} 條回覆',
replyCount_one: '{{count}} 條回覆',
Expand Down
124 changes: 110 additions & 14 deletions ui/packages/plugin-detail/src/FieldChangeItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,135 @@

import * as React from 'react';
import { cn } from '@object-ui/components';
import { ArrowRight } from 'lucide-react';
import type { FieldChangeEntry } from '@object-ui/types';

export interface FieldChangeItemProps {
/** The field change entry to render */
change: FieldChangeEntry;
/**
* The field's label as the reader reads it, drawn as given (a host adds its
* own separator, e.g. `Status:`). Absent: `change.fieldLabel`, else the
* field key made readable.
*/
label?: string;
/**
* Each side's text as the reader reads it; `null` is an empty side, drawn as
* `emptyLabel`. Absent: the side's display value, else its value as text,
* else empty.
*/
oldText?: string | null;
newText?: string | null;
/** What an empty side reads as. */
emptyLabel?: string;
/** The control that shows a long value in full, and the one that clamps it again. */
expandLabel?: string;
collapseLabel?: string;
className?: string;
}

/**
* FieldChangeItem — Renders a single field change entry.
* Shows: field label → old value → new value with human-readable display values.
* Aligned with @objectstack/spec FieldChangeEntrySchema.
* A value longer than this, or one with a line break, offers the expand
* control even where the line has not been laid out (a test DOM, a hidden tab).
*/
export const FIELD_CHANGE_LONG_VALUE_CHARS = 48;

const isLongValue = (text: string | null): boolean =>
text !== null && (text.includes('\n') || text.length > FIELD_CHANGE_LONG_VALUE_CHARS);

const sideOf = (display: string | undefined, value: unknown): string | null =>
display !== undefined && display !== ''
? display
: value === null || value === undefined || value === ''
? null
: String(value);

/**
* FieldChangeItem: one changed field on one line, `Label old → new`, each
* side cut to the line. A side that does not fit, or holds more than one
* line, offers a control that shows both sides in full; an empty side reads
* as `emptyLabel`.
*/
export const FieldChangeItem: React.FC<FieldChangeItemProps> = ({
change,
label,
oldText,
newText,
emptyLabel = '(empty)',
expandLabel = 'Show more',
collapseLabel = 'Show less',
className,
}) => {
const label =
const shownLabel =
label ??
change.fieldLabel ??
change.field.charAt(0).toUpperCase() + change.field.slice(1).replace(/_/g, ' ');
const before = oldText !== undefined ? oldText : sideOf(change.oldDisplayValue, change.oldValue);
const after = newText !== undefined ? newText : sideOf(change.newDisplayValue, change.newValue);

const [expanded, setExpanded] = React.useState(false);
// Whether a side is wider than its line, as laid out; the length rule above
// answers where nothing is laid out.
const [overflows, setOverflows] = React.useState(false);
const oldRef = React.useRef<HTMLSpanElement>(null);
const newRef = React.useRef<HTMLSpanElement>(null);
React.useLayoutEffect(() => {
if (expanded) return undefined;
const measure = () => {
const cut = (el: HTMLSpanElement | null) => !!el && el.scrollWidth > el.clientWidth;
setOverflows(cut(oldRef.current) || cut(newRef.current));
};
measure();
if (typeof ResizeObserver === 'undefined') return undefined;
const observer = new ResizeObserver(measure);
if (oldRef.current) observer.observe(oldRef.current);
if (newRef.current) observer.observe(newRef.current);
return () => observer.disconnect();
}, [before, after, expanded]);
const offersToggle = expanded || overflows || isLongValue(before) || isLongValue(after);

const oldDisplay =
change.oldDisplayValue ?? (change.oldValue != null ? String(change.oldValue) : '(empty)');
const newDisplay =
change.newDisplayValue ?? (change.newValue != null ? String(change.newValue) : '(empty)');
const value = (text: string | null, side: 'old' | 'new', ref: React.RefObject<HTMLSpanElement | null>) => (
<span
ref={ref}
className={cn(
'min-w-0',
expanded ? 'whitespace-pre-wrap break-words' : 'truncate',
text === null ? 'italic text-muted-foreground' : side === 'old' ? 'text-muted-foreground line-through' : 'text-foreground',
)}
data-field-change-side={side}
{...(text === null ? { 'data-field-change-empty': '' } : {})}
>
{text ?? emptyLabel}
</span>
);

return (
<div className={cn('flex items-center gap-1.5 text-sm flex-wrap', className)}>
<span className="font-medium text-foreground">{label}</span>
<span className="text-muted-foreground line-through">{oldDisplay}</span>
<ArrowRight className="h-3 w-3 text-muted-foreground shrink-0" />
<span className="text-foreground">{newDisplay}</span>
<div
className={cn('flex min-w-0 items-baseline gap-1.5 text-sm', expanded && 'flex-wrap', className)}
data-field-change={change.field}
data-field-change-expanded={expanded ? 'true' : 'false'}
>
<span className="shrink-0 font-medium text-foreground" data-field-change-label="">
{shownLabel}
</span>
{/* A space a flex line does not lay out, so the line reads and copies as `Label: old → new`. */}
{' '}
{value(before, 'old', oldRef)}
{/* The arrow is text, so the line reads and copies as `Label: old → new`. */}
<span className="shrink-0 text-muted-foreground" data-field-change-arrow="">
{' → '}
</span>
{value(after, 'new', newRef)}
{offersToggle && (
<button
type="button"
className="shrink-0 text-xs text-primary hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"
aria-expanded={expanded}
onClick={() => setExpanded((open) => !open)}
data-field-change-toggle=""
>
{expanded ? collapseLabel : expandLabel}
</button>
)}
</div>
);
};
Loading
Loading