Skip to content

Commit 046c224

Browse files
fix(plugin-detail): a record:activity whose types leaves out comment offers no comment composer (#34388)
<!-- claude-projects-attribution: {"github_login":"os-steve"} --> _Requested by **Steve** · [project thread](https://claude.ai/code/project/chan_01FdL1XeUyvVNxLreh3F4Qi9?thread=cmsg_01FdL1XeUyvVNxLreh3F4Qi9M74fmRwo3N4LF8cXvJSwDE)_ Fixes #34371 Clause-②: no Metadata-protocol: none ## 维护者速读 - **改了什么**:活动块(`record:activity`)的 `types` 不含 `comment` 时,不再显示评论输入框和「仅评论」筛选项;开发环境下对每个块提示一次原因和两种改法。 - **为什么改**:HotCRM 线索页的活动块写了 `types: ['task']`,评论被这个白名单过滤掉,但输入框照常显示,用户发的评论保存了却永远看不到。 - **风险与回滚**:只影响 `types` 写了且不含 `comment` 的活动块;没写 `types` 或含 `comment` 的块完全不变。回滚即 revert 本 PR。 - **先看**:`ui/packages/plugin-detail/src/renderers/record-activity.tsx`(新增 `commentsShown` 判定与告警);`ui/packages/plugin-detail/src/RecordActivityTimeline.tsx`(新 prop 收掉输入框与「仅评论」);`ui/packages/plugin-detail/src/renderers/recordActivityFeed.ts`(判定与告警文案)。 - **两分钟验证**:`pnpm --dir ui exec vitest run packages/plugin-detail/src/renderers/__tests__/record-activity.test.tsx`,预期 27 个全过,其中 5 个是本卡新增。 - **需要你做的**:无,席位落地。 ## What changes **Measured drop point.** The comments are not lost by the host. Reproduced through `RecordDetailView` rendering an authored record page (real `page:tabs` opened on its Activity tab, real `record:activity`) with HotCRM `lead_detail`'s `lead_activity` properties verbatim (`types: ['task']`, `limit: 20`, `showCompleted: true`, objectstack-ai/hotcrm main `07d5d9f`). The host reads `sys_comment` and `sys_activity` and builds the comment items with `type: 'comment'`; the block then runs them through `applyFeedConfig` (`recordActivityFeed.ts`), whose `types` allow-list step (`kept = kept.filter((i) => allowed.has(i.type))`) drops every `comment`, because `'comment'` is not in `['task']`. That is what the spec declares (`RecordActivityProps.types`: "Feed item kinds to show (default: all)"). The defect is that the same block still offered the composer (`showCommentInput` defaults to `true`) and the Comments only option, so a posted comment was stored and then filtered out of view. **Ruling.** Seat ruling 6915056720 on the dev report 6915007777 picked option C for this card: refusing the contradiction at authoring is spec-lane card #34383, and the producer fix (`'comment'` added to `lead_activity`'s `types`) is carried to hotcrm. Option B (making `types` skip comments) was declined. **This PR (option C, `Metadata-protocol: none`).** - `recordActivityFeed.ts`: `feedTypesAdmitComments(types, block)` answers whether the authored `types` can show a comment, through the same `normalizeFeedTypes` reading `applyFeedConfig` filters by, so the answer and the rows cannot disagree. `warnWithheldCommentComposer` names the block (and its node `id`), its `types` and both fixes, once per block and `types` (the `warnOnce` channel the file's other diagnostics use). - `record-activity.tsx`: computes `commentsShown` and hands it to the timeline; where the composer would otherwise have been offered (`showCommentInput` not `false`), it warns from an effect, in development only (the package's `isDevBuild` spelling). - `RecordActivityTimeline.tsx`: one optional prop, `commentsShown` (default `true`). `false` withholds the composer and the `comments_only` filter option; an authored `filterMode: 'comments_only'` then reads as `all` under the existing "a filter the dropdown does not offer filters nothing" rule. `RecordChatterPanel` passes nothing and is unchanged. A block with no `types`, or a `types` that includes `'comment'`, renders exactly as before. ## Tests New top-level `describe` in the block's existing harness, `renderers/__tests__/record-activity.test.tsx` (real renderer, real timeline, a host `DiscussionContext` with an `onAddComment`): - the HotCRM shape (`types: ['task']`) draws no composer and no Comments Only option (and the comment is not shown); - CONTROL `types: ['task', 'comment']`: the composer and the option stay, the comment shows, no warning; - CONTROL no `types`: the same; - the warning fires once across a re-render and a remount, naming the block, its `types` and both fixes; - a block with `showCommentInput: false` is told nothing. No forced test edits: no existing test changed. <details><summary>Pin run and ablations (fix commit 76ea4fd)</summary> - `pnpm --dir ui exec vitest run packages/plugin-detail/src/renderers/__tests__/record-activity.test.tsx`: Tests 27 passed (27). - Ablation 1, `record-activity.tsx`, `commentsShown` forced `true` through `scripts/ablation-replace.mjs` (anchor 1 to 0, blob moved): Tests 2 failed, 25 passed; the HotCRM-shape pin and the warn-once pin went red; restored, blob equal to HEAD, `git diff HEAD` empty. - Ablation 2, `RecordActivityTimeline.tsx`, the `comments_only` option gate forced open: Tests 1 failed, 26 passed ("expected [ 'All Activity', …(3) ] to not include 'Comments Only'"); restored, blob equal to HEAD. - The pins import the block from `src` (relative imports), so no `dist` rebuild sits between a mutation and the run. </details> ## Acceptance notes - HotCRM `lead_detail` keeps hiding its comments until the producer adds `'comment'` to `types` (carried to hotcrm by the seat ruling); this PR removes the composer that posted into the void. The same page's comment saying `scheduled` rows are dropped is stale (they map to `event` now), and `types: ['task']` hides those too. - The probe that measured the drop point through `RecordDetailView` was a one-off and is not committed. ## Verification All local runs on the final head `879d3661` unless named. - `pnpm --filter @object-ui/plugin-detail type-check` (`tsc --noEmit && tsc -p tsconfig.test.json`): lock VERDICT command-exit 0. - `pnpm --dir ui exec vitest run --maxWorkers=2 packages/plugin-detail/`: Test Files 379 passed, 1 skipped (380); Tests 3402 passed, 18 skipped (3420); lock VERDICT command-exit 0. - `node scripts/pm/dispatch-gates.mjs --commands --repo objectstack-ai/objectstack`: 38 commands derived, each run, each `exit 0`; `--ran` reconciliation: "38 derived famil(ies) accounted for — 38 run, 0 NOT-MEASURED". The record is in the project files as `ui-seat2/34371-gates-ran.txt`. - CI-only families (Type Check UI, Test UI shards, Build & E2E UI and the rest): read from this PR's check-runs. --- _Generated by [Claude Code](https://claude.ai/code/session_01ADHkmQL9UYenrqC6NTLq3h)_ --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: objectstack-fleet[bot] <332303061+objectstack-fleet[bot]@users.noreply.github.com>
1 parent 0e2e4f5 commit 046c224

5 files changed

Lines changed: 198 additions & 6 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
'@object-ui/plugin-detail': patch
3+
---
4+
5+
fix(plugin-detail): a `record:activity` whose `types` leaves out `comment` no longer offers a comment composer whose posts it then hides
6+
7+
Clause-②: no
8+
Metadata-protocol: none
9+
10+
`types` is the list of feed item kinds the block shows, and `comment` is one of them. A block authored with a list that leaves it out, such as `types: ['task']`, filters every comment out of its feed, including a comment posted on that same block. It still drew the "Leave a comment" composer and the "Comments only" filter, so a member's comment was saved and then never appeared.
11+
12+
Such a block now draws no composer and no "Comments only" option. In development it logs one warning per block that names the block, its `types` and the two fixes:
13+
14+
- to take comments on the block, add `'comment'` to `types`;
15+
- to keep the block activity-only, set `showCommentInput: false`.
16+
17+
A block with no `types`, or with a `types` that includes `'comment'`, is unchanged.

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ export interface RecordActivityTimelineProps {
9797
* the failure is the host's job.
9898
*/
9999
onAddComment?: (text: string, attachments?: Attachment[]) => void | Promise<void>;
100+
/**
101+
* Whether the feed this timeline draws can show a comment at all
102+
* (objectstack#34371). `false` — a `types` allow-list that leaves out
103+
* `comment` — withdraws the comment composer and the Comments-only filter, so
104+
* the timeline never offers a post it would then filter out of view. Absent
105+
* means `true`.
106+
*/
107+
commentsShown?: boolean;
100108
/** Called when a reply is submitted — a rejection keeps the reply draft, as above. */
101109
onAddReply?: (parentId: string | number, text: string) => void | Promise<void>;
102110
/** Called when user toggles a reaction */
@@ -225,16 +233,19 @@ const FEED_TYPE_COLORS: Record<FeedItemType, string> = {
225233
* The dropdown's options, given whether the record's field history is shown
226234
* (`RecordFieldHistoryContext`): `changes_only` is offered exactly when the
227235
* stream offers its 变更 chip — the one rule, `timelineStreamFilters`
228-
* (objectstack#30074, objectstack#30344).
236+
* (objectstack#30074, objectstack#30344). `comments_only` is offered exactly
237+
* when the feed can show a comment (`commentsShown`, objectstack#34371).
229238
*/
230239
function getFilterOptions(
231240
t: (key: string) => string,
232241
fieldHistory: boolean,
242+
commentsShown: boolean,
233243
): { value: FeedFilterMode; label: string }[] {
234244
const changesOffered = timelineStreamFilters(fieldHistory).includes('changes');
235245
return [
236246
{ value: 'all', label: t('detail.allActivity') },
237-
{ value: 'comments_only', label: t('detail.commentsOnly') },
247+
// A feed that cannot show a comment offers no filter for them (objectstack#34371).
248+
...(commentsShown ? [{ value: 'comments_only' as const, label: t('detail.commentsOnly') }] : []),
238249
...(changesOffered ? [{ value: 'changes_only' as const, label: t('detail.fieldChangesFilter') }] : []),
239250
{ value: 'tasks_only', label: t('detail.tasksOnly') },
240251
];
@@ -343,6 +354,7 @@ export const RecordActivityTimeline: React.FC<RecordActivityTimelineProps> = ({
343354
onLoadMore,
344355
loading = false,
345356
onAddComment,
357+
commentsShown = true,
346358
onAddReply,
347359
onToggleReaction,
348360
onEditComment,
@@ -478,11 +490,11 @@ export const RecordActivityTimeline: React.FC<RecordActivityTimelineProps> = ({
478490

479491
// A filter the dropdown does not offer filters nothing: it reads as `all`,
480492
// as the stream's chips do.
481-
const filterOptions = getFilterOptions(t, React.useContext(RecordFieldHistoryContext));
493+
const filterOptions = getFilterOptions(t, React.useContext(RecordFieldHistoryContext), commentsShown);
482494
const chosenFilter = controlledFilter ?? internalFilter;
483495
const activeFilter: FeedFilterMode = filterOptions.some((opt) => opt.value === chosenFilter) ? chosenFilter : 'all';
484496
const showFilter = config?.showFilterToggle !== false;
485-
const showCommentInput = config?.showCommentInput !== false && !!onAddComment;
497+
const showCommentInput = config?.showCommentInput !== false && !!onAddComment && commentsShown;
486498
const enableReactions = config?.enableReactions ?? false;
487499
const enableThreading = config?.enableThreading ?? false;
488500
const showSubscription = config?.showSubscriptionToggle ?? false;

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

Lines changed: 99 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@
3333
*/
3434

3535
import * as React from 'react';
36-
import { describe, it, expect, vi, beforeEach } from 'vitest';
36+
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
3737
import { render, screen, waitFor, cleanup, fireEvent } from '@testing-library/react';
3838
import { RecordContextProvider, DiscussionContextProvider } from '@object-ui/react';
3939
import type { FeedItem } from '@object-ui/types';
4040
import { RecordActivityRenderer } from '../record-activity';
41+
import { resetWithheldCommentComposerWarnings } from '../recordActivityFeed';
4142

4243
const COMPOSER_PLACEHOLDER = 'Leave a comment… (Ctrl+Enter to submit)';
4344
const EMPTY_FEED = 'No activity recorded';
@@ -329,3 +330,100 @@ describe('record:activity — showSubscriptionToggle is the one documented gap',
329330
expect(screen.queryByLabelText('Unsubscribe from notifications')).toBeNull();
330331
});
331332
});
333+
334+
/**
335+
* objectstack#34371 — a `types` allow-list that leaves out `comment` filters
336+
* every comment out of the block, the ones posted on it included, so the block
337+
* offers no composer and no Comments-only filter, and says why once in
338+
* development. HotCRM's `lead_detail` page authors exactly that shape
339+
* (`types: ['task']`, `showCompleted: true`); the controls are the same block
340+
* with `comment` admitted, and with no `types` at all.
341+
*/
342+
describe('record:activity — a types list without comment offers no comment composer (objectstack#34371)', () => {
343+
const FILTER_TRIGGER = 'Filter activity';
344+
const COMMENTS_ONLY = 'Comments Only';
345+
const FEED: FeedItem[] = [
346+
{ id: 'c1', type: 'comment', actor: 'Ada', body: 'a posted comment', createdAt: '2026-11-16T09:47:37.000Z' },
347+
{ id: 't1', type: 'task', actor: 'Ada', body: 'Meeting held', createdAt: '2026-11-16T09:30:00.000Z' },
348+
];
349+
const HOTCRM_LEAD_ACTIVITY = { types: ['task'], limit: 20, showCompleted: true };
350+
const withHost = (node: React.ReactNode) => (
351+
<DiscussionContextProvider items={FEED as any} onAddComment={vi.fn()}>
352+
{node}
353+
</DiscussionContextProvider>
354+
);
355+
const mountBlock = (properties: Record<string, unknown>) =>
356+
mountBound({ type: 'record:activity', id: 'lead_activity', properties }, makeDataSource(), withHost);
357+
358+
/** The dropdown's option labels, read by opening the Radix Select. */
359+
async function filterOptionLabels(): Promise<string[]> {
360+
fireEvent.keyDown(screen.getByRole('combobox', { name: FILTER_TRIGGER }), { key: 'ArrowDown' });
361+
await waitFor(() => expect(screen.queryAllByRole('option').length).toBeGreaterThan(0));
362+
return screen.getAllByRole('option').map((o) => o.textContent ?? '');
363+
}
364+
365+
let warn: ReturnType<typeof vi.spyOn>;
366+
beforeEach(() => {
367+
resetWithheldCommentComposerWarnings();
368+
warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
369+
});
370+
afterEach(() => {
371+
warn.mockRestore();
372+
});
373+
374+
const withheldWarnings = () =>
375+
(warn.mock.calls as unknown[][])
376+
.map((c: unknown[]) => String(c[0]))
377+
.filter((m: string) => m.includes('offers no comment composer'));
378+
379+
it('the HotCRM shape (types: [task]) draws no composer and no Comments-only option', async () => {
380+
mountBlock(HOTCRM_LEAD_ACTIVITY);
381+
expect(await screen.findByText('Meeting held')).toBeTruthy();
382+
expect(screen.queryByText('a posted comment')).toBeNull();
383+
expect(screen.queryByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeNull();
384+
const options = await filterOptionLabels();
385+
expect(options).toContain('All Activity');
386+
expect(options).not.toContain(COMMENTS_ONLY);
387+
});
388+
389+
it('CONTROL: types that admits comment keeps the composer and the option, and the comment shows', async () => {
390+
mountBlock({ ...HOTCRM_LEAD_ACTIVITY, types: ['task', 'comment'] });
391+
expect(await screen.findByText('a posted comment')).toBeTruthy();
392+
expect(screen.getByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeTruthy();
393+
expect(await filterOptionLabels()).toContain(COMMENTS_ONLY);
394+
expect(withheldWarnings()).toHaveLength(0);
395+
});
396+
397+
it('CONTROL: no types keeps the composer and the option, and the comment shows', async () => {
398+
mountBlock({ limit: 20, showCompleted: true });
399+
expect(await screen.findByText('a posted comment')).toBeTruthy();
400+
expect(screen.getByPlaceholderText(COMPOSER_PLACEHOLDER)).toBeTruthy();
401+
expect(await filterOptionLabels()).toContain(COMMENTS_ONLY);
402+
expect(withheldWarnings()).toHaveLength(0);
403+
});
404+
405+
it('warns once, naming the block, its types and both fixes, however often it renders', async () => {
406+
const first = mountBlock(HOTCRM_LEAD_ACTIVITY);
407+
expect(await screen.findByText('Meeting held')).toBeTruthy();
408+
first.rerender(
409+
<RecordContextProvider objectName="crm_account" recordId="rec-alpha" data={{ id: 'rec-alpha', name: 'Alpha' }} dataSource={makeDataSource()}>
410+
{withHost(<RecordActivityRenderer schema={{ type: 'record:activity', id: 'lead_activity', properties: { ...HOTCRM_LEAD_ACTIVITY } } as any} />)}
411+
</RecordContextProvider>,
412+
);
413+
first.unmount();
414+
mountBlock(HOTCRM_LEAD_ACTIVITY);
415+
expect(await screen.findByText('Meeting held')).toBeTruthy();
416+
const said = withheldWarnings();
417+
expect(said).toHaveLength(1);
418+
expect(said[0]).toContain('record:activity "lead_activity"');
419+
expect(said[0]).toContain('["task"]');
420+
expect(said[0]).toContain('add "comment" to `types`');
421+
expect(said[0]).toContain('`showCommentInput: false`');
422+
});
423+
424+
it('an author who switched the composer off is not told anything', async () => {
425+
mountBlock({ ...HOTCRM_LEAD_ACTIVITY, showCommentInput: false });
426+
expect(await screen.findByText('Meeting held')).toBeTruthy();
427+
expect(withheldWarnings()).toHaveLength(0);
428+
});
429+
});

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
* the wiring below reads them off that context instead of inventing a private
4646
* one (this package has no access to the current user, so it cannot author a
4747
* `sys_comment` row on its own):
48-
* `showCommentInput` (needs `onAddComment`) · `enableThreading` (replies
48+
* `showCommentInput` (needs `onAddComment`, and a `types` that admits
49+
* `comment`: objectstack#34371) · `enableThreading` (replies
4950
* need `onAddReply`) · `enableReactions` (needs `onToggleReaction`) ·
5051
* `enableMentions` (withholds the @-autocomplete suggestions when off)
5152
*
@@ -75,6 +76,8 @@ import {
7576
normalizeLimit,
7677
describeRefusedFeedLimit,
7778
isRefusedFeedRead,
79+
feedTypesAdmitComments,
80+
warnWithheldCommentComposer,
7881
IMPERSONATED_ACTOR_FALLBACK,
7982
type SysActivityRow,
8083
} from './recordActivityFeed';
@@ -92,6 +95,15 @@ import {
9295
type TimelineStreamFilter,
9396
} from '../recordTimelineStream';
9497

98+
/**
99+
* Dev mode, in this package's established spelling for it — the build's
100+
* `NODE_ENV`, read per call — the guard `record-related-list.tsx` and
101+
* `record-path.tsx` put on their authoring diagnostics.
102+
*/
103+
const isDevBuild = (): boolean =>
104+
(globalThis as { process?: { env?: Record<string, string | undefined> } }).process?.env
105+
?.NODE_ENV !== 'production';
106+
95107
const splitDesigner = (props: Record<string, any>) => {
96108
const { 'data-obj-id': id, 'data-obj-type': type, style, ...rest } = props || {};
97109
return { designer: { 'data-obj-id': id, 'data-obj-type': type, style }, rest };
@@ -176,6 +188,18 @@ export const RecordActivityRenderer: React.FC<RecordActivityRendererProps> = ({
176188
showSubscriptionToggle: read('showSubscriptionToggle'),
177189
};
178190

191+
// objectstack#34371 — a `types` allow-list that leaves out `comment` filters
192+
// every comment out of this block, the ones posted here included. Such a
193+
// block offers no composer and no Comments-only filter, and, where the
194+
// composer would have been offered, tells the author why once, in development.
195+
const commentsShown = feedTypesAdmitComments(types, BLOCK_NAME);
196+
const composerWithheld = !commentsShown && config.showCommentInput !== false;
197+
const nodeId: string | undefined = typeof schema.id === 'string' ? schema.id : undefined;
198+
const typesKey = JSON.stringify(types ?? null);
199+
React.useEffect(() => {
200+
if (composerWithheld && isDevBuild()) warnWithheldCommentComposer(BLOCK_NAME, nodeId, JSON.parse(typesKey));
201+
}, [composerWithheld, nodeId, typesKey]);
202+
179203
const hostItems: FeedItem[] | undefined = Array.isArray(schema.items)
180204
? (schema.items as FeedItem[])
181205
: Array.isArray(bag.items)
@@ -381,6 +405,7 @@ export const RecordActivityRenderer: React.FC<RecordActivityRendererProps> = ({
381405
hasMore={hasMore}
382406
onLoadMore={handleLoadMore}
383407
onAddComment={discussion?.onAddComment as any}
408+
commentsShown={commentsShown}
384409
onAddReply={discussion?.onAddReply as any}
385410
onToggleReaction={discussion?.onToggleReaction as any}
386411
// objectui#12268: the author's Edit and Delete on their own comment.

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,46 @@ export function normalizeFeedTypes(value: unknown, block: string): FeedItemType[
778778
return kept;
779779
}
780780

781+
/**
782+
* Whether a feed whose authored `types` is `value` can show a comment
783+
* (objectstack#34371): no `types` authored, or an allow-list that names
784+
* `comment`, through the same {@link normalizeFeedTypes} reading
785+
* {@link applyFeedConfig} filters by — so the answer and the rows cannot
786+
* disagree.
787+
*
788+
* A block for which this is `false` offers no comment composer and no
789+
* Comments-only filter: a comment posted there is stored and then filtered out
790+
* of the very feed it was posted to, which reads to the member as a lost post.
791+
*/
792+
export function feedTypesAdmitComments(value: unknown, block: string): boolean {
793+
const types = normalizeFeedTypes(value, block);
794+
return types === undefined || types.includes('comment');
795+
}
796+
797+
/** Blocks already told that their `types` withholds the composer. See {@link warnOnce}. */
798+
const warnedWithheldCommentComposers = new Set<string>();
799+
800+
/** Test seam: forget which blocks have already been told. */
801+
export function resetWithheldCommentComposerWarnings(): void {
802+
warnedWithheldCommentComposers.clear();
803+
}
804+
805+
/**
806+
* The author-facing half of {@link feedTypesAdmitComments} (objectstack#34371):
807+
* once per block (`block` plus the node's `id`, when it has one) and authored
808+
* `types`, name the block, its `types` and both fixes. Called only where the
809+
* composer would otherwise have been offered (`showCommentInput` not `false`).
810+
*/
811+
export function warnWithheldCommentComposer(block: string, nodeId: string | undefined, types: unknown): void {
812+
const scope = nodeId ? `${block} "${nodeId}"` : block;
813+
const shown = JSON.stringify(types);
814+
warnOnce(warnedWithheldCommentComposers, scope, [shown], () =>
815+
`[${scope}] offers no comment composer and no Comments-only filter: its \`types\` (${shown}) `
816+
+ 'leaves out "comment", so a comment posted here would be stored and never shown on this block. '
817+
+ 'To take comments on this block, add "comment" to `types`; to keep it activity-only, '
818+
+ 'set `showCommentInput: false`.');
819+
}
820+
781821
/**
782822
* What the contract admits as this block's row cap: a positive integer NUMBER.
783823
*

0 commit comments

Comments
 (0)