Skip to content

Commit 74bc5d7

Browse files
committed
fix(web): nest review thread replies in the pull request comments list
The Summary tab's comment list was flat, so a reply such as "Fixed in f087cb3d" sat at the top while the finding it answered was a separate card further down. Each review thread is now one item at its root comment's time: the finding first, with path:line, then the replies indented under it, oldest first. A resolved thread folds into one row that opens to show the finding and its replies. Filters and paging act on whole threads. A thread shows when any of its comments passes the filter on its own, so a bot finding stays beside the human reply to it; a resolved thread hides as a whole. "Show older" counts a thread as one item, so a page never splits a thread. The grouping helper is shared with the timeline.
1 parent 76f58b0 commit 74bc5d7

3 files changed

Lines changed: 452 additions & 90 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestSummaryTab.tsx‎

Lines changed: 100 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ import { PullRequestLabelPicker } from "./PullRequestLabelPicker";
5353
import { PullRequestReviewerPicker } from "./PullRequestReviewerPicker";
5454
import { PullRequestActivityUnavailableState } from "./PullRequestActivityUnavailableState";
5555
import {
56+
filterPullRequestConversationItems,
57+
isPullRequestCommentFinished,
5658
latestPullRequestReviewOutcomes,
5759
orderPullRequestComments,
60+
pagePullRequestConversationItems,
61+
pullRequestConversationItemComments,
62+
pullRequestConversationItems,
5863
pullRequestFindingKey,
5964
pullRequestReviewOutcome,
6065
visibleBody,
66+
type PullRequestConversationItem,
6167
type PullRequestFinding,
6268
} from "./pullRequestDetail.logic";
6369
import {
@@ -201,6 +207,8 @@ function CollapsedComment({
201207
reactionBar,
202208
detail,
203209
thread,
210+
replyCount = 0,
211+
replies = null,
204212
}: {
205213
comment: PullRequestComment;
206214
editing: CommentEditing;
@@ -209,6 +217,9 @@ function CollapsedComment({
209217
reactionBar: ReactNode;
210218
detail: PullRequestDetailView;
211219
thread: PullRequestReviewThread | undefined;
220+
/** Replies to a folded thread's root, shown with it when the row opens. */
221+
replyCount?: number;
222+
replies?: ReactNode;
212223
}) {
213224
const [open, setOpen] = useState(false);
214225
const statusTriggerRef = useRef<HTMLButtonElement>(null);
@@ -218,6 +229,11 @@ function CollapsedComment({
218229
<div className="p-3">
219230
<div className="flex flex-wrap items-start gap-2">
220231
<CommentIdentity comment={comment} detail={detail} />
232+
{replyCount > 0 ? (
233+
<span className="shrink-0 py-1 text-xs text-muted-foreground">
234+
{replyCount} {replyCount === 1 ? "reply" : "replies"}
235+
</span>
236+
) : null}
221237
<CollapsibleTrigger
222238
ref={statusTriggerRef}
223239
className="flex shrink-0 items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground hover:bg-muted hover:text-foreground"
@@ -253,6 +269,7 @@ function CollapsedComment({
253269
{body === null && !editing.canEdit(comment) ? null : (
254270
<CommentBody className="mt-2" comment={comment} editing={editing} />
255271
)}
272+
{replies ? <div className="mt-3">{replies}</div> : null}
256273
</div>
257274
) : null}
258275
</CollapsiblePanel>
@@ -389,28 +406,26 @@ export function PullRequestSummaryTab({
389406
DEFAULT_COMMENT_FILTER,
390407
CommentFilterSchema,
391408
);
392-
const threadByCommentId = new Map(
393-
detail.reviewThreads.flatMap((thread) =>
394-
thread.comments.map((comment) => [comment.id, thread] as const),
395-
),
409+
// A review thread is one item: its finding, then the replies to it. Filtering and paging act
410+
// on whole items, so a reply never shows without the finding it answers, or the other way.
411+
const filteredItems = filterPullRequestConversationItems(
412+
pullRequestConversationItems(detail.comments, detail.reviewThreads),
413+
commentFilter,
396414
);
397-
398-
const isFinished = (comment: PullRequestComment) =>
399-
threadByCommentId.get(comment.id)?.isResolved === true ||
400-
pullRequestReviewOutcome(comment.reviewState) === "dismissed";
401-
const isBot = (comment: PullRequestComment) =>
402-
comment.author?.isBot === true || comment.author?.login.endsWith("[bot]") === true;
403-
const filteredComments = detail.comments.filter(
404-
(comment) =>
405-
(commentFilter.bots || !isBot(comment)) && (commentFilter.resolved || !isFinished(comment)),
415+
const shownCommentIds = new Set(
416+
filteredItems.flatMap((item) =>
417+
pullRequestConversationItemComments(item).map((comment) => comment.id),
418+
),
406419
);
407-
const filteredOutCount = detail.comments.length - filteredComments.length;
408-
const recentComments = filteredComments.slice(
409-
Math.max(0, filteredComments.length - shownComments),
420+
const filteredOutCount = detail.comments.filter(
421+
(comment) => !shownCommentIds.has(comment.id),
422+
).length;
423+
const { shown: recentItems, hidden: hiddenCommentCount } = pagePullRequestConversationItems(
424+
filteredItems,
425+
shownComments,
410426
);
411-
const hiddenCommentCount = filteredComments.length - recentComments.length;
412427
const [commentOrder, setCommentOrder] = useState<"newest" | "oldest">("newest");
413-
const visibleComments = orderPullRequestComments(recentComments, commentOrder);
428+
const visibleItems = orderPullRequestComments(recentItems, commentOrder);
414429
const showOldestCommentsButton =
415430
hiddenCommentCount > 0 ? (
416431
<Button
@@ -524,53 +539,44 @@ export function PullRequestSummaryTab({
524539
},
525540
};
526541

527-
const renderComment = (comment: PullRequestComment) => {
528-
const thread = threadByCommentId.get(comment.id);
542+
const reactionBarFor = (comment: PullRequestComment) => (
543+
<PullRequestReactionBar
544+
className="ml-auto justify-end"
545+
reactions={comment.reactions ?? []}
546+
canReact={detail.capabilities.reactions === true}
547+
subjectId={comment.id}
548+
environmentId={environmentId}
549+
reference={reference}
550+
onRefresh={onRefresh}
551+
/>
552+
);
553+
554+
const renderReplies = (replies: ReadonlyArray<PullRequestComment>) =>
555+
replies.length === 0 ? null : (
556+
<div className="ml-4 space-y-2 border-l-2 border-border/60 pl-3">
557+
{replies.map((reply) => renderCommentCard(reply, undefined, { reply: true }))}
558+
</div>
559+
);
560+
561+
// `thread` is the review thread the comment opens, when it is a thread's root; a reply leaves
562+
// the location and the finding to that root.
563+
const renderCommentCard = (
564+
comment: PullRequestComment,
565+
thread: PullRequestReviewThread | undefined,
566+
{ reply = false }: { reply?: boolean } = {},
567+
) => {
529568
const body = visibleBody(comment.body);
530-
if (isFinished(comment)) {
531-
return (
532-
<CollapsedComment
533-
key={`${detail.url}:${comment.id}`}
534-
comment={comment}
535-
editing={commentEditing}
536-
detail={detail}
537-
thread={thread}
538-
label={thread?.isResolved ? "Resolved" : "Review dismissed"}
539-
body={body}
540-
reactionBar={
541-
<PullRequestReactionBar
542-
className="ml-auto justify-end"
543-
reactions={comment.reactions ?? []}
544-
canReact={detail.capabilities.reactions === true}
545-
subjectId={comment.id}
546-
environmentId={environmentId}
547-
reference={reference}
548-
onRefresh={onRefresh}
549-
/>
550-
}
551-
/>
552-
);
553-
}
554569
const outcome = pullRequestReviewOutcome(comment.reviewState);
555570
const finding: PullRequestFinding | null =
556-
(comment.kind !== "review" && comment.kind !== "review-comment") || outcome === "approved"
571+
reply ||
572+
(comment.kind !== "review" && comment.kind !== "review-comment") ||
573+
outcome === "approved"
557574
? null
558575
: thread === undefined
559576
? body === null
560577
? null
561578
: { kind: "comment", comment }
562579
: { kind: "thread", thread };
563-
const reactionBar = (
564-
<PullRequestReactionBar
565-
reactions={comment.reactions ?? []}
566-
canReact={detail.capabilities.reactions === true}
567-
subjectId={comment.id}
568-
environmentId={environmentId}
569-
reference={reference}
570-
onRefresh={onRefresh}
571-
className="ml-auto justify-end"
572-
/>
573-
);
574580
return (
575581
<article
576582
key={`${detail.url}:${comment.id}`}
@@ -599,18 +605,50 @@ export function PullRequestSummaryTab({
599605
{pendingFinding === pullRequestFindingKey(finding) ? "Preparing..." : fixFindingLabel}
600606
</Button>
601607
) : null}
602-
{reactionBar}
603-
</div>
604-
<div className="px-3">
605-
<CommentLocation comment={comment} thread={thread} />
608+
{reactionBarFor(comment)}
606609
</div>
610+
{reply ? null : (
611+
<div className="px-3">
612+
<CommentLocation comment={comment} thread={thread} />
613+
</div>
614+
)}
607615
{body === null && !commentEditing.canEdit(comment) ? null : (
608616
<CommentBody className="px-3 py-3" comment={comment} editing={commentEditing} />
609617
)}
610618
</article>
611619
);
612620
};
613621

622+
const renderItem = (item: PullRequestConversationItem) => {
623+
const comment = item.kind === "comment" ? item.comment : item.root;
624+
const thread = item.kind === "thread" ? item.thread : undefined;
625+
const replies = item.kind === "thread" ? item.replies : [];
626+
// A resolved thread folds as one unit: one row for the finding, its replies inside.
627+
if (isPullRequestCommentFinished(comment, thread)) {
628+
return (
629+
<CollapsedComment
630+
key={`${detail.url}:${item.kind}:${item.id}`}
631+
comment={comment}
632+
editing={commentEditing}
633+
detail={detail}
634+
thread={thread}
635+
label={thread?.isResolved ? "Resolved" : "Review dismissed"}
636+
body={visibleBody(comment.body)}
637+
replyCount={replies.length}
638+
replies={renderReplies(replies)}
639+
reactionBar={reactionBarFor(comment)}
640+
/>
641+
);
642+
}
643+
if (item.kind === "comment") return renderCommentCard(comment, undefined);
644+
return (
645+
<div key={`${detail.url}:thread:${item.id}`} className="space-y-2">
646+
{renderCommentCard(comment, thread)}
647+
{renderReplies(replies)}
648+
</div>
649+
);
650+
};
651+
614652
return (
615653
<div ref={scrollerRef} className="h-full overflow-y-auto" data-pull-request-summary-scroll>
616654
<section className="px-4 pt-2.5 pb-1">
@@ -866,7 +904,7 @@ export function PullRequestSummaryTab({
866904
) : null}
867905
{detail.comments.length === 0 ? (
868906
<p className="py-2 text-xs text-muted-foreground">No comments yet.</p>
869-
) : filteredComments.length === 0 ? (
907+
) : filteredItems.length === 0 ? (
870908
<p className="py-2 text-xs text-muted-foreground">
871909
{filteredOutCount === 1
872910
? "The only comment is hidden by the filter."
@@ -875,7 +913,7 @@ export function PullRequestSummaryTab({
875913
) : (
876914
<div className="space-y-3">
877915
{commentOrder === "oldest" ? showOldestCommentsButton : null}
878-
{visibleComments.map(renderComment)}
916+
{visibleItems.map(renderItem)}
879917
{commentOrder === "newest" ? showOldestCommentsButton : null}
880918
{shownComments > COMMENT_PAGE ? (
881919
<Button

0 commit comments

Comments
 (0)