diff --git a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx index d626d454f..26e80f2f2 100644 --- a/src/renderer/src/components/right-sidebar/ChecksPanel.tsx +++ b/src/renderer/src/components/right-sidebar/ChecksPanel.tsx @@ -37,6 +37,7 @@ import { ConflictingFilesSection, MergeConflictNotice, ChecksList, + isMutablePRConversationComment, PRCommentsList, PRTriageStrip } from './checks-panel-content' @@ -69,6 +70,7 @@ import type { } from '../../../../shared/hosted-review' import { getHostedReviewCacheKey, refreshHostedReviewCard } from '@/store/slices/hosted-review' import { toast } from 'sonner' +import { useConfirmationDialog } from '@/components/confirmation-dialog' import { classifyHostedReview, type HostedReviewClassificationOptions @@ -345,6 +347,7 @@ export default function ChecksPanel(): React.JSX.Element { const titleInputFocusTimerRef = useRef | null>(null) const pollIntervalRef = useRef(30_000) // start at 30s, backs off to 120s const mountedRef = useMountedRef() + const confirm = useConfirmationDialog() const prevChecksRef = useRef('') const conflictSummaryRefreshKeyRef = useRef(null) const asyncResultKeyRef = useRef('') @@ -1738,6 +1741,57 @@ export default function ChecksPanel(): React.JSX.Element { ] ) + const handleEditComment = useCallback( + async (comment: PRComment, body: string): Promise => { + if (!pr?.prRepo || !isMutablePRConversationComment(comment)) { + return false + } + const result = await window.api.gh.updateIssueCommentBySlug({ + owner: pr.prRepo.owner, + repo: pr.prRepo.repo, + commentId: comment.id, + body + }) + if (!result.ok) { + toast.error(result.error.message) + return false + } + setComments((prev) => + prev.map((entry) => (entry.id === comment.id ? { ...entry, body } : entry)) + ) + return true + }, + [pr?.prRepo] + ) + + const handleDeleteComment = useCallback( + async (comment: PRComment): Promise => { + if (!pr?.prRepo || !isMutablePRConversationComment(comment)) { + return + } + const confirmed = await confirm({ + title: 'Delete comment?', + description: 'This will permanently remove the comment from the PR.', + confirmLabel: 'Delete', + confirmVariant: 'destructive' + }) + if (!confirmed) { + return + } + const result = await window.api.gh.deleteIssueCommentBySlug({ + owner: pr.prRepo.owner, + repo: pr.prRepo.repo, + commentId: comment.id + }) + if (!result.ok) { + toast.error(result.error.message) + return + } + setComments((prev) => prev.filter((entry) => entry.id !== comment.id)) + }, + [pr?.prRepo, confirm] + ) + const handleReplyToComment = useCallback( async (comment: PRComment, body: string) => { if (!repo || !prNumber || !pr?.prRepo) { @@ -2616,6 +2670,8 @@ export default function ChecksPanel(): React.JSX.Element { onAddComment={pr ? handleAddPRComment : undefined} onReply={pr ? handleReplyToComment : undefined} onResolve={pr || activeGitLabReview ? handleResolve : undefined} + onEditComment={pr ? handleEditComment : undefined} + onDeleteComment={pr ? handleDeleteComment : undefined} /> ) diff --git a/src/renderer/src/components/right-sidebar/checks-panel-content.test.tsx b/src/renderer/src/components/right-sidebar/checks-panel-content.test.tsx index 95884ac1b..7b755ce9e 100644 --- a/src/renderer/src/components/right-sidebar/checks-panel-content.test.tsx +++ b/src/renderer/src/components/right-sidebar/checks-panel-content.test.tsx @@ -9,6 +9,7 @@ import { ConflictTriageStrip, getFailedChecksForDetails, MergeConflictNotice, + isMutablePRConversationComment, PRCommentsList, PRTriageStrip } from './checks-panel-content' @@ -159,6 +160,43 @@ describe('ChecksList', () => { }) }) +describe('isMutablePRConversationComment', () => { + it('allows top-level conversation comments but not review threads or summaries', () => { + expect( + isMutablePRConversationComment({ + id: 12, + author: 'alice', + authorAvatarUrl: '', + body: 'Looks good', + createdAt: '2026-05-14T00:00:00Z', + url: 'https://github.com/acme/widgets/pull/42#issuecomment-12' + }) + ).toBe(true) + expect( + isMutablePRConversationComment({ + id: 34, + author: 'alice', + authorAvatarUrl: '', + body: 'Inline note', + createdAt: '2026-05-14T00:00:00Z', + url: 'https://github.com/acme/widgets/pull/42#discussion_r34', + threadId: 'thread-1', + path: 'src/a.ts' + }) + ).toBe(false) + expect( + isMutablePRConversationComment({ + id: 99, + author: 'alice', + authorAvatarUrl: '', + body: 'LGTM', + createdAt: '2026-05-14T00:00:00Z', + url: 'https://github.com/acme/widgets/pull/42#pullrequestreview-99' + }) + ).toBe(false) + }) +}) + describe('PRCommentsList', () => { it('places the collapsed add-comment action in the comments header', () => { const comments: PRComment[] = [ @@ -188,6 +226,31 @@ describe('PRCommentsList', () => { expect(markup).not.toContain('Add a PR comment') }) + it('renders a more-actions menu on conversation comments', () => { + const comments: PRComment[] = [ + { + id: 1, + author: 'AmethystLiang', + authorAvatarUrl: '', + body: 'Existing review context', + createdAt: '2026-05-14T00:00:00Z', + url: 'https://github.com/acme/widgets/pull/42#issuecomment-1' + } + ] + + const markup = renderWithTooltips( + React.createElement(PRCommentsList, { + comments, + commentsLoading: false, + onEditComment: () => Promise.resolve(true), + onDeleteComment: () => {} + }) + ) + + expect(markup).toContain('aria-label="More comment actions"') + expect(markup).toContain('data-slot="dropdown-menu-trigger"') + }) + it('uses the header plus action as the empty comments state', () => { const markup = renderWithTooltips( React.createElement(PRCommentsList, { diff --git a/src/renderer/src/components/right-sidebar/checks-panel-content.tsx b/src/renderer/src/components/right-sidebar/checks-panel-content.tsx index 9190a383c..8544738df 100644 --- a/src/renderer/src/components/right-sidebar/checks-panel-content.tsx +++ b/src/renderer/src/components/right-sidebar/checks-panel-content.tsx @@ -17,7 +17,10 @@ import { ChevronRight, Sparkles, RefreshCw, - AlertTriangle + AlertTriangle, + MoreHorizontal, + Pencil, + Trash } from 'lucide-react' import { ExternalLink } from 'lucide-react' import { Button } from '@/components/ui/button' @@ -36,6 +39,13 @@ import { DialogTitle, DialogTrigger } from '@/components/ui/dialog' +import { + DropdownMenu, + DropdownMenuContent, + DropdownMenuItem, + DropdownMenuSeparator, + DropdownMenuTrigger +} from '@/components/ui/dropdown-menu' import { cn } from '@/lib/utils' import CommentMarkdown from '@/components/sidebar/CommentMarkdown' import { @@ -1229,6 +1239,76 @@ function formatLineRange(comment: PRComment): string | null { return `L${comment.line}` } +/** True for top-level PR conversation comments the viewer can edit or delete. */ +export function isMutablePRConversationComment(comment: PRComment): boolean { + if (comment.threadId || comment.path) { + return false + } + if (comment.url && comment.url.includes('pullrequestreview')) { + return false + } + return Number.isSafeInteger(comment.id) && comment.id > 0 +} + +function CommentMoreMenu({ + comment, + onStartEdit, + onDelete +}: { + comment: PRComment + onStartEdit?: () => void + onDelete?: () => void | Promise +}): React.JSX.Element | null { + const hasGoToComment = Boolean(comment.url) + const hasEdit = Boolean(onStartEdit) + const hasDelete = Boolean(onDelete) + if (!hasGoToComment && !hasEdit && !hasDelete) { + return null + } + + return ( + + + + + + {hasGoToComment && ( + window.api.shell.openUrl(comment.url)}> + + Go to comment + + )} + {hasGoToComment && (hasEdit || hasDelete) ? : null} + {hasEdit ? ( + { + event.preventDefault() + onStartEdit?.() + }} + > + + Edit + + ) : null} + {hasDelete ? ( + void onDelete?.()}> + + Delete + + ) : null} + + + ) +} + /** Build copy text that includes file location context for review comments. */ function buildCopyText(comment: PRComment): string { if (!comment.path) { @@ -1248,7 +1328,9 @@ function CommentRow({ replyDisabled, replyDisabledReason, onResolve, - onReply + onReply, + onEditComment, + onDeleteComment }: { comment: PRComment isReply: boolean @@ -1258,20 +1340,70 @@ function CommentRow({ replyDisabledReason?: string onResolve?: (threadId: string, resolve: boolean) => boolean | Promise onReply?: (comment: PRComment) => void + onEditComment?: (comment: PRComment, body: string) => Promise + onDeleteComment?: (comment: PRComment) => void | Promise }): React.JSX.Element { const automated = isBotPRComment(comment) + const canMutateComment = isMutablePRConversationComment(comment) + const [editing, setEditing] = useState(false) + const [draft, setDraft] = useState(comment.body) + const [submittingEdit, setSubmittingEdit] = useState(false) + + useEffect(() => { + if (!editing) { + setDraft(comment.body) + } + }, [comment.body, editing]) + + const handleStartEdit = useCallback((): void => { + setDraft(comment.body) + setEditing(true) + }, [comment.body]) + + const handleCancelEdit = useCallback( + (event: React.MouseEvent): void => { + event.stopPropagation() + setEditing(false) + setDraft(comment.body) + }, + [comment.body] + ) + + const handleSaveEdit = useCallback( + async (event: React.MouseEvent): Promise => { + event.stopPropagation() + const trimmedDraft = draft.trim() + if (!onEditComment || !trimmedDraft || trimmedDraft === comment.body) { + setEditing(false) + return + } + setSubmittingEdit(true) + try { + const ok = await onEditComment(comment, trimmedDraft) + if (ok) { + setEditing(false) + } + } finally { + setSubmittingEdit(false) + } + }, + [comment, draft, onEditComment] + ) + + const handleDelete = useCallback((): void => { + void onDeleteComment?.(comment) + }, [comment, onDeleteComment]) + + const trimmedDraft = draft.trim() + const canSaveEdit = !submittingEdit && trimmedDraft.length > 0 && trimmedDraft !== comment.body + return (
{ - if (comment.url) { - window.api.shell.openUrl(comment.url) - } - }} >
{/* Author line: avatar + name + file badge aligned on center */} @@ -1307,38 +1439,76 @@ function CommentRow({ )}
-
- {showResolve && comment.threadId != null && onResolve && ( - + {showResolve && comment.threadId != null && onResolve && ( + + )} + {showReply && onReply && ( + + )} + + - )} - {showReply && onReply && ( - - )} - -
-
- )} - /> +
+ {editing ? ( +
+