Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.
Go
MUL-7528 feat(issues): copy link to a single comment (#8607)
gogodjzhub02beb43a131
diff --git a/packages/views/issues/actions/__tests__/use-issue-actions.test.tsx b/packages/views/issues/actions/__tests__/use-issue-actions.test.tsxindex 49c008fc1b..9fa4bb286a 100644--- a/packages/views/issues/actions/__tests__/use-issue-actions.test.tsx+++ b/packages/views/issues/actions/__tests__/use-issue-actions.test.tsx@@ -298,6 +298,18 @@ describe("useIssueActions", () => {);});+ it("copyCommentLink writes the issue's shareable URL anchored at the comment", async () => {+ const { result } = renderHook(() => useIssueActions(mockIssue), { wrapper });++ await act(async () => {+ await result.current.copyCommentLink("comment-7");+ });++ expect(navigator.clipboard.writeText).toHaveBeenCalledWith(+ "https://app.multica.com/test/issues/TES-1#comment-comment-7",+ );+ });+it("openSetParent / openAddChild / openDeleteConfirm / openCreateSubIssue open the correct modal with payload", () => {const { result } = renderHook(() => useIssueActions(mockIssue), { wrapper });diff --git a/packages/views/issues/actions/use-issue-actions.ts b/packages/views/issues/actions/use-issue-actions.tsindex dbd3df8066..3ee3cf9add 100644--- a/packages/views/issues/actions/use-issue-actions.ts+++ b/packages/views/issues/actions/use-issue-actions.ts@@ -28,6 +28,7 @@ export interface UseIssueActionsResult {openInNewTab: () => void;togglePin: () => void;copyLink: () => Promise<void>;+ copyCommentLink: (commentId: string) => Promise<void>;openCreateSubIssue: () => void;openSetParent: () => void;removeParent: () => void;@@ -168,6 +169,26 @@ export function useIssueActions(issue: Issue | null): UseIssueActionsResult {}}, [paths, issueId, issueIdentifier, navigation, t]);+ // Built during render so `copyCommentLink` depends on this string alone:+ // `paths` is rebuilt on every render, and the handler is passed to every+ // memoized comment card, so depending on it would re-render all of them on+ // any unrelated page update. Identifier form for the same reason as `copyLink`.+ const issueShareUrl = issueId+ ? navigation.getShareableUrl(paths.issueDetail(issueIdentifier || issueId))+ : null;+ const copyCommentLink = useCallback(async (commentId: string) => {+ if (!issueShareUrl) return;+ // The `#comment-…` fragment is the deep-link anchor `IssueDetailRoute`+ // resolves via `parseCommentHighlightHash`; dropping it would downgrade the+ // link to the whole issue.+ const url = `${issueShareUrl}#comment-${commentId}`;+ if (await copyText(url)) {+ toast.success(t(($) => $.comment.link_copied));+ } else {+ toast.error(t(($) => $.comment.link_copy_failed));+ }+ }, [issueShareUrl, t]);+const openCreateSubIssue = useCallback(() => {if (!issueId) return;openModal("create-issue", {@@ -266,6 +287,7 @@ export function useIssueActions(issue: Issue | null): UseIssueActionsResult {openInNewTab,togglePin,copyLink,+ copyCommentLink,openCreateSubIssue,openSetParent,removeParent,diff --git a/packages/views/issues/components/comment-card-copy-link.test.tsx b/packages/views/issues/components/comment-card-copy-link.test.tsxnew file mode 100644index 0000000000..f0c9337faf--- /dev/null+++ b/packages/views/issues/components/comment-card-copy-link.test.tsx@@ -0,0 +1,128 @@+import { describe, expect, it, vi } from "vitest";+import { fireEvent, screen } from "@testing-library/react";+import { forwardRef, type ReactNode } from "react";+import { QueryClient, QueryClientProvider } from "@tanstack/react-query";+import type { TimelineEntry } from "@multica/core/types";+import { renderWithI18n } from "../../test/i18n";++// Per-comment copy link: the menu must offer a link to the single comment+// (`#comment-<id>`), not just the comment body text. The URL is built by+// `useIssueActions.copyCommentLink`; this suite pins that the card routes each+// row's own id to the handler and hides the item when no handler is wired.++vi.mock("@multica/core/api", () => ({+ api: { uploadFile: vi.fn() },+ dispatchReasonCode: () => undefined,+ errorCode: () => undefined,+}));++vi.mock("../../navigation", () => ({+ useNavigation: () => ({+ push: vi.fn(),+ pathname: "/acme/issues",+ getShareableUrl: (p: string) => `https://app.example${p}`,+ }),+}));++vi.mock("@multica/core/workspace/hooks", () => ({+ useActorName: () => ({ getActorName: () => "Ada" }),+}));++vi.mock("../../common/actor-avatar", () => ({+ ActorAvatar: () => null,+}));++vi.mock("../hooks/use-comment-trigger-preview", () => ({+ useCommentTriggerPreview: () => ({ agents: [], blocked: [] }),+}));++vi.mock("../../editor", async () => ({+ ...(await vi.importActual<typeof import("../../editor/use-upload-gate")>("../../editor/use-upload-gate")),+ ...(await vi.importActual<typeof import("../../editor/use-lazy-editor")>("../../editor/use-lazy-editor")),+ ...(await vi.importActual<typeof import("../../editor/use-composer-submit")>("../../editor/use-composer-submit")),+ useEditorUpload: () => ({ uploadWithToast: vi.fn(), upload: vi.fn(), uploading: false }),+ useFileDropZone: () => ({ isDragOver: false, dropZoneProps: {} }),+ FileDropOverlay: () => null,+ ReadonlyContent: ({ content }: { content: string }) => <div>{content}</div>,+ Attachment: () => null,+ AttachmentDownloadProvider: ({ children }: { children: ReactNode }) => <>{children}</>,+ ContentEditor: forwardRef(function MockContentEditor() {+ return <textarea data-testid="editor" />;+ }),+}));++import { CommentCard } from "./comment-card";++function comment(id: string, parentId: string | null): TimelineEntry {+ return {+ type: "comment",+ id,+ actor_type: "member",+ actor_id: "user-1",+ content: `body ${id}`,+ parent_id: parentId,+ comment_type: "comment",+ reactions: [],+ attachments: [],+ created_at: "2026-09-11T07:00:00Z",+ updated_at: "2026-09-11T07:00:00Z",+ revision: 1,+ };+}++function renderThread(+ root: TimelineEntry,+ replies: TimelineEntry[],+ onCopyLink?: (commentId: string) => void,+) {+ const qc = new QueryClient({ defaultOptions: { queries: { retry: false } } });+ return renderWithI18n(+ <QueryClientProvider client={qc}>+ <CommentCard+ issueId="issue-1"+ entry={root}+ replies={replies}+ currentUserId="user-1"+ onReply={vi.fn().mockResolvedValue(true)}+ onEdit={vi.fn().mockResolvedValue(undefined)}+ onDelete={vi.fn()}+ onToggleReaction={vi.fn()}+ onCopyLink={onCopyLink}+ />+ </QueryClientProvider>,+ );+}++const actionMenus = () => screen.queryAllByRole("button", { name: "Comment actions" });++describe("CommentCard — copy comment link", () => {+ it("copies the root comment's own deep link", async () => {+ const onCopyLink = vi.fn();+ renderThread(comment("root", null), [], onCopyLink);++ fireEvent.click(actionMenus()[0]!);+ fireEvent.click(await screen.findByText("Copy link"));++ expect(onCopyLink).toHaveBeenCalledWith("root");+ });++ it("copies a reply's own deep link, not the thread root's", async () => {+ const onCopyLink = vi.fn();+ renderThread(comment("root", null), [comment("reply", "root")], onCopyLink);++ // Menus render in order: root first, then the reply.+ fireEvent.click(actionMenus()[1]!);+ fireEvent.click(await screen.findByText("Copy link"));++ expect(onCopyLink).toHaveBeenCalledWith("reply");+ });++ it("omits the item when no handler is wired", async () => {+ renderThread(comment("root", null), []);++ fireEvent.click(actionMenus()[0]!);++ await screen.findByText("Copy");+ expect(screen.queryByText("Copy link")).toBeNull();+ });+});\ No newline at end of filediff --git a/packages/views/issues/components/comment-card.tsx b/packages/views/issues/components/comment-card.tsxindex f647e029cc..edcb3f8410 100644--- a/packages/views/issues/components/comment-card.tsx+++ b/packages/views/issues/components/comment-card.tsx@@ -1,7 +1,7 @@"use client";import { Fragment, memo, useCallback, useEffect, useRef, useState, type ReactNode } from "react";-import { CheckCircle2, ChevronRight, ListChevronsDownUp, Copy, Loader2, MessageSquarePlus, MoreHorizontal, Pencil, RotateCcw, Trash2 } from "lucide-react";+import { CheckCircle2, ChevronRight, ListChevronsDownUp, Copy, Link2, Loader2, MessageSquarePlus, MoreHorizontal, Pencil, RotateCcw, Trash2 } from "lucide-react";import { toast } from "sonner";import { Card } from "@multica/ui/components/ui/card";import { Button, buttonVariants } from "@multica/ui/components/ui/button";@@ -149,6 +149,8 @@ interface CommentCardProps {onCreateSubIssue?: (commentId: string) => void;/** Resolve/unresolve any comment in this thread (commentId = the target row). */onResolveToggle?: (commentId: string, resolved: boolean) => void;+ /** Copy a deep link (`#comment-…`) to a single comment in this thread. */+ onCopyLink?: (commentId: string) => void;/*** When non-null, the thread root is currently rendered as a resolved-but-* expanded card. Pass a "Collapse" affordance into the header so the user@@ -639,6 +641,7 @@ function CommentRow({onToggleReaction,onCreateSubIssue,onResolveToggle,+ onCopyLink,}: {runHeader?: ReactNode;runMetadata?: ReactNode;@@ -657,6 +660,7 @@ function CommentRow({onToggleReaction: (commentId: string, emoji: string) => void;onCreateSubIssue?: (commentId: string) => void;onResolveToggle?: (commentId: string, resolved: boolean) => void;+ onCopyLink?: (commentId: string) => void;}) {const { t } = useT("issues");const locale = useLocale();@@ -753,6 +757,12 @@ function CommentRow({<Copy className="h-3.5 w-3.5" />{t(($) => $.comment.copy_action)}</DropdownMenuItem>+ {onCopyLink && (+ <DropdownMenuItem onClick={() => onCopyLink(entry.id)}>+ <Link2 className="h-3.5 w-3.5" />+ {t(($) => $.comment.copy_link_action)}+ </DropdownMenuItem>+ )}{onCreateSubIssue && entry.comment_type === "comment" && (<DropdownMenuItem onClick={() => onCreateSubIssue(entry.id)}><MessageSquarePlus className="h-3.5 w-3.5" aria-hidden />@@ -979,6 +989,7 @@ function CommentCardImpl({onToggleReaction,onCreateSubIssue,onResolveToggle,+ onCopyLink,onCollapseResolved,expandedResolvedIds,onResolvedExpandChange,@@ -1034,7 +1045,7 @@ function CommentCardImpl({const reply = run.hasReply ? allNestedReplies.find((entry) => entry.id === run.commentId) : undefined;return <Fragment key={run.task.id}><AgentRunComment run={run} entering={enteringRunIds?.has(run.task.id)} commentProps={reply ? {issueId, entry: reply, replies: [], currentUserId, canModerate, onReply, onEdit, onDelete,- onToggleReaction, onCreateSubIssue, onResolveToggle, highlightedCommentId, enteringRunIds,+ onToggleReaction, onCreateSubIssue, onResolveToggle, onCopyLink, highlightedCommentId, enteringRunIds,} : undefined} />{reply && reply.id !== commentId && renderAnchoredRuns(reply.id)}</Fragment>;});@@ -1196,6 +1207,12 @@ function CommentCardImpl({<Copy className="h-3.5 w-3.5" />{t(($) => $.comment.copy_action)}</DropdownMenuItem>+ {onCopyLink && (+ <DropdownMenuItem onClick={() => onCopyLink(entry.id)}>+ <Link2 className="h-3.5 w-3.5" />+ {t(($) => $.comment.copy_link_action)}+ </DropdownMenuItem>+ )}{onCreateSubIssue && entry.comment_type === "comment" && (<DropdownMenuItem onClick={() => onCreateSubIssue(entry.id)}><MessageSquarePlus className="h-3.5 w-3.5" aria-hidden />@@ -1407,6 +1424,7 @@ function CommentCardImpl({onToggleReaction={onToggleReaction}onCreateSubIssue={onCreateSubIssue}onResolveToggle={onResolveToggle}+ onCopyLink={onCopyLink}/></div>{renderAnchoredRuns(resolutionReply.id)}@@ -1455,6 +1473,7 @@ function CommentCardImpl({onToggleReaction={onToggleReaction}onCreateSubIssue={onCreateSubIssue}onResolveToggle={onResolveToggle}+ onCopyLink={onCopyLink}/></div>)}diff --git a/packages/views/issues/components/issue-detail.test.tsx b/packages/views/issues/components/issue-detail.test.tsxindex 4537cd3e30..28297f2d62 100644--- a/packages/views/issues/components/issue-detail.test.tsx+++ b/packages/views/issues/components/issue-detail.test.tsx@@ -22,6 +22,9 @@ const mockViewport = vi.hoisted(() => ({ isMobile: false }));// Counts MockContentEditor mounts. This pins the description to exactly one// eager editor per issue and catches stale editor reuse across issue switches.const contentEditorMounts = vi.hoisted(() => ({ count: 0 }));+// Every ReadonlyContent render, by content. A comment card renders its body+// through it, so this counts card renders without reaching into the card.+const readonlyContentRenders = vi.hoisted(() => [] as string[]);const descriptionSelectionAction = vi.hoisted(() => ({ current: undefined as { label: string; onSelect: () => void } | undefined }));// Stable empty-attachments reference: the real store returns a shared constant// so the `useCommentDraftStore(s => s.getAttachments(key))` selector keeps a@@ -167,9 +170,10 @@ vi.mock("../../editor", async () => ({ImageSequenceProvider: ({ children }: { children: React.ReactNode }) =>children,isPreviewable: () => false,- ReadonlyContent: ({ content }: { content: string }) => (- <div data-testid="readonly-content">{content}</div>- ),+ ReadonlyContent: ({ content }: { content: string }) => {+ readonlyContentRenders.push(content);+ return <div data-testid="readonly-content">{content}</div>;+ },ContentEditor: forwardRef(function MockContentEditor({defaultValue,@@ -676,6 +680,7 @@ describe("IssueDetail (shared)", () => {beforeEach(() => {vi.clearAllMocks();contentEditorMounts.count = 0;+ readonlyContentRenders.length = 0;descriptionSelectionAction.current = undefined;mockViewport.isMobile = false;// Default: issue loads successfully@@ -1545,6 +1550,24 @@ describe("IssueDetail (shared)", () => {expect(screen.getByText("I can help with this")).toBeInTheDocument();});+ // Comment cards are memoized so page state that has nothing to do with the+ // timeline does not re-render every comment on a long issue. Any handler the+ // page hands to the cards must keep its identity across such renders.+ it("does not re-render comment cards when unrelated page state changes", async () => {+ renderIssueDetail();+ await screen.findByText("I can help with this");+ await screen.findByText("Details");++ const commentBodies = new Set(mockTimeline.map((entry) => entry.content));+ const cardRenders = () =>+ readonlyContentRenders.filter((content) => commentBodies.has(content)).length;+ const before = cardRenders();++ fireEvent.click(screen.getByText("Details"));++ expect(cardRenders()).toBe(before);+ });+it("prefers timeline identity when the actor is absent from the member directory", async () => {mockApiObj.listTimeline.mockResolvedValue([{diff --git a/packages/views/issues/components/issue-detail.tsx b/packages/views/issues/components/issue-detail.tsxindex c47f9519d7..1802d033cc 100644--- a/packages/views/issues/components/issue-detail.tsx+++ b/packages/views/issues/components/issue-detail.tsx@@ -2661,6 +2661,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tronReplyAccepted: scrollToTimelineBottom, onEdit: editComment, onDelete: deleteComment,onToggleReaction: handleToggleReaction, onCreateSubIssue: openCommentSubIssue,onResolveToggle: handleResolveToggle,+ onCopyLink: actions.copyCommentLink,onCollapseResolved: reply.resolved_at ? () => toggleResolvedExpand(reply.id, false) : undefined,expandedResolvedIds: expandedResolved, onResolvedExpandChange: toggleResolvedExpand,highlightedCommentId: highlightedId,@@ -2698,6 +2699,7 @@ export function IssueDetail({ issueId, onDelete, onDone, defaultSidebarOpen = tronToggleReaction={handleToggleReaction}onCreateSubIssue={openCommentSubIssue}onResolveToggle={handleResolveToggle}+ onCopyLink={actions.copyCommentLink}onCollapseResolved={isResolved ? () => toggleResolvedExpand(item.id, false) : undefined}expandedResolvedIds={expandedResolved}onResolvedExpandChange={toggleResolvedExpand}diff --git a/packages/views/locales/en/issues.json b/packages/views/locales/en/issues.jsonindex a150471b1a..5cf63f2a30 100644--- a/packages/views/locales/en/issues.json+++ b/packages/views/locales/en/issues.json@@ -510,6 +510,9 @@"save_action": "Save","cancel_edit": "Cancel","copy_action": "Copy",+ "copy_link_action": "Copy link",+ "link_copied": "Link copied",+ "link_copy_failed": "Failed to copy link","copied_toast": "Copied","more_actions": "Comment actions","edit_action": "Edit",diff --git a/packages/views/locales/fr/issues.json b/packages/views/locales/fr/issues.jsonindex c7a740b184..dc8f6c0af8 100644--- a/packages/views/locales/fr/issues.json+++ b/packages/views/locales/fr/issues.json@@ -510,6 +510,9 @@"save_action": "Enregistrer","cancel_edit": "Annuler","copy_action": "Copier",+ "copy_link_action": "Copier le lien",+ "link_copied": "Lien copié",+ "link_copy_failed": "Échec de la copie du lien","copied_toast": "Copié","more_actions": "Actions du commentaire","edit_action": "Modifier",diff --git a/packages/views/locales/ja/issues.json b/packages/views/locales/ja/issues.jsonindex 145e71095d..86a370c9dd 100644--- a/packages/views/locales/ja/issues.json+++ b/packages/views/locales/ja/issues.json@@ -501,6 +501,9 @@"save_action": "保存","cancel_edit": "キャンセル","copy_action": "コピー",+ "copy_link_action": "リンクをコピー",+ "link_copied": "リンクをコピーしました",+ "link_copy_failed": "リンクをコピーできませんでした","copied_toast": "コピーしました","more_actions": "コメントの操作","edit_action": "編集",diff --git a/packages/views/locales/ko/issues.json b/packages/views/locales/ko/issues.jsonindex 93107faf05..5e7bb4d8a3 100644--- a/packages/views/locales/ko/issues.json+++ b/packages/views/locales/ko/issues.json@@ -501,6 +501,9 @@"save_action": "저장","cancel_edit": "취소","copy_action": "복사",+ "copy_link_action": "링크 복사",+ "link_copied": "링크를 복사했습니다",+ "link_copy_failed": "링크를 복사하지 못했습니다","copied_toast": "복사했습니다","more_actions": "댓글 작업","edit_action": "수정",diff --git a/packages/views/locales/zh-Hans/issues.json b/packages/views/locales/zh-Hans/issues.jsonindex 1b0963e94e..a717b2b6dc 100644--- a/packages/views/locales/zh-Hans/issues.json+++ b/packages/views/locales/zh-Hans/issues.json@@ -501,6 +501,9 @@"save_action": "保存","cancel_edit": "取消","copy_action": "复制",+ "copy_link_action": "复制链接",+ "link_copied": "链接已复制",+ "link_copy_failed": "复制链接失败","copied_toast": "已复制","more_actions": "评论操作","edit_action": "编辑",