Skip to content

Commit 9972432

Browse files
fix(plugin-detail): the Changes chip no longer folds the record's creation into its edits (#35957)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuDYM244ZZo7uXksNPNmuEyz)_ Fixes #35788 Clause-②: no Metadata-protocol: none repo:objectstack#1 · os-sales · session_01L6bhgWdb2isyvQFrgHazQx ## 维护者速读 - 用户能看到什么变化:在开了字段历史的记录页「动态」里,点「变更」时,同一个人同一天的几次修改折叠成一行,次数现在只算真正的修改,记录的创建单独显示一次,不再被算成又一次修改。 - 为什么做:记录页改版里「动态」折叠功能带来的计数错误,替审批人、审计和负责人看准一条记录被改过几次。 - 出错会怎样:最坏是「变更」里创建那一行显示位置不对,数据本身不受影响,改动可直接撤回。 - 要你做什么:无。 ## What changes - `recordTimelineStream.ts`: new `isRecordCreationEntry(item)` — a field-history entry written by the ledger's `create` action (the action the spec's `RECORD_TIMELINE_FOLDED_ACTIVITY_TYPES` pairs with the `created` activity row). The `auditEntriesToFeedItems` doc now says what the code does: the creation's audit entry pairs onto the `created` row, and where it stands alone it is one row of its own, never one more edit. - `RecordActivityTimeline.tsx`: `isStreamFieldChange` (what `foldStreamChanges` folds) excludes that entry. This is the one place All and Changes share, so the fix lands on both: Changes now folds the three edits and shows the creation once, as its own row; All is unchanged (its creation was already the paired `Created` row). - `ui/e2e/live/record-history-display.spec.ts`: tightened back to the exact count — the fold holds exactly 3 rows, `data-fold-count` is `3`, no creation line inside the fold, and the creation appears at most once in the stream. - Changeset: `@object-ui/plugin-detail` patch. Mechanism, measured: the PM hypothesis holds. On the Changes chip, `fieldHistoryEntriesOf` unwraps the audit entry paired onto the `created` activity row, so the creation's entry (changes from empty values) reaches `foldStreamChanges` as a bare `sys_audit_log` field change and joins the same-actor, same-day run. ## Tests Pins added as a top-level `describe` in the existing fold harness `src/__tests__/denseActivityRows-35602.test.tsx` (same actor, same day, create + 3 updates, activity rows and audit entries paired through `mergeTimelineStream`): - Changes: `foldStreamChanges(filterTimelineStream(stream, 'changes'))` is `fold:3, item:audit:c0`. - All: `fold:3, item:a0` (the `Created` row) — control, unchanged. - Rendered Changes chip: one fold, `data-fold-count` 3, the creation's line outside it, exactly once. Readings are in the details blocks under Verification. ## Acceptance notes - The standalone creation row on the Changes chip is drawn the way any unpaired audit entry is (its field values from empty). Only the fold count and placement were in scope; how that row is worded is not changed here. - `ui/e2e/live/record-history-display.spec.ts` was not run live (NOT MEASURED: live e2e, reason: needs a booted showcase stack plus console; the `Live E2E UI` CI job runs it). ## Verification Read first (by risk): 1. `ui/packages/plugin-detail/src/RecordActivityTimeline.tsx` — the `isStreamFieldChange` hunk. 2. `ui/packages/plugin-detail/src/recordTimelineStream.ts` — `isRecordCreationEntry`. 3. `ui/e2e/live/record-history-display.spec.ts` — the tightened count. Two-minute check: `cd ui && pnpm exec vitest run packages/plugin-detail/src/__tests__/denseActivityRows-35602.test.tsx` — expect 9 passed, including the three `objectstack#35788` cases. <details><summary>Unit tests (head 5d9f8e5)</summary> - `cd ui && pnpm exec vitest run packages/plugin-detail/src/__tests__/denseActivityRows-35602.test.tsx packages/plugin-detail/src/__tests__/recordTimelineStream-27055.test.tsx` under `os-verify-lock`: Test Files 2 passed (2), Tests 61 passed (61), VERDICT command-exit 0. - Whole package at 7bb40c1 (pre-merge; the merge of main brought no change to these files): `pnpm --filter @object-ui/plugin-detail run type-check` (tsc --noEmit and tsc -p tsconfig.test.json) exit 0; package vitest: Test Files 393 passed, 1 skipped (394); Tests 3602 passed, 18 skipped; VERDICT command-exit 0. </details> <details><summary>Ablation (one-shot, not kept)</summary> `node scripts/ablation-replace.mjs` on `RecordActivityTimeline.tsx`, anchor `(isFieldHistoryEntry(item) && !isRecordCreationEntry(item))` replaced by `(isFieldHistoryEntry(item) /* ABLATED-35788 */)`: anchor 1 to 0, blob 7ff0617 to 55e3deed89df. Result: 2 failed, 7 passed: the Changes case (`fold:4` instead of `fold:3, item:audit:c0`) and the rendered fold count (`4` instead of `3`); the All control stays green, as expected (All pairs the creation onto its Created row). Restored: blob equals HEAD 7ff0617, `git diff HEAD` empty. The test imports the subject by relative path (src), so no dist leg. A first attempt was a no-op (replacement text was a substring of the anchor; the tool refused it) and is not counted. </details> <details><summary>Gates (head 5d9f8e5)</summary> `node scripts/pm/dispatch-gates.mjs --commands` derived 38 commands; all 38 run locally, every one exit 0 (exit captured before any pipe). `--ran`: 38 derived families accounted for, 38 run, 0 NOT-MEASURED (a derived zero). `pnpm --dir ui exec vitest run scripts/`: Test Files 172 passed, 2 skipped; Tests 5111 passed. `check:nul-bytes` exit 0. </details> --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgWdb2isyvQFrgHazQx)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgWdb2isyvQFrgHazQx <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgWdb2isyvQFrgHazQx --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 7de1bad commit 9972432

5 files changed

Lines changed: 99 additions & 10 deletions

File tree

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(record-page): the 动态 tab's Changes chip no longer counts the record's creation as one more edit
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
On a record of a history-tracked object that one person created and then edited on the same day, the Changes (变更) chip folded the creation's own audit entry into the run of edits: the fold said "4 updates" for three edits, and its first "edit" was the creation drawn as field changes from empty values. The All view of the same stream was right (the edits plus one Created row).
11+
12+
Now the creation's audit entry never joins a fold of field changes, under All and Changes alike: the Changes chip folds the edits alone and shows the creation once, as its own row. No props, locale keys or entry exports change; `isRecordCreationEntry` is added to the `recordTimelineStream` module (not re-exported from the package entry).

‎ui/e2e/live/record-history-display.spec.ts‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,18 @@ test('the timeline stream\'s Changes chip shows display values (localized dates,
100100
const foldEntries = fold.getByTestId('activity-fold-entries');
101101
// The three UPDATE entries render as change lines; wait for the latest one.
102102
await expect(foldEntries.locator('[data-stream-change]', { hasText: 'Owner' }).first()).toBeVisible({ timeout: 15_000 });
103-
// The fold counts the rows it expands to, and holds all three updates. (The
104-
// Changes chip also draws the creation's own audit entry as a change line,
105-
// which folds in beside them when it is stamped the same day, so the count
106-
// is not pinned to exactly three.)
103+
// The fold holds exactly the three updates. The creation's own audit entry
104+
// is the record's creation, not one more edit: it never folds in beside
105+
// them, even stamped the same day by the same person (objectstack#35788).
107106
const foldRow = foldEntries.locator('[data-stream-row]');
107+
await expect(foldRow, 'the fold holds the three updates and nothing else').toHaveCount(3);
108+
await expect(fold).toHaveAttribute('data-fold-count', '3');
108109
await expect(foldRow.filter({ hasText: 'Customer Since', hasNotText: 'Lifecycle' }), 'the date update').toHaveCount(1);
109110
await expect(foldRow.filter({ hasText: 'Finance' }), 'the lifecycle and industry update').toHaveCount(1);
110111
await expect(foldRow.filter({ hasText: other.name }), 'the owner update').toHaveCount(1);
111-
await expect(fold).toHaveAttribute('data-fold-count', String(await foldRow.count()));
112+
// The creation is said at most once, and never inside the fold.
113+
await expect(foldRow.filter({ hasText: name }), 'no creation line in the fold').toHaveCount(0);
114+
expect(await stream.locator('[data-stream-row]', { hasText: name }).count(), 'the creation at most once').toBeLessThanOrEqual(1);
112115
const text = (await stream.innerText()).replace(/\s+/g, ' ');
113116
// What the change lines say, without the fold row's summary (which names
114117
// fields, not values): every positive read below is of a real line, and

‎ui/packages/plugin-detail/src/RecordActivityTimeline.tsx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import {
5252
fieldHistoryEntriesOf,
5353
fieldHistoryOf,
5454
isFieldHistoryEntry,
55+
isRecordCreationEntry,
5556
filterTimelineStream,
5657
isSystemStreamEntry,
5758
timelineStreamFilters,
@@ -232,12 +233,14 @@ const FEED_TYPE_ICONS: Record<FeedItemType, React.ElementType> = {
232233
/**
233234
* Whether a stream entry is one person's field change, the kind
234235
* {@link foldStreamChanges} folds: an audit entry or an `updated` activity
235-
* row, not a milestone (`activityKind`) and not a reply.
236+
* row, not a milestone (`activityKind`) and not a reply. The audit entry of
237+
* the record's creation is not an edit: it stands as its own row, so a fold
238+
* counts the edits alone, under 全部 and 变更 alike (objectstack#35788).
236239
*/
237240
function isStreamFieldChange(item: FeedItem): boolean {
238241
return (
239242
item.type === 'field_change'
240-
&& (isFieldHistoryEntry(item) || item.activityType === 'updated')
243+
&& ((isFieldHistoryEntry(item) && !isRecordCreationEntry(item)) || item.activityType === 'updated')
241244
&& item.activityKind === undefined
242245
&& !item.parentId
243246
);

‎ui/packages/plugin-detail/src/__tests__/denseActivityRows-35602.test.tsx‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ import { describe, it, expect, afterEach, vi } from 'vitest';
2020
import { render, cleanup, fireEvent, screen } from '@testing-library/react';
2121
import type { FeedItem } from '@object-ui/types';
2222
import { RecordActivityTimeline, foldStreamChanges } from '../RecordActivityTimeline';
23-
import { mergeTimelineStream } from '../recordTimelineStream';
23+
import {
24+
auditEntriesToFeedItems,
25+
filterTimelineStream,
26+
mergeTimelineStream,
27+
type AuditEntryLike,
28+
} from '../recordTimelineStream';
2429

2530
afterEach(cleanup);
2631

@@ -138,3 +143,52 @@ describe('dense activity rows (objectstack#35602)', () => {
138143
expect(screen.getAllByRole('textbox').length).toBeGreaterThan(0);
139144
});
140145
});
146+
147+
describe('the record\'s creation in a fold of field changes (objectstack#35788)', () => {
148+
// One person creates a record and edits it three times on the same day: the
149+
// ledger writes four audit entries (the creation's carries the values the
150+
// record was created with) and the activity stream four rows.
151+
const audit: AuditEntryLike[] = [
152+
{ id: 'u3', action: 'update', user_id: 'u1', user_name: 'Ada Lovelace', created_at: today(4), changes: [{ field: 'owner_id', label: 'Owner', from: 'Ada Lovelace', to: 'Grace Hopper' }] },
153+
{ id: 'u2', action: 'update', user_id: 'u1', user_name: 'Ada Lovelace', created_at: today(3), changes: [{ field: 'status', label: 'Lifecycle', from: 'Prospect', to: 'Active' }] },
154+
{ id: 'u1', action: 'update', user_id: 'u1', user_name: 'Ada Lovelace', created_at: today(2), changes: [{ field: 'signed_on', label: 'Customer Since', from: '2026-07-26', to: '2026-08-04' }] },
155+
{ id: 'c0', action: 'create', user_id: 'u1', user_name: 'Ada Lovelace', created_at: today(1), changes: [{ field: 'name', label: 'Account Name', from: null, to: 'Acme' }] },
156+
];
157+
const activity = (id: string, activityType: 'created' | 'updated', createdAt: string): FeedItem =>
158+
({ ...edit(id, 'u1', createdAt), activityType, body: activityType === 'created' ? 'Created Account' : 'updated' }) as FeedItem;
159+
const stream = () =>
160+
mergeTimelineStream(
161+
[
162+
activity('a3', 'updated', today(4)),
163+
activity('a2', 'updated', today(3)),
164+
activity('a1', 'updated', today(2)),
165+
activity('a0', 'created', today(1)),
166+
],
167+
auditEntriesToFeedItems(audit, { unknownUser: 'Unknown user' }),
168+
);
169+
const shape = (entries: ReturnType<typeof foldStreamChanges>) =>
170+
entries.map((e) => (e.kind === 'fold' ? `fold:${e.items.length}` : `item:${String(e.item.id)}`));
171+
172+
it('the 变更 chip folds the three edits and shows the creation once, on its own', () => {
173+
expect(shape(foldStreamChanges(filterTimelineStream(stream(), 'changes')))).toEqual(['fold:3', 'item:audit:c0']);
174+
});
175+
176+
it('全部 folds the same three edits beside its one 「Created」 row', () => {
177+
expect(shape(foldStreamChanges(filterTimelineStream(stream(), 'all')))).toEqual(['fold:3', 'item:a0']);
178+
});
179+
180+
it('draws the 变更 chip\'s fold with a count of three, the creation outside it', () => {
181+
const { container } = render(
182+
<RecordActivityTimeline items={stream()} variant="stream" titleLabel="Timeline" streamFilter="changes" />,
183+
);
184+
expect(container.querySelector('[data-stream-filter="changes"]')?.getAttribute('aria-pressed')).toBe('true');
185+
const folds = container.querySelectorAll('[data-testid="activity-fold"]');
186+
expect(folds.length).toBe(1);
187+
expect(folds[0].getAttribute('data-fold-count')).toBe('3');
188+
expect(folds[0].textContent).not.toContain('Account Name');
189+
const creation = Array.from(container.querySelectorAll('[data-stream-row]')).filter((row) =>
190+
row.textContent?.includes('Account Name'),
191+
);
192+
expect(creation.length).toBe(1);
193+
});
194+
});

‎ui/packages/plugin-detail/src/recordTimelineStream.ts‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,11 @@ const displayOf = (value: unknown): string | undefined =>
112112

113113
/**
114114
* Audit entries as `field_change` feed items. Only an entry that changed a
115-
* field becomes one: the record's creation is the activity stream's own
116-
* `created` row, so it is not said twice.
115+
* field becomes one. The record's creation is the activity stream's own
116+
* `created` row, so it is not said twice: its audit entry (the values the
117+
* record was created with) pairs onto that row ({@link mergeTimelineStream}),
118+
* and where it stands alone (the 变更 chip, or no activity row to pair with)
119+
* it is one row of its own, never one more edit ({@link isRecordCreationEntry}).
117120
*/
118121
export function auditEntriesToFeedItems(
119122
entries: readonly AuditEntryLike[] | null | undefined,
@@ -321,6 +324,20 @@ export function isFieldHistoryEntry(item: FeedItem): boolean {
321324
return item.type === 'field_change' && item.source === 'sys_audit_log';
322325
}
323326

327+
/**
328+
* Whether an item is the audit entry of the record's creation: a
329+
* field-history entry written by the ledger's `create` action, the one the
330+
* spec pairs with the `created` activity row. It is the record's creation,
331+
* said once: never one more edit folded into a run of field changes
332+
* (objectstack#35788).
333+
*/
334+
export function isRecordCreationEntry(item: FeedItem): boolean {
335+
return (
336+
isFieldHistoryEntry(item)
337+
&& foldedActivityTypeOf((item as FeedItem & AuditFeedFacts).auditAction) === RECORD_TIMELINE_FOLDED_ACTIVITY_TYPES.create
338+
);
339+
}
340+
324341
/**
325342
* The field-history entries of a stream, each on its own: an unpaired audit
326343
* entry as it is, and the audit entry an activity row carries

0 commit comments

Comments
 (0)