Skip to content

Commit b3fa702

Browse files
committed
feat(console): the record page reads the served timeline count and asks only the panel's activity rows
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QsR2jSrQVdYaC3GSLbQCFd
1 parent 7363dfb commit b3fa702

8 files changed

Lines changed: 243 additions & 56 deletions

File tree

‎ui/packages/app-shell/src/views/RecordDetailView.tsx‎

Lines changed: 156 additions & 36 deletions
Large diffs are not rendered by default.

‎ui/packages/app-shell/src/views/recordPagePayload.ts‎

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@
3131
* - the discussion and the activity → the page's feed, which takes them
3232
* from the payload (`recordPageComments` / `recordPageActivity`) instead
3333
* of reading `sys_comment`, `sys_comment_reaction` and `sys_activity`
34-
* (objectstack#28470).
34+
* (objectstack#28470);
35+
* - the 动态 stream's count → the page's 动态 count (`recordPageTimeline`),
36+
* so the page asks only the activity rows the 动态 panel draws
37+
* (objectstack#28737).
3538
*
3639
* Each related list names the lookups of its rows to resolve (`expand`), as
3740
* the list's own read does, so the rows carry the names the list draws and no
@@ -70,10 +73,12 @@ import { seedRecordApprovals, type ApprovalRequestLite } from '../hooks/useRecor
7073
const MAX_RELATED = 50;
7174

7275
/**
73-
* How many activity rows the page asks (objectstack#28470): the window the
74-
* record feed always read (`$top: 200`). The 动态 panel draws the newest few,
75-
* but its count and the 动态 tab are the whole merged stream the page holds,
76-
* so the page asks the window the stream is drawn from, not the panel's peek.
76+
* The activity window the record feed reads (`$top: 200`, objectstack#28470):
77+
* what the 动态 tab draws in full, and what a page asks when it opens on a
78+
* face that draws the whole stream. A page that opens on the 动态 panel asks
79+
* only the rows the panel draws, and the stream's count comes with it
80+
* (`timeline`, objectstack#28737); the 动态 tab reads this window when it
81+
* opens.
7782
*/
7883
export const RECORD_PAGE_ACTIVITY_ROWS = 200;
7984

@@ -210,6 +215,8 @@ export function recordPageRequestOf(plan: {
210215
activity?: number;
211216
/** How many attachments, when the page draws them. */
212217
attachments?: number;
218+
/** The sources the page's 动态 stream merges, when it draws the stream's count (objectstack#28737). */
219+
timeline?: { discussion: boolean; activity: boolean; fieldChanges: boolean };
213220
}): RecordPageRequest {
214221
return {
215222
...(plan.expand.length > 0 ? { expand: plan.expand } : {}),
@@ -227,6 +234,7 @@ export function recordPageRequestOf(plan: {
227234
...(plan.discussion ? { discussion: true } : {}),
228235
...(plan.activity !== undefined ? { activity: { top: plan.activity } } : {}),
229236
...(plan.attachments !== undefined ? { attachments: { top: plan.attachments } } : {}),
237+
...(plan.timeline ? { timeline: plan.timeline } : {}),
230238
};
231239
}
232240

@@ -290,21 +298,45 @@ export function recordPageComments(payload: Promise<RecordPagePayload | null>):
290298

291299
/**
292300
* The payload's activity as the record feed's activity read answers it
293-
* (`{ data }`): rejects with that read's refusal.
301+
* (`{ data }`), with how many rows the record holds (`total`), so the feed
302+
* knows whether it holds them all: rejects with that read's refusal.
294303
*/
295-
export function recordPageActivity(payload: Promise<RecordPagePayload | null>): Promise<{ data: Record<string, any>[] }> {
304+
export function recordPageActivity(
305+
payload: Promise<RecordPagePayload | null>,
306+
): Promise<{ data: Record<string, any>[]; total: number }> {
296307
return payload.then((page) => {
297308
const part = page?.activity;
298-
if (!page || !part) return { data: [] };
309+
if (!page || !part) return { data: [], total: 0 };
299310
if (isRefused(part)) {
300311
const thrown = streamRefusal(part.error, 'Activity refused');
301312
if (thrown) throw thrown;
302-
return { data: [] };
313+
return { data: [], total: 0 };
303314
}
304-
return { data: part.records ?? [] };
315+
const data = part.records ?? [];
316+
return { data, total: typeof part.total === 'number' ? part.total : data.length };
305317
});
306318
}
307319

320+
/**
321+
* The 动态 stream's count as the payload answers it (objectstack#28737):
322+
* `total`, and how many of its entries are the comments the payload's
323+
* discussion carried (`comments`) — the comment half the feed holds whole and
324+
* keeps current through its own writes, so the page's count is
325+
* `total - comments + the comments it holds`. `null` when the payload carries
326+
* no count or a read behind it was refused: the feed's own refusal says so.
327+
*/
328+
export function recordPageTimeline(
329+
payload: Promise<RecordPagePayload | null>,
330+
): Promise<{ total: number; comments: number } | null> {
331+
return payload.then((page) => {
332+
const part = page?.timeline;
333+
if (!page || !part || isRefused(part)) return null;
334+
const discussion = page.discussion;
335+
const comments = discussion && !isRefused(discussion) ? (discussion.comments ?? []).length : 0;
336+
return { total: part.total, comments };
337+
}, () => null);
338+
}
339+
308340
/**
309341
* Hand each part of the payload to the reader that asks it. Call it before any
310342
* reader's effect runs (a layout effect of the page), so each reader joins its

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { RelatedCardStack } from './RelatedCardStack';
2323
import { RecordTimelinePanel } from './RecordTimelinePanel';
2424
import { RECORD_TAB_OVERVIEW, RecordTabRow, type RecordTab } from './RecordTabRow';
2525
import { partitionRecordTabsByRecords } from './synth/recordTabRow';
26-
import { RecordTimelineCountContext } from './recordTimelineStream';
26+
import { RECORD_TIMELINE_PANEL_MAX_ENTRIES, RecordTimelineCountContext } from './recordTimelineStream';
2727
import { RecordTimelineCountProbe } from './renderers/record-activity';
2828
import {
2929
relatedCardId,
@@ -405,7 +405,7 @@ export const RecordPageColumns: React.FC<RecordPageColumnsProps> = ({
405405
{hasTimeline && (
406406
<RecordTimelinePanel
407407
nodes={columns.timeline}
408-
entries={wide ? 5 : 3}
408+
entries={wide ? RECORD_TIMELINE_PANEL_MAX_ENTRIES : 3}
409409
onViewAll={onEnlargeRelated ? viewAllTimeline : undefined}
410410
count={streamCount}
411411
onCount={reportTimelineCount}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ export {
212212
recordPageColumnOfTab,
213213
buildDefaultPageColumns,
214214
bodyTableIdsOf,
215+
RECORD_PAGE_TIMELINE_PANEL,
215216
} from './synth/recordPageColumns';
216217
// objectstack#27069 — the one reading of a related-list entry.
217218
export { relatedListEntryNames } from './synth/relatedListEntry';
@@ -236,6 +237,10 @@ export type { RelatedCountTarget, RelatedCountsSource } from './useRelatedCounts
236237
// the record's field changes over through this context.
237238
export {
238239
RecordFieldChangesContext,
240+
// objectstack#28737 — the stream's size as the host counts it, and the
241+
// panel's most entries (the host asks that many activity rows at open).
242+
RecordTimelineTotalContext,
243+
RECORD_TIMELINE_PANEL_MAX_ENTRIES,
239244
auditEntriesToFeedItems,
240245
mergeTimelineStream,
241246
filterTimelineStream,

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

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
*/
2020

2121
import * as React from 'react';
22+
import { RECORD_TIMELINE_UPDATE_ACTIVITY_TYPE } from '@objectstack/spec/api';
2223
import type { FeedItem } from '@object-ui/types';
2324

2425
/**
@@ -46,6 +47,20 @@ export interface RecordTimelinePanel {
4647

4748
export const RecordTimelinePanelContext = React.createContext<RecordTimelinePanel | null>(null);
4849

50+
/** The most entries the 动态 panel shows (its wide face); 3 when narrow. */
51+
export const RECORD_TIMELINE_PANEL_MAX_ENTRIES = 5;
52+
53+
/**
54+
* The whole 动态 stream's size as the host counts it (objectstack#28737): the
55+
* record page payload's `timeline` count, kept current by the host across its
56+
* own comment writes. The host then holds only the newest of the stream's
57+
* activity, so the count its rows would give is not the stream's: the panel's
58+
* count chip, its 「查看全部 N 条」, the 动态 tab's count and the tab row's
59+
* probe all name this one instead. `null` (no host count, or not yet
60+
* answered): each counts the stream it holds, as before.
61+
*/
62+
export const RecordTimelineTotalContext = React.createContext<number | null>(null);
63+
4964
/**
5065
* Where the 动态 stream drawn in full — the 动态 tab — reports how many
5166
* entries it holds, for the tab's count chip on the record page's tab row
@@ -120,7 +135,7 @@ export function mergeTimelineStream(
120135
): FeedItem[] {
121136
const changes = fieldChanges ?? [];
122137
const base = (feed ?? []).filter(
123-
(item) => !(changes.length > 0 && (item as { activityType?: string }).activityType === 'updated'),
138+
(item) => !(changes.length > 0 && (item as { activityType?: string }).activityType === RECORD_TIMELINE_UPDATE_ACTIVITY_TYPE),
124139
);
125140
return [...base, ...changes]
126141
.map((item, index) => ({ item, index }))

‎ui/packages/plugin-detail/src/renderers/record-activity.tsx‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ import {
8383
RecordFieldChangesContext,
8484
RecordTimelineCountContext,
8585
RecordTimelinePanelContext,
86+
RecordTimelineTotalContext,
8687
filterTimelineStream,
8788
mergeTimelineStream,
8889
type TimelineStreamFilter,
@@ -338,10 +339,14 @@ export const RecordActivityRenderer: React.FC<RecordActivityRendererProps> = ({
338339
// row: the whole stream's size, unknown while the feed loads or a read was
339340
// refused (a refused read is not "none"). The tab's full face reports it
340341
// while its 全部 chip is on; another chip's total is not the stream's.
342+
// objectstack#28737 — the whole stream's size is the host's count where it
343+
// has one (it holds only the newest activity then), else the rows' own.
341344
const countReporter = React.useContext(RecordTimelineCountContext);
345+
const hostTotal = React.useContext(RecordTimelineTotalContext);
346+
const wholeTotal = asStream && hostTotal !== null ? hostTotal : applied.total;
342347
const reportCount = asPeek ? timelinePanel?.onCount : asStream ? (countReporter ?? undefined) : undefined;
343348
const reportsWhole = asPeek || streamFilter === 'all';
344-
const streamCount = !loading && !activityDenied && !commentsDenied ? applied.total : null;
349+
const streamCount = !loading && !activityDenied && !commentsDenied ? wholeTotal : null;
345350
React.useEffect(() => {
346351
if (reportsWhole) reportCount?.(streamCount);
347352
}, [reportCount, reportsWhole, streamCount]);
@@ -377,7 +382,7 @@ export const RecordActivityRenderer: React.FC<RecordActivityRendererProps> = ({
377382
{...(asPeek
378383
? {
379384
variant: 'peek' as const,
380-
totalCount: applied.total,
385+
totalCount: wholeTotal,
381386
onViewAll: timelinePanel?.onViewAll,
382387
}
383388
: asStream
@@ -433,6 +438,7 @@ export function RecordTimelineCountProbe({
433438
const node = firstActivityNode(nodes);
434439
const discussion = useDiscussionContext();
435440
const fieldChanges = React.useContext(RecordFieldChangesContext);
441+
const hostTotal = React.useContext(RecordTimelineTotalContext);
436442
const bag = (node?.properties ?? {}) as Record<string, any>;
437443
const read = (key: string) => node?.[key] ?? bag[key];
438444
const hostItems = Array.isArray(read('items')) ? (read('items') as FeedItem[]) : undefined;
@@ -444,9 +450,11 @@ export function RecordTimelineCountProbe({
444450
const unifiedTimeline = read('unifiedTimeline');
445451
const count = React.useMemo(() => {
446452
if (!node || !sourceItems || loading || denied) return null;
453+
// objectstack#28737 — the host's count of the whole stream, where it has one.
454+
if (hostTotal !== null) return hostTotal;
447455
const stream = mergeTimelineStream(sourceItems, fieldChanges);
448456
return applyFeedConfig(stream, { types, showCompleted, unifiedTimeline }, Number.MAX_SAFE_INTEGER, BLOCK_NAME).items.length;
449-
}, [node, sourceItems, loading, denied, fieldChanges, types, showCompleted, unifiedTimeline]);
457+
}, [node, sourceItems, loading, denied, hostTotal, fieldChanges, types, showCompleted, unifiedTimeline]);
450458
React.useEffect(() => {
451459
onCount(count);
452460
}, [onCount, count]);

‎ui/packages/plugin-detail/src/renderers/recordActivityFeed.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
*/
3636

3737
import { FeedFilterMode as FeedFilterModeEnum, FeedItemType as FeedItemTypeEnum } from '@objectstack/spec/data';
38+
import { RECORD_TIMELINE_UNDRAWN_ACTIVITY_TYPES } from '@objectstack/spec/api';
3839
import { classifyLoadError } from '@object-ui/react';
3940
import type { FeedItem, FeedItemType } from '@object-ui/types';
4041
import type { FeedFilterMode } from '../RecordActivityTimeline';
@@ -144,10 +145,10 @@ export const ACTIVITY_TYPE_TO_FEED_TYPE: Readonly<Record<string, FeedItemType |
144145
system: 'system',
145146
completed: 'task',
146147
scheduled: 'event',
147-
commented: undefined,
148-
mentioned: undefined,
149-
login: undefined,
150-
logout: undefined,
148+
// objectstack#28737 — the types the stream draws no entry for are ONE
149+
// definition with the record page payload's `timeline` count, which leaves
150+
// the same ones out: `commented`, `mentioned`, `login`, `logout`.
151+
...Object.fromEntries(RECORD_TIMELINE_UNDRAWN_ACTIVITY_TYPES.map((type) => [type, undefined])),
151152
};
152153

153154
/**

‎ui/packages/types/src/data.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,12 @@ export interface RecordPagePayload {
422422
activity?: { total: number; records: Record<string, any>[] } | { error: RecordPagePartRefusal };
423423
/** The record's newest attachments and their count, or their read's refusal (objectstack#28470). */
424424
attachments?: { total: number; records: Record<string, any>[] } | { error: RecordPagePartRefusal };
425+
/**
426+
* How many entries the record's 动态 stream holds over the sources the
427+
* request named (objectstack#28737), or the refusal of a comment or
428+
* activity read.
429+
*/
430+
timeline?: { total: number } | { error: RecordPagePartRefusal };
425431
}
426432

427433
/**

0 commit comments

Comments
 (0)