Skip to content

Commit c30ce97

Browse files
feat(record-page): on a phone the record's comments open as a page: threads first, replies inside, the box docked at the foot, a long press for actions (#36076) (#36208)
<!-- claude-projects-attribution: {"github_login":"os-sales"} --> _Requested by **Sales** · [project thread](https://claude.ai/code/project/chan_01D5bWFY3rFzgJcytD5gD4Uu?thread=cmsg_01D5bWFY3rFzgJcytD5gD4UuLteuRKBSRXDK9REnG68QAD)_ repo:objectstack#1 · os-sales · session_01L6bhgTfxZyB5T41DdoPaBy Fixes #36076 Clause-②: yes (widening) — `@object-ui/plugin-detail` exports `CommentsPage` and `CommentsPageProps`; `CommentThread` takes a third `mode` (`'page'`) and optional `itemInteraction`, `heldId` and `onHeldActions`; `CommentItem` an optional `interactionProps`; `CommentComposer` and `RichTextCommentInput` an optional `layout` (`'default' | 'phone'`). `@object-ui/app-shell` reserves the console URL parameter `comments` (`RECORD_COMMENTS_PARAM`, listed in `RESERVED_URL_PARAMS`). `@object-ui/i18n` gains four `detail.*` keys in every pack. Nothing is removed or re-typed; the desktop is unchanged. Metadata-protocol: none ## 维护者速读 - 手机上打开一条记录,右上角多了评论图标,旁边是未解决的评论串数。点了进**整页**评论,盖在记录页上;左上「‹ 记录名」或系统返回键回到记录页,记录页滚到哪还在哪(实测返回前后都是 74)。 - **两层**:列表只列第一层评论,有回复的下面是回复人头像加「N 条回复」;点一条进这一串,原评论在上,回复按时间往下,左上「‹ 评论」回列表。 - **输入框固定在屏幕底部**,键盘弹起时站在键盘上面。平时一行,点了展开,下面一排:提到人、加粗、斜体、列表、代码,右边发送。在列表里发的是新评论,在一串里发的是回复(两个框各留各的草稿)。页面上没有「Ctrl+Enter」字样。 - **长按一条评论**(或系统的长按菜单),从底部升起面板:第一行六个表情,下面「标记已解决」(只在第一层)、「编辑」「删除」(红色,点了先确认)。每一项出现的条件和电脑端悬停那排完全一样,手机没有另判权限。 - 列表右上角筛选:「显示已解决」「只看我参与的」,和电脑端同一个菜单。手机上「动态」页签只剩系统记录。 - **删除的门**:#36186+#36191 已合并并合入本分支。手机长按面板和电脑端用同一套判定:普通成员能删自己没有回复的评论,能给自己看得到的任何评论串标记已解决。 - 不改电脑端,不改任何权限和服务端。 ## What changes **The phone's comment page** (`@object-ui/plugin-detail`, `src/comments/`) - `CommentsPage`: a full-screen page (`role="dialog"`, fixed over the host) that reads `useRecordComments()`, the same discussion, writes and gates as the desktop panel. Props: `threadId` (`null` = the list), `onOpenThread`, `onBack`, `backLabel`, `onEngage`. - The list draws each thread with `CommentThread mode="summary"`; a tap on a comment outside its own controls, Enter on a focused comment, or its 「N 条回复」 opens the thread. A thread that is not held (deleted, stale link) shows the list. - The thread draws `CommentThread mode="page"` (new): its comment, then every reply, with no reply box of its own; 「回复」 there puts the caret in the docked box. - Two docked `CommentComposer layout="phone"` boxes (list and reply), each keeping its own draft; the list's stays mounted while a thread is open, so its draft and the list's scroll survive a visit to a thread. - The page follows the on-screen keyboard through `visualViewport` (top and height while the keyboard covers more than 80 px), the same reading as `PhoneListPanels`' sheet; the inline style is positional only. - Esc returns one level (`data-owns-escape`); the focus lands on 「‹」 when a level opens. - `useCommentPress`: 500 ms hold, cancelled past 10 px of travel; the click that ends a hold is swallowed. `onPressStart` fires at the press itself (pointer down, context menu, Enter/Space), and the page hands it `onEngage`, so the host's question about the comment's actions is on the wire before the hold completes. `contextmenu` opens the same sheet (Android's own long press, the keyboard's menu key, a right click). One record of the press serves every comment. - `CommentActionSheet` (vaul `Drawer`): six reactions (the viewer's own marked `aria-pressed`), then Mark resolved / Reopen, Edit, Delete (destructive). A row is drawn only where the comment's `CommentItemActions` hands its handler: these are the object `CommentThread.actionsOf` builds for the desktop's hover row, so every gate is the thread's. The sheet is never a snapshot of the press: `CommentThread` takes `heldId` and reports the held comment's current actions to `onHeldActions` each time what they offer changes, so a verdict that lands while the sheet is up adds its rows (L1-c REWORK 7070700220). A comment with no action raises nothing. - `CommentsFilterMenu`: the desktop panel's filter menu, extracted unchanged so both surfaces draw the same one. - `CommentItem.interactionProps`: spread on the comment's box with `select-none` and no iOS callout, except while it is being edited. - `RichTextCommentInput layout="phone"`: the editor first, then one row (mention, bold, italic, list, code; send at the right end, round, 44 px), no preview, the names without their shortcut (`detail.formatBold`, `detail.formatItalic`), 16 px text. A press on the row keeps the caret (and the keyboard) in the box. The default layout is untouched. **The record page** (`@object-ui/app-shell`) - `commentsPageOffered` in `RecordDetailView`: the same rule as `commentsPanelOffered` (feeds on, a standard page, a record id) on a phone and not embedded. `commentsSurfaceOffered` (either one) now drives what `commentsPanelOffered` drove: the discussion rides the open's payload, the 动态 stream gives the comments up (`RecordCommentsInPanelContext`) and its count leaves them out. - `?comments=` (list) / `?comments=<id>` (thread), read from the router: opening and a thread push an entry flagged `__commentsPushed` in history state (the entry's other state kept); 「‹」 pops a flagged entry and otherwise replaces the URL one level up (a reload or a shared link). The page is mounted inside the record's `DiscussionContextProvider`, over the record, which stays mounted, so nothing is read again and the scroll is kept. Closing returns the focus to the top bar's comments icon. - The phone's `RecordTopBar` gets the `comments` slot (`CommentsButton` at 44 px). - The explain probes: `moderatesComments` is asked while the panel or the page is open; `updatesOthersComments` on the first press on a comment (the page's `onEngage`, fired at pointer down), as on the desktop's first reach into the panel. Opening the record asks nothing more. **Strings**: `detail.addReactionEmoji`, `detail.commentThread`, `detail.formatBold`, `detail.formatItalic` in all eleven packs (zh-Hant regenerated) and the provider-less defaults; the rest reuse existing keys (`detail.sendComment` already existed). **Docs**: `content/docs/frontend/plugins/plugin-detail.mdx` (### On a phone) and the plugin-detail README (### The phone's comment page). **Pending release notes**: `.changeset/36075-record-comments-panel.md` (from #36114) is left as it stands on main. Its line "the phone keeps the comments in its 动态 tab" is answered in this PR's own changeset, which says that on a phone the comments live on the phone's page and that this replaces that line. `36075-comments-resolved.md` ("…and the phone keep their feed as before") is left as it stands too; the same sentence of this PR's changeset answers it. ## Small calls made here (dev-thread rule, Sales 22:19:27Z) 1. The full page is a URL parameter over the record route, not a new route: the record stays mounted (no re-read, scroll kept), precedent `?related=`. 2. No 「回复」 row in the long-press sheet: in a thread the docked box is the reply; in the list a tap opens the thread. 3. No 「预览」 on the phone toolbar; the card's row lists mention, bold, italic, list, code and send. 4. The filter is the desktop's dropdown, not a bottom sheet. 5. A long press on a comment with no available action opens nothing (a read-only discussion). 6. Thread title 「评论串」; the list keeps 「评论」. ## Overlap - #36136 (wide-screen pinned details): MERGED (48c732c) and merged into this branch; the only conflict was the `@object-ui/plugin-detail` import line in `RecordDetailView.tsx` (main's list plus `CommentsPage`). After the merge `tsc` for app-shell is clean and every `RecordDetailView.*` and `plugin-detail/src/comments` test passes (103 files, 873 tests), as does `i18n` (105 files). - #36200 (#36186+#36191 comment doors): MERGED (d12ac84) and merged into this branch with no conflict. The phone sheet draws from the same `actionsOf`, so it takes the new ✓ gate (any thread the viewer reads) and the own-comment delete door (`ownCommentDeletesOnly`: own comment with no reply only) with no code change; one CommentsPage test expectation moved from `['delete']` to `['resolve','delete']`, and a new test pins the door on the phone sheet. - #36151 (phone record bottom bar, not pushed yet) and #36147: same file, different blocks. ## Verification **New tests (all pass)** - `plugin-detail/src/comments/CommentsPage.test.tsx` (18): the list shows top-level comments with 「2 replies」, no reply; a tap on a comment or its count opens the thread, a tap on a reaction is the reaction's; Enter opens; 「‹」 names the record; the docked box writes a comment, toolbar order @ B I list code Send, no 「Ctrl」 in the page; a thread shows comment then replies and replies to its comment; a missing thread shows the list; the list draft survives a thread visit; long press on own comment: 6 reactions (own one pressed), resolve, edit, delete, and the release opens nothing, `onEngage` once; another's comment: no edit or delete; a reply: no resolve; a sheet reaction toggles, Delete reaches the host; a press that travels is a scroll; contextmenu opens the sheet; read-only raises nothing and docks no box; a moderator's press on another's comment engages at pointer down, the sheet opens with Mark resolved and Delete, and when `updatesOthersComments` turns true with the sheet up Edit joins (fails on the pre-fix head); behind the own-comment delete door Delete is on the viewer's own reply only, not on their comment with replies nor on another's reply; resolved threads hidden by default with the filter offered. - `app-shell/src/views/RecordDetailView.commentsPanel-36075.test.tsx`, new top-level describe (6), the real `RecordDetailView` at 375: the top-bar icon with 「2」, a press pushes `?comments=` (flagged) and draws the list over the still-mounted record; tap → `?comments=c-ada` with the reply, 「‹」 → list → record, focus on the icon; a link straight to a thread: 「‹」 replaces one level up twice; the 动态 tab draws no comment and no 「Ctrl」; no icon with feeds off; a moderator's first long press on Grace's comment with the `sys_comment` explain answered late: no comment explain before the press, asked at the press, the sheet shows Delete, then Edit and Delete once the answer lands (fails on the pre-fix head). **Local runs** (after merging main `cbd582f4`): every `app-shell/src/views/RecordDetailView.*`, `plugin-detail/src/comments` and `i18n` test file, 209 files, 2,830 tests pass. Before the merge, a wider set (all `RecordDetailView.*`, `recordCommentsPanel*`, `ObjectView.phone*`, `app-shell/src/__tests__`, all of `plugin-detail` and `i18n`): 640 files, 6,991 tests pass. `tsc` (src and tests) clean for plugin-detail and app-shell. ESLint on the changed files: 0 errors (warnings only of the kinds already in these files). `overlap-check.mjs`: clean against main; #36136 conflict as above. After the L1-c fix: all of `plugin-detail` (405 files, 3,745 tests) and the host comments file (16 tests) pass; ESLint 0 errors on the touched files. **Browser evidence** (CRM example on `objectstack dev --fresh`, console on Vite from this branch, zh-CN, 375×812 touch, light and dark; seat-side folder `/mnt/project-files/build-seat1/36076/`, script and readings in its README) | Shot | Reading | |---|---| | Record page | icon 「3」 at the top bar's right | | List | 「‹ Globex Ltd」 · 评论 · filter; three first-level comments, 「2 条回复」 under the first | | Thread | comment, then both replies; URL `?comments=<id>` | | Composer expanded | @ B I list code, round send at the right; the box's bottom at 812 (the viewport's) | | Long press, own comment | six reactions, 标记已解决, 编辑, 删除 (red) | | After 👍 | 「👍 1」 under the comment, marked as own | | Back to the record | scrollTop 74 before, 74 after | | 动态 tab | 「动态 (0)」, no comment, no box | Not shown in the browser (the run's only account is an administrator, who moderates): a member's long press on someone else's comment; pinned by the unit test above. The iOS keyboard cannot be emulated in headless Chromium. ## Human Minimum - [x] 1. Schemas start as Zod; `packages/spec` holds no runtime logic. (not touched) - [x] 2. Every name I added uses the casing for its kind. - [x] 3. No formatter ran; `pnpm lint` passes on the changed files. - [x] 4. One issue, one branch off an up-to-date `main`, one pull request. - [x] 5. A change that publishes carries a changeset, and both declaration lines are filled in here and in the changeset. - [x] 6. `packages/spec` touched: n/a. - [x] 7. No hand edits to `content/docs/references/`, `packages/*/CHANGELOG.md` or `content/docs/releases/`. - [x] 8. Title, body and comments are in English (the 维护者速读 block is the maintainer's summary, in the maintainer's language). Branch name is the harness-assigned `claude/project-thread-uzlelf`. --- _Generated by [Claude Code](https://claude.ai/code/session_01L6bhgTfxZyB5T41DdoPaBy)_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01L6bhgTfxZyB5T41DdoPaBy <!-- signed: repo:objectstack#1 · os-sales · session_01L6bhgTfxZyB5T41DdoPaBy --> --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 2955685 commit c30ce97

30 files changed

Lines changed: 1523 additions & 86 deletions
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@object-ui/app-shell': patch
3+
'@object-ui/plugin-detail': patch
4+
'@object-ui/i18n': patch
5+
---
6+
7+
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
8+
9+
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.
10+
Metadata-protocol: none
11+
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.
12+
13+
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.
14+
15+
- 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.
16+
- 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.
17+
- 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.
18+
- The filter at the top right is the desktop's: 「显示已解决」 and 「只看我参与的」.
19+
- 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.
20+
- 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.
21+
22+
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.

‎content/docs/frontend/plugins/plugin-detail.mdx‎

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -239,12 +239,38 @@ the record drawer), and no longer inside the 动态 (Activity) tab
239239
The panel and the icon come with the default record page and with a page that
240240
only fills its slots. A record page you author in full keeps the feed blocks it
241241
places (`record:discussion`, `record:activity`) exactly as before, and an object
242-
with `enable.feeds: false` shows no icon. On a phone the comments stay in the
243-
动态 tab.
242+
with `enable.feeds: false` shows no icon.
243+
244+
### On a phone
245+
246+
On a phone the same icon sits at the right of the record page's top bar, with
247+
the same number, and opens the record's comments as a page of their own over
248+
the record (objectstack#36076). The record stays where it was under it: 「‹」
249+
and the browser's Back return to it as it was scrolled.
250+
251+
- **Two levels.** The page lists each thread's first comment, with the faces of
252+
the latest repliers and 「N 条回复」 under it; replies are not on the list. A
253+
tap on a comment opens its thread: the comment first, then the replies,
254+
oldest first. 「‹ 评论」 goes back to the list.
255+
- **The comment box** stays at the foot of the screen, and above the keyboard
256+
while it is up. One line until you tap it; then a row under the text holds
257+
mention, bold, italic, list and code, with send at the right end. In the list
258+
it writes a new comment; in a thread, a reply. It names no keyboard shortcut.
259+
- **A long press** on a comment raises its actions from the bottom: six
260+
reactions on one row, then 「标记已解决」 (on a thread's first comment), 「编辑」
261+
and 「删除」, red, which asks before deleting. Each appears exactly where the
262+
desktop's hover row would offer it. The comment's reactions show under its
263+
text with their counts, yours marked; a tap on one adds yours or takes it back.
264+
- **The filter** at the list's top right is the desktop's: 「显示已解决」 and
265+
「只看我参与的」.
266+
- **The 动态 tab** holds the system entries only, as on the desktop.
267+
268+
The page is addressed by the URL (`?comments=` for the list, `?comments=<id>`
269+
for a thread), so a link or a reload opens it where it was.
244270

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

250276
## The `record:activity` block

‎ui/packages/app-shell/src/urlParams.ts‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import { NAV_RUN_ACTION_PARAM } from '@object-ui/layout';
5151
* | | objectui#2257). Never stacks history. | |
5252
* | `palette` | Command palette overlay (alias `cmdk`). | replace |
5353
* | `shortcuts` | Keyboard-shortcuts dialog overlay. | replace |
54+
* | `comments` | The phone's comment page over a record route: | push (open), |
55+
* | | empty = the threads, a top-level comment's id | pop (close) |
56+
* | | = that thread (objectstack#36076). | |
5457
* | `from` | Ancestor breadcrumb trail for a record route, | push (with |
5558
* | | so drilling record→related-record keeps a | the drill-in) |
5659
* | | clickable path back (`Account → #p → Invoice`).| |
@@ -127,6 +130,20 @@ export const RECORD_RELATED_ENLARGE_PUSHED_STATE = '__relatedEnlargePushed';
127130
*/
128131
export const NAV_DRAWER_OPEN_STATE = '__navDrawerOpen';
129132

133+
/**
134+
* The phone's comment page over the record page (`?comments=`, objectstack#36076):
135+
* present and empty, the record's threads; a top-level comment's id, that
136+
* thread. Read by `RecordDetailView` on a phone's record page only.
137+
*/
138+
export const RECORD_COMMENTS_PARAM = 'comments';
139+
140+
/**
141+
* History-state flag beside {@link RECORD_COMMENTS_PARAM}: the record view
142+
* pushed this `?comments=` entry, so 「‹」 pops it. Not a URL parameter; an
143+
* entry reached by a reload or a shared link carries none, and 「‹」 replaces.
144+
*/
145+
export const RECORD_COMMENTS_PUSHED_STATE = '__commentsPushed';
146+
130147
/** Command palette overlay (ADR-0054 Phase 1; alias `cmdk`). */
131148
export const COMMAND_PALETTE_PARAM = 'palette';
132149

@@ -170,6 +187,7 @@ export const RESERVED_URL_PARAMS: readonly string[] = [
170187
RECORD_FORM_LINK_PARAM,
171188
RECORD_DETAIL_TAB_PARAM,
172189
RECORD_RELATED_ENLARGE_PARAM,
190+
RECORD_COMMENTS_PARAM,
173191
COMMAND_PALETTE_PARAM,
174192
KEYBOARD_SHORTCUTS_PARAM,
175193
RECORD_TRAIL_PARAM,

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

Lines changed: 151 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import * as React from 'react';
2525
import '@testing-library/jest-dom/vitest';
2626
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
2727
import { render, cleanup, within, act, waitFor, fireEvent } from '@testing-library/react';
28-
import { MemoryRouter } from 'react-router-dom';
28+
import { MemoryRouter, useLocation } from 'react-router-dom';
2929

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

6465
const OBJECT_NAME = 'crm_case';
6566
const NO_FEEDS = 'crm_note';
@@ -147,13 +148,22 @@ interface MountOptions {
147148
objectName?: string;
148149
pages?: unknown[];
149150
embedded?: boolean;
151+
/** The record route's query, `?comments=…` for the phone's comment page. */
152+
search?: string;
150153
}
151154

152-
async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false }: MountOptions = {}) {
155+
/** The router's location now, for the phone's `?comments=` entries. */
156+
function LocationProbe() {
157+
const location = useLocation();
158+
return <span data-testid="location" data-search={location.search} data-pushed={String(!!(location.state as any)?.__commentsPushed)} />;
159+
}
160+
161+
async function mount({ objectName = OBJECT_NAME, pages = [], embedded = false, search = '' }: MountOptions = {}) {
153162
const rendered = render(
154163
<I18nProvider config={{ defaultLanguage: 'en', detectBrowserLanguage: false }} persistLanguage={false}>
155164
<MePermissionsProvider initialPermissions={PERMS}>
156-
<MemoryRouter initialEntries={[`/app/service/${objectName}/${RECORD_ID}`]}>
165+
<MemoryRouter initialEntries={[`/app/service/${objectName}/${RECORD_ID}${search}`]}>
166+
<LocationProbe />
157167
<MetadataCtx.Provider value={metadataFor(pages)}>
158168
<RecordDetailView
159169
dataSource={makeDataSource()}
@@ -301,3 +311,141 @@ describe('the record comment panel (objectstack#36075)', () => {
301311
expect(await within(panel(container)!).findByText(ADA_BODY)).toBeInTheDocument();
302312
});
303313
});
314+
315+
/**
316+
* objectstack#36076 — the phone's comment page, through the REAL
317+
* `RecordDetailView` at 375 wide:
318+
*
319+
* - The icon is in the phone's top bar with the number of threads; a press
320+
* pushes `?comments=` and draws the page over the record, which stays
321+
* mounted under it.
322+
* - The list shows top-level comments only; a tap pushes the thread
323+
* (`?comments=<id>`), which shows the comment and its reply. 「‹」 pops back
324+
* to the list, then to the record, and the focus returns to the icon.
325+
* - A link or a reload straight to a thread: 「‹」 replaces the URL one level up.
326+
* - The 动态 tab keeps the system entries alone, as on the desktop.
327+
* - No icon on an object with feeds off.
328+
*/
329+
describe("the phone's comment page (objectstack#36076)", () => {
330+
beforeEach(() => setWindowWidth(375));
331+
332+
const page = () => document.querySelector('[data-comments-page]') as HTMLElement | null;
333+
const search = () => document.querySelector('[data-testid="location"]')!.getAttribute('data-search');
334+
335+
it('the top bar carries the icon with the thread count; a press pushes the page over the record', async () => {
336+
const { container } = await mount();
337+
await waitFor(() => expect(button(container)).not.toBeNull());
338+
expect(button(container)!.closest('[data-record-top-bar]')).not.toBeNull();
339+
await waitFor(() => expect(button(container)!.querySelector('[data-comments-count]')).toHaveTextContent('2'));
340+
expect(panel(container)).toBeNull();
341+
fireEvent.click(button(container)!);
342+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
343+
expect(search()).toBe('?comments=');
344+
expect(document.querySelector('[data-testid="location"]')).toHaveAttribute('data-pushed', 'true');
345+
const list = within(page()!);
346+
expect(await list.findByText(ADA_BODY)).toBeInTheDocument();
347+
expect(list.getByText(GRACE_BODY)).toBeInTheDocument();
348+
expect(list.queryByText(REPLY_BODY)).toBeNull();
349+
expect(list.getByRole('button', { name: /1 reply/ })).toBeInTheDocument();
350+
// The record is still there, under the page.
351+
expect(within(container).getAllByText(`Case ${RECORD_ID}`).length).toBeGreaterThan(0);
352+
});
353+
354+
it('a tap opens the thread; 「‹」 goes back to the list, then to the record, focus on the icon', async () => {
355+
const { container } = await mount();
356+
await waitFor(() => expect(button(container)).not.toBeNull());
357+
fireEvent.click(button(container)!);
358+
fireEvent.click(await within(page()!).findByText(ADA_BODY));
359+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'thread'));
360+
expect(search()).toBe('?comments=c-ada');
361+
expect(within(page()!).getByText(REPLY_BODY)).toBeInTheDocument();
362+
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
363+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
364+
expect(search()).toBe('?comments=');
365+
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
366+
await waitFor(() => expect(page()).toBeNull());
367+
expect(search()).toBe('');
368+
await waitFor(() => expect(document.activeElement).toBe(button(container)));
369+
});
370+
371+
it('a link straight to a thread: 「‹」 replaces the URL one level up', async () => {
372+
await mount({ search: '?comments=c-ada' });
373+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'thread'));
374+
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
375+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
376+
expect(search()).toBe('?comments=');
377+
fireEvent.click(page()!.querySelector('[data-comments-page-back]')!);
378+
await waitFor(() => expect(page()).toBeNull());
379+
expect(search()).toBe('');
380+
});
381+
382+
it('the 动态 tab keeps the system entries alone', async () => {
383+
const { container } = await mount({ search: '?tab=activity' });
384+
await waitFor(() => expect(button(container)).not.toBeNull());
385+
await act(async () => {});
386+
expect(within(container).queryByText(ADA_BODY)).toBeNull();
387+
expect(within(container).queryByText('Ctrl+Enter', { exact: false })).toBeNull();
388+
});
389+
390+
it("a moderator's first long press on another's comment: the sheet gains Edit when the late answer lands", async () => {
391+
__clearRecordEditableCache();
392+
// The record's update is answered at once (the viewer moderates); the row
393+
// floor's answer for a comment the viewer did not write comes later.
394+
let answerFloor!: () => void;
395+
const floor = new Promise<void>((resolve) => {
396+
answerFloor = resolve;
397+
});
398+
const explained: string[] = [];
399+
const allow = () =>
400+
new Response(JSON.stringify({ allowed: true, record: { visible: true } }), {
401+
status: 200,
402+
headers: { 'content-type': 'application/json' },
403+
});
404+
vi.stubGlobal(
405+
'fetch',
406+
vi.fn(async (url: string, init?: RequestInit) => {
407+
if (String(url).endsWith('/security/explain')) {
408+
const body = JSON.parse(String(init?.body ?? '{}'));
409+
explained.push(body.object);
410+
if (body.object === 'sys_comment') await floor;
411+
return allow();
412+
}
413+
return new Response(JSON.stringify({ data: [] }), { status: 200, headers: { 'content-type': 'application/json' } });
414+
}),
415+
);
416+
try {
417+
await mount({ search: '?comments=' });
418+
await waitFor(() => expect(page()).toHaveAttribute('data-comments-page', 'list'));
419+
const grace = (await within(page()!).findByText(GRACE_BODY)).closest('[data-comment-id]') as HTMLElement;
420+
// Opening the page asks nothing about other people's comments.
421+
await act(async () => {});
422+
expect(explained).not.toContain('sys_comment');
423+
vi.useFakeTimers();
424+
fireEvent.pointerDown(grace, { pointerType: 'touch', button: 0, clientX: 10, clientY: 10 });
425+
act(() => {
426+
vi.advanceTimersByTime(600);
427+
});
428+
fireEvent.pointerUp(grace, { pointerType: 'touch' });
429+
vi.useRealTimers();
430+
// The press asked; the hold opened before the answer.
431+
expect(explained).toContain('sys_comment');
432+
const sheet = () => document.querySelector('[data-comment-action-sheet]') as HTMLElement | null;
433+
const rows = () =>
434+
Array.from(sheet()?.querySelectorAll('[data-comment-action]') ?? []).map((row) => row.getAttribute('data-comment-action'));
435+
await waitFor(() => expect(rows()).toEqual(['delete']));
436+
await act(async () => {
437+
answerFloor();
438+
});
439+
await waitFor(() => expect(rows()).toEqual(['edit', 'delete']));
440+
} finally {
441+
vi.useRealTimers();
442+
__clearRecordEditableCache();
443+
}
444+
});
445+
446+
it('no icon on an object with feeds off', async () => {
447+
const { container } = await mount({ objectName: NO_FEEDS });
448+
await act(async () => {});
449+
expect(button(container)).toBeNull();
450+
});
451+
});

0 commit comments

Comments
 (0)