Skip to content
Merged
22 changes: 22 additions & 0 deletions .changeset/36076-phone-comment-page.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
'@object-ui/app-shell': patch
'@object-ui/plugin-detail': patch
'@object-ui/i18n': patch
---

feat(record-page): on a phone, the record's comments open as a page of their own: the threads first, a thread's replies inside it, the comment box docked at the foot, and a long press for a comment's actions

Clause-②: yes (widening) — `@object-ui/plugin-detail` adds the export `CommentsPage` and its type `CommentsPageProps`; `CommentThread` takes a third `mode`, `'page'`, and optional `itemInteraction`, `heldId` and `onHeldActions`; `CommentItem` an optional `interactionProps`; `CommentComposer` and `RichTextCommentInput` (exported) an optional `layout` (`'default' | 'phone'`). `@object-ui/app-shell` reserves the console URL parameter `comments` (`RECORD_COMMENTS_PARAM`, in `RESERVED_URL_PARAMS`). `@object-ui/i18n` adds four keys to every pack: `detail.addReactionEmoji`, `detail.commentThread`, `detail.formatBold`, `detail.formatItalic` (the toolbar's names without their shortcut). Nothing existing is removed or re-typed; the desktop's panel, toolbar and labels are unchanged.
Metadata-protocol: none
Skills-docs: none — no skill under `skills/**` teaches where the console draws a record's comments; `content/docs/frontend/plugins/plugin-detail.mdx` and the plugin-detail README gain the phone's page in this change.

On a phone the record page's top bar gains the comments icon, with the number of unresolved threads. A press opens the record's comments as a page over the record, which stays where it was under it; 「‹」 and the browser's Back return to it.

- The page lists each thread's first comment with 「N 条回复」 under it; a tap opens the thread, the comment first and its replies after it. 「‹ 评论」 returns to the list.
- The comment box is docked at the foot of the screen and stands on the keyboard while it is up. One line until tapped; then a row under the text holds mention, bold, italic, list and code, and send at the right end. In the list it writes a comment, in a thread a reply. No 「Ctrl+Enter」 hint.
- A long press on a comment (or its context menu) raises a sheet from the bottom: six reactions, 「标记已解决」 on a thread's first comment, 「编辑」 and 「删除」 (red, confirmed first), each offered exactly where the desktop's hover row offers it.
- The filter at the top right is the desktop's: 「显示已解决」 and 「只看我参与的」.
- The 动态 tab holds the system entries alone, as on the desktop. On a phone the comments live on this page: this replaces the lines of the two objectstack#36075 entries (the record comment panel, and resolved threads) that said the phone keeps the comments in its 动态 tab, or keeps its feed as before.
- The page is in the URL (`?comments=` for the list, `?comments=<id>` for a thread), so a link or a reload opens it where it was.

Unchanged: the desktop; who may write, resolve, edit or delete a comment (the phone offers each exactly where the desktop does); a record page authored in full and an object with `enable.feeds: false` show no icon.
34 changes: 30 additions & 4 deletions content/docs/frontend/plugins/plugin-detail.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -239,12 +239,38 @@ the record drawer), and no longer inside the 动态 (Activity) tab
The panel and the icon come with the default record page and with a page that
only fills its slots. A record page you author in full keeps the feed blocks it
places (`record:discussion`, `record:activity`) exactly as before, and an object
with `enable.feeds: false` shows no icon. On a phone the comments stay in the
动态 tab.
with `enable.feeds: false` shows no icon.

### On a phone

On a phone the same icon sits at the right of the record page's top bar, with
the same number, and opens the record's comments as a page of their own over
the record (objectstack#36076). The record stays where it was under it: 「‹」
and the browser's Back return to it as it was scrolled.

- **Two levels.** The page lists each thread's first comment, with the faces of
the latest repliers and 「N 条回复」 under it; replies are not on the list. A
tap on a comment opens its thread: the comment first, then the replies,
oldest first. 「‹ 评论」 goes back to the list.
- **The comment box** stays at the foot of the screen, and above the keyboard
while it is up. One line until you tap it; then a row under the text holds
mention, bold, italic, list and code, with send at the right end. In the list
it writes a new comment; in a thread, a reply. It names no keyboard shortcut.
- **A long press** on a comment raises its actions from the bottom: six
reactions on one row, then 「标记已解决」 (on a thread's first comment), 「编辑」
and 「删除」, red, which asks before deleting. Each appears exactly where the
desktop's hover row would offer it. The comment's reactions show under its
text with their counts, yours marked; a tap on one adds yours or takes it back.
- **The filter** at the list's top right is the desktop's: 「显示已解决」 and
「只看我参与的」.
- **The 动态 tab** holds the system entries only, as on the desktop.

The page is addressed by the URL (`?comments=` for the list, `?comments=<id>`
for a thread), so a link or a reload opens it where it was.

The components are exported from `@object-ui/plugin-detail` (`CommentsPanel`,
`CommentsButton`, `CommentThread`, `CommentItem`, `CommentComposer`,
`useRecordComments`); each reads the discussion off the host's
`CommentsPage`, `CommentsButton`, `CommentThread`, `CommentItem`,
`CommentComposer`, `useRecordComments`); each reads the discussion off the host's
`DiscussionContext`, as the feed blocks do.

## The `record:activity` block
Expand Down
18 changes: 18 additions & 0 deletions ui/packages/app-shell/src/urlParams.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
* | | objectui#2257). Never stacks history. | |
* | `palette` | Command palette overlay (alias `cmdk`). | replace |
* | `shortcuts` | Keyboard-shortcuts dialog overlay. | replace |
* | `comments` | The phone's comment page over a record route: | push (open), |
* | | empty = the threads, a top-level comment's id | pop (close) |
* | | = that thread (objectstack#36076). | |
* | `from` | Ancestor breadcrumb trail for a record route, | push (with |
* | | so drilling record→related-record keeps a | the drill-in) |
* | | clickable path back (`Account → #p → Invoice`).| |
Expand Down Expand Up @@ -127,6 +130,20 @@ export const RECORD_RELATED_ENLARGE_PUSHED_STATE = '__relatedEnlargePushed';
*/
export const NAV_DRAWER_OPEN_STATE = '__navDrawerOpen';

/**
* The phone's comment page over the record page (`?comments=`, objectstack#36076):
* present and empty, the record's threads; a top-level comment's id, that
* thread. Read by `RecordDetailView` on a phone's record page only.
*/
export const RECORD_COMMENTS_PARAM = 'comments';

/**
* History-state flag beside {@link RECORD_COMMENTS_PARAM}: the record view
* pushed this `?comments=` entry, so 「‹」 pops it. Not a URL parameter; an
* entry reached by a reload or a shared link carries none, and 「‹」 replaces.
*/
export const RECORD_COMMENTS_PUSHED_STATE = '__commentsPushed';

/** Command palette overlay (ADR-0054 Phase 1; alias `cmdk`). */
export const COMMAND_PALETTE_PARAM = 'palette';

Expand Down Expand Up @@ -170,6 +187,7 @@ export const RESERVED_URL_PARAMS: readonly string[] = [
RECORD_FORM_LINK_PARAM,
RECORD_DETAIL_TAB_PARAM,
RECORD_RELATED_ENLARGE_PARAM,
RECORD_COMMENTS_PARAM,
COMMAND_PALETTE_PARAM,
KEYBOARD_SHORTCUTS_PARAM,
RECORD_TRAIL_PARAM,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import * as React from 'react';
import '@testing-library/jest-dom/vitest';
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { render, cleanup, within, act, waitFor, fireEvent } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { MemoryRouter, useLocation } from 'react-router-dom';

vi.mock('@object-ui/auth', async (importOriginal) => ({
...(await importOriginal<Record<string, unknown>>()),
Expand Down Expand Up @@ -60,6 +60,7 @@ import { MetadataCtx } from '@object-ui/react';
import { MePermissionsProvider, type MePermissionsAuthenticatedResponse } from '@object-ui/permissions';
import { toast } from 'sonner';
import { RecordDetailView } from './RecordDetailView';
import { __clearRecordEditableCache } from '../../../plugin-detail/src/useRecordEditable';

const OBJECT_NAME = 'crm_case';
const NO_FEEDS = 'crm_note';
Expand Down Expand Up @@ -147,13 +148,22 @@ interface MountOptions {
objectName?: string;
pages?: unknown[];
embedded?: boolean;
/** The record route's query, `?comments=…` for the phone's comment page. */
search?: string;
}

async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false }: MountOptions = {}) {
/** The router's location now, for the phone's `?comments=` entries. */
function LocationProbe() {
const location = useLocation();
return <span data-testid="location" data-search={location.search} data-pushed={String(!!(location.state as any)?.__commentsPushed)} />;
}

async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false, search = '' }: MountOptions = {}) {
const rendered = render(
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }} persistLanguage={false}>
<MePermissionsProvider initialPermissions={PERMS}>
<MemoryRouter initialEntries={[`/app/service/${objectName}/${RECORD_ID}`]}>
<MemoryRouter initialEntries={[`/app/service/${objectName}/${RECORD_ID}${search}`]}>
<LocationProbe />
<MetadataCtx.Provider value={metadataFor(pages)}>
<RecordDetailView
dataSource={makeDataSource()}
Expand Down Expand Up @@ -301,3 +311,141 @@ describe('the record comment panel (objectstack#36075)', () => {
expect(await within(panel(container)!).findByText(ADA_BODY)).toBeInTheDocument();
});
});

/**
* objectstack#36076 — the phone's comment page, through the REAL
* `RecordDetailView` at 375 wide:
*
* - The icon is in the phone's top bar with the number of threads; a press
* pushes `?comments=` and draws the page over the record, which stays
* mounted under it.
* - The list shows top-level comments only; a tap pushes the thread
* (`?comments=<id>`), which shows the comment and its reply. 「‹」 pops back
* to the list, then to the record, and the focus returns to the icon.
* - A link or a reload straight to a thread: 「‹」 replaces the URL one level up.
* - The 动态 tab keeps the system entries alone, as on the desktop.
* - No icon on an object with feeds off.
*/
describe("the phone's comment page (objectstack#36076)", () => {
beforeEach(() => setWindowWidth(375));

const page = () => document.querySelector('[data-comments-page]') as HTMLElement | null;
const search = () => document.querySelector('[data-testid="location"]')!.getAttribute('data-search');

it('the top bar carries the icon with the thread count; a press pushes the page over the record', async () => {
const { container } = await mount();
await waitFor(() => expect(button(container)).not.toBeNull());
expect(button(container)!.closest('[data-record-top-bar]')).not.toBeNull();
await waitFor(() => expect(button(container)!.querySelector('[data-comments-count]')).toHaveTextContent('2'));
expect(panel(container)).toBeNull();
fireEvent.click(button(container)!);
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
expect(search()).toBe('?comments=');
expect(document.querySelector('[data-testid="location"]')).toHaveAttribute('data-pushed', 'true');
const list = within(page()!);
expect(await list.findByText(ADA_BODY)).toBeInTheDocument();
expect(list.getByText(GRACE_BODY)).toBeInTheDocument();
expect(list.queryByText(REPLY_BODY)).toBeNull();
expect(list.getByRole('button', { name: /1 reply/ })).toBeInTheDocument();
// The record is still there, under the page.
expect(within(container).getAllByText(`Case ${RECORD_ID}`).length).toBeGreaterThan(0);
});

it('a tap opens the thread; 「‹」 goes back to the list, then to the record, focus on the icon', async () => {
const { container } = await mount();
await waitFor(() => expect(button(container)).not.toBeNull());
fireEvent.click(button(container)!);
fireEvent.click(await within(page()!).findByText(ADA_BODY));
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'thread'));
expect(search()).toBe('?comments=c-ada');
expect(within(page()!).getByText(REPLY_BODY)).toBeInTheDocument();
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
expect(search()).toBe('?comments=');
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
await waitFor(() => expect(page()).toBeNull());
expect(search()).toBe('');
await waitFor(() => expect(document.activeElement).toBe(button(container)));
});

it('a link straight to a thread: 「‹」 replaces the URL one level up', async () => {
await mount({ search: '?comments=c-ada' });
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'thread'));
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
expect(search()).toBe('?comments=');
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
await waitFor(() => expect(page()).toBeNull());
expect(search()).toBe('');
});

it('the 动态 tab keeps the system entries alone', async () => {
const { container } = await mount({ search: '?tab=activity' });
await waitFor(() => expect(button(container)).not.toBeNull());
await act(async () => {});
expect(within(container).queryByText(ADA_BODY)).toBeNull();
expect(within(container).queryByText('Ctrl+Enter', { exact: false })).toBeNull();
});

it("a moderator's first long press on another's comment: the sheet gains Edit when the late answer lands", async () => {
__clearRecordEditableCache();
// The record's update is answered at once (the viewer moderates); the row
// floor's answer for a comment the viewer did not write comes later.
let answerFloor!: () => void;
const floor = new Promise<void>((resolve) => {
answerFloor = resolve;
});
const explained: string[] = [];
const allow = () =>
new Response(JSON.stringify({ allowed: true, record: { visible: true } }), {
status: 200,
headers: { 'content-type': 'application/json' },
});
vi.stubGlobal(
'fetch',
vi.fn(async (url: string, init?: RequestInit) => {
if (String(url).endsWith('/security/explain')) {
const body = JSON.parse(String(init?.body ?? '{}'));
explained.push(body.object);
if (body.object === 'sys_comment') await floor;
return allow();
}
return new Response(JSON.stringify({ data: [] }), { status: 200, headers: { 'content-type': 'application/json' } });
}),
);
try {
await mount({ search: '?comments=' });
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
const grace = (await within(page()!).findByText(GRACE_BODY)).closest('[data-comment-id]') as HTMLElement;
// Opening the page asks nothing about other people's comments.
await act(async () => {});
expect(explained).not.toContain('sys_comment');
vi.useFakeTimers();
fireEvent.pointerDown(grace, { pointerType: 'touch', button: 0, clientX: 10, clientY: 10 });
act(() => {
vi.advanceTimersByTime(600);
});
fireEvent.pointerUp(grace, { pointerType: 'touch' });
vi.useRealTimers();
// The press asked; the hold opened before the answer.
expect(explained).toContain('sys_comment');
const sheet = () => document.querySelector('[data-comment-action-sheet]') as HTMLElement | null;
const rows = () =>
Array.from(sheet()?.querySelectorAll('[data-comment-action]') ?? []).map((row) => row.getAttribute('data-comment-action'));
await waitFor(() => expect(rows()).toEqual(['delete']));
await act(async () => {
answerFloor();
});
await waitFor(() => expect(rows()).toEqual(['edit', 'delete']));
} finally {
vi.useRealTimers();
__clearRecordEditableCache();
}
});

it('no icon on an object with feeds off', async () => {
const { container } = await mount({ objectName: NO_FEEDS });
await act(async () => {});
expect(button(container)).toBeNull();
});
});
Loading
Loading