diff --git a/.changeset/36070-comment-small-fixes.md b/.changeset/36070-comment-small-fixes.md new file mode 100644 index 00000000000..473b383e519 --- /dev/null +++ b/.changeset/36070-comment-small-fixes.md @@ -0,0 +1,20 @@ +--- +'@object-ui/plugin-detail': patch +'@object-ui/fields': patch +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +fix(comments): Reply puts the caret in the reply box, comments show the author's avatar or initials, the mention menu opens at the caret, and a delete says it went through + +Clause-②: yes (widening) +Metadata-protocol: none + +Four small fixes to comments on the record page: + +- **Reply.** Pressing Reply on a comment opened the reply box but left focus on the button, so typing went nowhere (or into the main comment box). The caret now goes into the reply box. On a comment whose replies were collapsed, Reply also expands them first. +- **Author avatar.** A comment by someone without an avatar showed a generic comment icon. Every comment and reply now leads with a 20 px avatar: the author's image, or their initials on the same round disc the people chips draw. +- **Mention menu.** Typing `@` opened the people menu at the top left of the comment box. It now opens under the caret, or above it when the window has no room below. +- **Delete.** Deleting a comment now shows a "Comment deleted" toast (zh: 评论已删除). A refused delete still shows its error, as before. + +Additions, nothing removed or changed in meaning: `@object-ui/plugin-detail` exports `CommentAuthorAvatar` (and its props type), and `ThreadedReplies` takes a new optional `focusReplyOnOpen` prop (default `false`, so a host that always shows the reply box keeps today's focus behaviour). `@object-ui/fields` exports `getPersonInitials`. New locale key `detail.commentDeleted` in all eleven locale packs. diff --git a/content/docs/frontend/plugins/plugin-detail.mdx b/content/docs/frontend/plugins/plugin-detail.mdx index 851175fdf7e..f9e160e2638 100644 --- a/content/docs/frontend/plugins/plugin-detail.mdx +++ b/content/docs/frontend/plugins/plugin-detail.mdx @@ -23,6 +23,7 @@ The Feed & Chatter system provides Airtable-style record-level collaboration. It | `FieldChangeItem` | Field change history display (old → new values) | | `ReactionPicker` | Emoji reaction selector | | `ThreadedReplies` | Collapsible reply threading | +| `CommentAuthorAvatar` | 20 px author avatar in front of a comment or reply: the image, or the person chips' initials disc | | `SubscriptionToggle` | Bell notification toggle | ## Usage @@ -569,11 +570,22 @@ decision as a defect is how a warning channel gets ignored: | `parentItem` | `FeedItem` | required | Parent comment item | | `replies` | `FeedItem[]` | required | Reply items | | `onAddReply` | `(parentId, text) => void` | — | Add reply callback | -| `showReplyInput` | `boolean` | `false` | Show reply input | +| `showReplyInput` | `boolean` | `true` | Show reply input | +| `focusReplyOnOpen` | `boolean` | `false` | Each time the input opens, expand the replies and put the caret in the input. Pass it when the input opens behind your own Reply button; leave it off when the input always shows, or every thread takes focus on mount | | `onEditComment` | `(itemId, text) => void \| Promise` | — | Edit on a reply whose `authoredByViewer` is `true` | | `onDeleteComment` | `(itemId) => void \| Promise` | — | Delete on the same replies | | `className` | `string` | `''` | Additional CSS classes | +### CommentAuthorAvatar + +| Property | Type | Default | Description | +|----------|------|---------|-------------| +| `name` | `string` | required | Author display name; the initials come from it (`getPersonInitials` of `@object-ui/fields`) | +| `avatarUrl` | `string` | — | Author image; without one, or when it fails to load, the initials disc shows | +| `className` | `string` | — | Additional CSS classes | + +`RecordActivityTimeline` draws it in front of every comment and every reply. In `RichTextCommentInput`, typing `@` opens the mention menu under the caret, or above it when the window has no room below. + ### SubscriptionToggle | Property | Type | Default | Description | diff --git a/ui/e2e/narrow-drawer-time-34614.spec.ts b/ui/e2e/narrow-drawer-time-34614.spec.ts index 39e89c3e0f9..409a850743d 100644 --- a/ui/e2e/narrow-drawer-time-34614.spec.ts +++ b/ui/e2e/narrow-drawer-time-34614.spec.ts @@ -70,7 +70,7 @@ const CLS = { metaDot: grab(META, /data-record-meta-when="">\s*\{user \? ·<\/span>/, ['text-muted-foreground/40']), metaTime: grab(META, /\s*
/, ['flex', 'gap-2']), - feedIcon: grab(FEED, /const STREAM_ICON_CELL =\s*'([^']+)'/, ['shrink-0', 'w-3.5']), + feedIcon: grab(FEED, /const COMMENT_AVATAR_CELL =\s*'([^']+)'/, ['shrink-0', 'w-5']), feedContent: grab(FEED, /\{\/\* Content[^*]*\*\/\}\s*
/, ['flex-1', 'min-w-0']), feedHeader: grab(FEED, /const STREAM_COMMENT_HEADER =\s*'([^']+)'/, ['flex', 'flex-wrap', 'items-center']), feedActor: grab(FEED, /\{item\.actor\}<\/span>\s*\{item\.source/, ['font-medium']), diff --git a/ui/packages/app-shell/src/views/RecordDetailView.authoredActivityThreading-12249.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.authoredActivityThreading-12249.test.tsx index 31ed34e2a5f..0e0c6b4c524 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.authoredActivityThreading-12249.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.authoredActivityThreading-12249.test.tsx @@ -288,9 +288,10 @@ describe('an authored record:activity with enableThreading shows a stored reply it('a read with a parent and one child shows the child under the parent, not as a row of its own', async () => { const { view } = await mount([PARENT, CHILD, LONE], { perms: answer(CREATE_ONLY) }); - const parentRow = rootRowOf(view, PARENT_BODY); + // Collapsed until asked. expect(view.queryByText(CHILD_BODY)).toBeNull(); - fireEvent.click(within(parentRow).getByRole('button', { name: /1 reply/ })); + // `rootRowOf` presses 「回复」, which expands the replies first (objectstack#36070). + const parentRow = rootRowOf(view, PARENT_BODY); expect(within(parentRow).getByText(CHILD_BODY)).toBeInTheDocument(); expect(replyToggles(view)).toHaveLength(1); }); @@ -321,7 +322,8 @@ describe('an authored record:activity with enableThreading offers the reply inpu expect(dataSource.create).toHaveBeenCalledTimes(1); expect(dataSource.create.mock.calls[0][0]).toBe(COMMENT); expect(dataSource.create.mock.calls[0][1]).toMatchObject({ thread_id: THREAD, parent_id: 'c-lone', body: NEW_REPLY }); - fireEvent.click(within(loneRow).getByRole('button', { name: /1 reply/ })); + // The reply opened behind 「回复」 expanded the thread (objectstack#36070). + expect(within(loneRow).getByRole('button', { name: /1 reply/ })).toBeInTheDocument(); expect(within(loneRow).getByText(NEW_REPLY)).toBeInTheDocument(); }); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.feedCommentEditDelete-12268.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.feedCommentEditDelete-12268.test.tsx index 78d4ce10043..7a85af9e9fe 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.feedCommentEditDelete-12268.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.feedCommentEditDelete-12268.test.tsx @@ -107,6 +107,7 @@ type Pack = { deleteCommentConfirm: string; commentEditFailed: string; commentDeleteFailed: string; + commentDeleted: string; edited: string; save: string; cancel: string; @@ -434,6 +435,7 @@ describe.each(['record:activity', 'record:discussion'])( await waitFor(() => expect(screen.queryByRole('alertdialog')).toBeNull()); expect(dataSource.delete).not.toHaveBeenCalled(); expect(view.getByText(ADA_BODY)).toBeInTheDocument(); + expect(toast.success).not.toHaveBeenCalledWith(EN.detail.commentDeleted); fireEvent.click(deleteIn(rowOf(view, ADA_BODY))!); dialog = await screen.findByRole('alertdialog'); @@ -446,6 +448,8 @@ describe.each(['record:activity', 'record:discussion'])( await waitFor(() => expect(view.queryByText(ADA_BODY)).toBeNull()); expect(view.getByText(GRACE_BODY)).toBeInTheDocument(); expect(toast.error).not.toHaveBeenCalled(); + // The delete says it went through (objectstack#36070). + expect(toast.success).toHaveBeenCalledWith(EN.detail.commentDeleted); }); it("deleting the author's comment keeps another member's reply to it on the page, at once and after the feed is read again", async () => { @@ -494,6 +498,7 @@ describe.each(['record:activity', 'record:discussion'])( }); await waitFor(() => expect(toast.error).toHaveBeenCalledWith(EN.detail.commentDeleteFailed)); expect(view.getByText(ADA_BODY)).toBeInTheDocument(); + expect(toast.success).not.toHaveBeenCalledWith(EN.detail.commentDeleted); }); }, ); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.replyCountOnRead-12144.test.tsx b/ui/packages/app-shell/src/views/RecordDetailView.replyCountOnRead-12144.test.tsx index df0d07fce6c..85085a79bed 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.replyCountOnRead-12144.test.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.replyCountOnRead-12144.test.tsx @@ -244,20 +244,23 @@ afterEach(() => { describe('a stored reply shows under its parent on the default record page (objectui#12144)', () => { it('a read with a parent and one child shows the child under the parent, not as a row of its own', async () => { const { view } = await mount([PARENT, CHILD]); - const parentRow = rootRowOf(view, PARENT_BODY); // Collapsed until asked: the reply is not on screen yet, and not as a root row either. expect(view.queryByText(CHILD_BODY)).toBeNull(); - const toggle = within(parentRow).getByRole('button', { name: /1 reply/ }); - fireEvent.click(toggle); + // `rootRowOf` presses 「回复」, which expands the replies first (objectstack#36070). + const parentRow = rootRowOf(view, PARENT_BODY); expect(within(parentRow).getByText(CHILD_BODY)).toBeInTheDocument(); expect(replyToggles(view)).toHaveLength(1); + // The count toggle still folds them away. + fireEvent.click(within(parentRow).getByRole('button', { name: /1 reply/ })); + expect(view.queryByText(CHILD_BODY)).toBeNull(); }); it('the count is the children in the read: two stored replies read as two', async () => { const second = { ...CHILD, id: 'c-child-2', body: 'Second stored reply', created_at: '2026-10-01T09:30:00.000Z' }; const { view } = await mount([PARENT, CHILD, second]); const parentRow = rootRowOf(view, PARENT_BODY); - fireEvent.click(within(parentRow).getByRole('button', { name: /2 replies/ })); + // Expanded by 「回复」 (objectstack#36070); the toggle reads the count. + expect(within(parentRow).getByRole('button', { name: /2 replies/ })).toBeInTheDocument(); expect(within(parentRow).getByText(CHILD_BODY)).toBeInTheDocument(); expect(within(parentRow).getByText('Second stored reply')).toBeInTheDocument(); }); @@ -288,7 +291,9 @@ describe('a comment read from the server offers the reply input where the caller expect(dataSource.create).toHaveBeenCalledTimes(1); expect(dataSource.create.mock.calls[0][0]).toBe(COMMENT); expect(dataSource.create.mock.calls[0][1]).toMatchObject({ thread_id: THREAD, parent_id: 'c-lone', body: NEW_REPLY }); - fireEvent.click(within(loneRow).getByRole('button', { name: /1 reply/ })); + // The reply opened behind 「回复」 expanded the thread (objectstack#36070), so + // the new reply shows at once under its count. + expect(within(loneRow).getByRole('button', { name: /1 reply/ })).toBeInTheDocument(); expect(within(loneRow).getByText(NEW_REPLY)).toBeInTheDocument(); }); diff --git a/ui/packages/app-shell/src/views/RecordDetailView.tsx b/ui/packages/app-shell/src/views/RecordDetailView.tsx index 983b57378d3..0fbd83c6947 100644 --- a/ui/packages/app-shell/src/views/RecordDetailView.tsx +++ b/ui/packages/app-shell/src/views/RecordDetailView.tsx @@ -3978,8 +3978,8 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri * It asks first, through the console's ordinary destructive-action confirm: * this page's own `confirmHandler`, the `ActionConfirmDialog` the record's * Delete opens, painted destructive. A cancel settles `false` and nothing is - * sent. The row leaves the panel only once the server has deleted it; a - * refused delete raises a localized error and leaves the row where it was. + * sent. The row leaves the panel only once the server has deleted it, with a + * "Comment deleted" toast (objectstack#36070); a refused delete raises a localized error and leaves the row where it was. * A deleted reply takes one off its parent's `replyCount`, the count * `handleAddReply` adds one to. */ @@ -4023,6 +4023,9 @@ export function RecordDetailView({ dataSource, objects, onEdit, objectNameOverri : item, ), })); + // The row is gone; say so, so the reader knows the delete went through + // and the comment did not just scroll away (objectstack#36070). + toast.success(t('detail.commentDeleted', { defaultValue: 'Comment deleted' })); }, [dataSource, feedRecordKey, feedItemsByRecord, confirmHandler, t], ); diff --git a/ui/packages/fields/src/index.tsx b/ui/packages/fields/src/index.tsx index cdfa6fe9562..7657a2af6ec 100644 --- a/ui/packages/fields/src/index.tsx +++ b/ui/packages/fields/src/index.tsx @@ -5398,6 +5398,10 @@ export * from './widgets/BooleanField.js'; // highlights chip). `BooleanValueText` stays internal: its only caller is the // lookup column renderer in this package. export { useBooleanValueLabel, type BooleanValueLabel } from './widgets/booleanValueLabel.js'; +// objectstack#36070 — the up-to-two-character initials a person chip draws +// when it has no avatar image (PersonRow, the people-field chips). Exported so +// `@object-ui/plugin-detail`'s comment author avatar draws the same initials. +export { getPersonInitials } from './widgets/personDisplay.js'; export * from './widgets/SelectField.js'; export * from './widgets/DateField.js'; export * from './widgets/DateTimeField.js'; diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 56b6567f5cb..531886ab246 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -1688,6 +1688,7 @@ const ar = { deleteCommentConfirm: "هل أنت متأكد أنك تريد حذف هذا التعليق؟", commentEditFailed: "لم يُحفظ تعديلك. يحتفظ التعليق بنصه السابق.", commentDeleteFailed: "لم يُحذف التعليق. يُرجى المحاولة مرة أخرى.", + commentDeleted: "تم حذف التعليق", mentionsWithheld: "لن يُرسَل إشعار بهذا التعليق إلى {{names}}.", linkCopyFailed: "فشل نسخ الرابط", claim: "استلام", diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index c347cc22840..59a78f59b53 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -1510,6 +1510,7 @@ const de = { deleteCommentConfirm: "Möchten Sie diesen Kommentar wirklich löschen?", commentEditFailed: "Ihre Änderung wurde nicht gespeichert. Der Kommentar behält seinen bisherigen Text.", commentDeleteFailed: "Der Kommentar wurde nicht gelöscht. Bitte versuchen Sie es erneut.", + commentDeleted: "Kommentar gelöscht", mentionsWithheld: "Über diesen Kommentar wird keine Benachrichtigung an {{names}} gesendet.", linkCopyFailed: "Link konnte nicht kopiert werden", claim: "Übernehmen", diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index 20e3f55ac33..8769d1abc08 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -1659,6 +1659,7 @@ const en = { deleteCommentConfirm: 'Are you sure you want to delete this comment?', commentEditFailed: 'Your edit was not saved. The comment keeps its previous text.', commentDeleteFailed: 'The comment was not deleted. Please try again.', + commentDeleted: 'Comment deleted', // objectstack#28218 — a comment write whose answer names mentioned users the // server will not notify (`withheldMentions`): one sentence naming them, no reason. mentionsWithheld: '{{names}} will not be notified of this comment.', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 5a9c2d0003c..adaa93bbc4f 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -1556,6 +1556,7 @@ const es = { deleteCommentConfirm: "¿Está seguro de que desea eliminar este comentario?", commentEditFailed: "Tu edición no se ha guardado. El comentario conserva su texto anterior.", commentDeleteFailed: "El comentario no se ha eliminado. Inténtalo de nuevo.", + commentDeleted: "Comentario eliminado", mentionsWithheld: "No se enviará ninguna notificación de este comentario a {{names}}.", linkCopyFailed: "No se pudo copiar el enlace", claim: "Reclamar", diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index efaebb7ac85..60cbdc345af 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -1553,6 +1553,7 @@ const fr = { deleteCommentConfirm: "Êtes-vous sûr de vouloir supprimer ce commentaire ?", commentEditFailed: "Votre modification n'a pas été enregistrée. Le commentaire conserve son texte précédent.", commentDeleteFailed: "Le commentaire n'a pas été supprimé. Veuillez réessayer.", + commentDeleted: "Commentaire supprimé", mentionsWithheld: "Aucune notification de ce commentaire ne sera envoyée à {{names}}.", linkCopyFailed: "Impossible de copier le lien", claim: "Prendre en charge", diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 38dcdc76b67..43db270016c 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -1591,6 +1591,7 @@ const ja = { deleteCommentConfirm: "このコメントを削除してもよろしいですか?", commentEditFailed: "編集内容は保存されませんでした。コメントは以前の内容のままです。", commentDeleteFailed: "コメントは削除されませんでした。もう一度お試しください。", + commentDeleted: "コメントを削除しました", mentionsWithheld: "{{names}} にはこのコメントの通知が届きません。", linkCopyFailed: "リンクのコピーに失敗しました", claim: "担当する", diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index b0102e0d9fd..94597468323 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -1510,6 +1510,7 @@ const ko = { deleteCommentConfirm: "이 댓글을 삭제하시겠습니까?", commentEditFailed: "수정 내용이 저장되지 않았습니다. 댓글은 이전 내용을 유지합니다.", commentDeleteFailed: "댓글이 삭제되지 않았습니다. 다시 시도해 주세요.", + commentDeleted: "댓글이 삭제되었습니다", mentionsWithheld: "{{names}}에게는 이 댓글의 알림이 전송되지 않습니다.", linkCopyFailed: "링크 복사 실패", claim: "담당하기", diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 652138d24cf..61d4c587f71 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -1553,6 +1553,7 @@ const pt = { deleteCommentConfirm: "Tem certeza de que deseja excluir este comentário?", commentEditFailed: "Sua edição não foi salva. O comentário mantém o texto anterior.", commentDeleteFailed: "O comentário não foi excluído. Tente novamente.", + commentDeleted: "Comentário excluído", mentionsWithheld: "Nenhuma notificação deste comentário será enviada para {{names}}.", linkCopyFailed: "Falha ao copiar o link", claim: "Assumir", diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index 39a945a76a0..9f61f1e50b8 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -1698,6 +1698,7 @@ const ru = { deleteCommentConfirm: "Вы уверены, что хотите удалить этот комментарий?", commentEditFailed: "Изменения не сохранены. Комментарий сохраняет прежний текст.", commentDeleteFailed: "Комментарий не удалён. Попробуйте ещё раз.", + commentDeleted: "Комментарий удалён", mentionsWithheld: "Уведомление об этом комментарии не будет отправлено: {{names}}.", linkCopyFailed: "Не удалось скопировать ссылку", claim: "Взять в работу", diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index a35f4da21ce..65b48424815 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -1377,6 +1377,7 @@ const zh = { deleteCommentConfirm: '确定要删除这条评论吗?', commentEditFailed: '您的修改未保存,评论保留原有内容。', commentDeleteFailed: '评论未删除,请重试。', + commentDeleted: '评论已删除', mentionsWithheld: '{{names}} 不会收到这条评论的通知。', linkCopyFailed: '复制链接失败', claim: '认领', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index b2cb363edd2..a82cba48a18 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -1377,6 +1377,7 @@ const zhHant = { deleteCommentConfirm: '確定要刪除這條評論嗎?', commentEditFailed: '您的修改未儲存,評論保留原有內容。', commentDeleteFailed: '評論未刪除,請重試。', + commentDeleted: '評論已刪除', mentionsWithheld: '{{names}} 不會收到這條評論的通知。', linkCopyFailed: '複製連結失敗', claim: '認領', diff --git a/ui/packages/plugin-detail/README.md b/ui/packages/plugin-detail/README.md index 2ab07af1183..92e56c10dc7 100644 --- a/ui/packages/plugin-detail/README.md +++ b/ui/packages/plugin-detail/README.md @@ -759,6 +759,17 @@ affordances (View, Edit, Delete) are not governed by this key. } ``` +### Comments: author avatar, reply focus, mention menu + +Every comment and reply in `RecordActivityTimeline` leads with +`CommentAuthorAvatar`: the author's 20 px image, or their initials on the round +disc the person chips draw (`getPersonInitials` from `@object-ui/fields`). +`ThreadedReplies` takes `focusReplyOnOpen`: each time its reply input opens it +expands the replies and puts the caret in the input, so a host whose input opens +behind its own Reply button lets the reader type straight away. In +`RichTextCommentInput`, the `@` mention menu opens under the caret, or above it +when the window has no room below. + ### InlineEditSaveBar & InlineFieldInput The record-level inline-edit session (#2407): double-clicking a field (or its diff --git a/ui/packages/plugin-detail/src/CommentAuthorAvatar.tsx b/ui/packages/plugin-detail/src/CommentAuthorAvatar.tsx new file mode 100644 index 00000000000..d2708b583fe --- /dev/null +++ b/ui/packages/plugin-detail/src/CommentAuthorAvatar.tsx @@ -0,0 +1,35 @@ +/** + * ObjectUI + * Copyright (c) 2024-present ObjectStack Inc. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +import * as React from 'react'; +import { Avatar, AvatarFallback, AvatarImage, cn } from '@object-ui/components'; +import { getPersonInitials } from '@object-ui/fields'; + +export interface CommentAuthorAvatarProps { + /** The author's display name: the initials are read from it. */ + name: string; + /** The author's avatar image, when they set one. */ + avatarUrl?: string; + className?: string; +} + +/** + * The 20 px author avatar in front of a comment and of each reply + * (objectstack#36070): the author's image, or their initials on the round + * disc every other person chip draws (the people-field chips, PersonRow) — + * the same `Avatar` / `AvatarFallback` pair and the same `getPersonInitials`. + * An image that fails to load falls back to the initials, as those chips do. + */ +export const CommentAuthorAvatar: React.FC = ({ name, avatarUrl, className }) => ( + + {avatarUrl && } + + {getPersonInitials(name)} + + +); diff --git a/ui/packages/plugin-detail/src/RecordActivityTimeline.tsx b/ui/packages/plugin-detail/src/RecordActivityTimeline.tsx index 7ff06177ccf..900fc59b303 100644 --- a/ui/packages/plugin-detail/src/RecordActivityTimeline.tsx +++ b/ui/packages/plugin-detail/src/RecordActivityTimeline.tsx @@ -40,6 +40,7 @@ import { CommentBody } from './CommentAuthorControls'; import { useDisplayLocale } from '@object-ui/i18n'; import { useRecordContext, useSafeFieldLabel } from '@object-ui/react'; import { useDetailTranslation } from './useDetailTranslation'; +import { CommentAuthorAvatar } from './CommentAuthorAvatar'; import { foldFeedItems, readerRecordNameOf, @@ -192,8 +193,8 @@ export interface RecordActivityTimelineProps { } /** The stream chips' copy (objectstack#27055): 全部 / 活动 / 讨论 / 变更. */ -/** A comment's icon cell: the row's 14 px icon, centred on its first line. */ -const STREAM_ICON_CELL = 'shrink-0 flex h-[30px] w-3.5 items-center justify-center text-muted-foreground'; +/** A comment's avatar cell: the author's 20 px avatar, centred on its first line. */ +const COMMENT_AVATAR_CELL = 'shrink-0 flex h-[30px] w-5 items-center justify-center'; /** A comment's header line: who, then when, 30 px tall, wrapping between pieces. */ const STREAM_COMMENT_HEADER = 'flex min-h-[30px] flex-wrap items-center gap-x-2 text-[13px]'; /** @@ -859,19 +860,16 @@ export const RecordActivityTimeline: React.FC = ({ ? (emoji: string) => onToggleReaction(item.id, emoji) : undefined; - // A comment is the row with what they wrote under it: a small icon, who + // A comment is the row with what they wrote under it: the author avatar, who // and when on one 30 px line, the comment, and the row's actions (react, // reply, the author's edit and delete) revealed on hover or focus. return (
- {/* Icon */} -
- {item.actorAvatarUrl ? ( - {item.actor} - ) : ( - - )} + {/* The author's 20 px avatar, or their initials (objectstack#36070), + centred on the 30 px header line. */} +
+
{/* Content: 13 px on a 20 px line, so the comment is one line under the row */}
@@ -962,6 +960,7 @@ export const RecordActivityTimeline: React.FC = ({ replies={replies} onAddReply={onAddReply} showReplyInput={replyOpen} + focusReplyOnOpen onEditComment={onEditComment} onDeleteComment={onDeleteComment} /> diff --git a/ui/packages/plugin-detail/src/RichTextCommentInput.tsx b/ui/packages/plugin-detail/src/RichTextCommentInput.tsx index c1495fed33e..f44ab8bc5a6 100644 --- a/ui/packages/plugin-detail/src/RichTextCommentInput.tsx +++ b/ui/packages/plugin-detail/src/RichTextCommentInput.tsx @@ -20,6 +20,7 @@ import { } from 'lucide-react'; import { useDetailTranslation } from './useDetailTranslation'; import { extractMentions } from './extractMentions'; +import { getTextareaCaretCoordinates } from './textareaCaret'; export interface MentionSuggestion { id: string; @@ -56,6 +57,21 @@ export interface RichTextCommentInputProps { compact?: boolean; } +/** The mention menu's width (`w-56`) and its tallest height (`max-h-40`), in px. */ +const MENTION_MENU_WIDTH = 224; +const MENTION_MENU_MAX_HEIGHT = 160; +/** The gap between the caret's line and the mention menu, in px. */ +const MENTION_MENU_GAP = 4; + +/** + * Where the mention menu opens, relative to the editor box (objectstack#36070): + * under the caret's line, or above it when the space under it in the window + * is too short for the menu and the space above is longer. + */ +type MentionMenuPlacement = + | { side: 'below'; top: number; left: number } + | { side: 'above'; bottom: number; left: number }; + /** The look of a picked mention, in the preview and in the composer's chip row. */ const MENTION_CHIP_CLASS = 'inline-flex items-center rounded-full bg-primary/10 px-1.5 text-primary font-medium'; @@ -130,6 +146,8 @@ export const RichTextCommentInput: React.FC = ({ const [mentionQuery, setMentionQuery] = React.useState(''); const [mentionIndex, setMentionIndex] = React.useState(0); const textareaRef = React.useRef(null); + const editorBoxRef = React.useRef(null); + const [mentionPlacement, setMentionPlacement] = React.useState(null); React.useEffect(() => { if (autoFocus) textareaRef.current?.focus(); // On mount only: a later re-render must not pull focus back. @@ -155,6 +173,36 @@ export const RichTextCommentInput: React.FC = ({ ); }, [mentionQuery, mentionSuggestions]); + // The menu follows the caret: measured after each render that shows it, + // where the caret now is (the query typed after `@` moves it). Where layout + // cannot be measured the menu keeps its old place, over the editor's top left. + const mentionMenuShown = showMentions && filteredMentions.length > 0; + React.useLayoutEffect(() => { + // A closed menu keeps its last place unread; the next opening measures + // again before the browser paints it. + if (!mentionMenuShown) return; + const textarea = textareaRef.current; + const box = editorBoxRef.current; + if (!textarea || !box) return; + const caret = getTextareaCaretCoordinates(textarea, textarea.selectionStart); + if (!caret) return; + const lineTop = textarea.offsetTop + caret.top - textarea.scrollTop; + const lineBottom = lineTop + caret.height; + const left = Math.max( + 0, + Math.min(textarea.offsetLeft + caret.left - textarea.scrollLeft, box.clientWidth - MENTION_MENU_WIDTH), + ); + const boxTop = box.getBoundingClientRect().top; + const spaceBelow = window.innerHeight - (boxTop + lineBottom); + const spaceAbove = boxTop + lineTop; + const needed = MENTION_MENU_MAX_HEIGHT + MENTION_MENU_GAP; + setMentionPlacement( + spaceBelow < needed && spaceAbove > spaceBelow + ? { side: 'above', bottom: box.clientHeight - lineTop + MENTION_MENU_GAP, left } + : { side: 'below', top: lineBottom + MENTION_MENU_GAP, left }, + ); + }, [mentionMenuShown, value, mentionQuery]); + const insertAtCursor = React.useCallback( (before: string, after: string = '') => { const textarea = textareaRef.current; @@ -367,7 +415,7 @@ export const RichTextCommentInput: React.FC = ({
{/* Editor / Preview */} -
+
{isPreview ? (
= ({ )} {/* @mention dropdown */} - {showMentions && filteredMentions.length > 0 && ( -
+ {mentionMenuShown && ( +
{filteredMentions.map((suggestion, index) => (