Skip to content

Commit 70581b5

Browse files
committed
feat(web): resolved review conversations fold into avatars on their diff line
A resolved conversation in the pull request Code tab took a row between code lines. It now shows as its authors' avatars at the end of the commented line and opens in place on click. Collapsing it returns it to the avatars.
1 parent fdaf883 commit 70581b5

3 files changed

Lines changed: 162 additions & 7 deletions

File tree

‎apps/web/src/components/pullRequest/PullRequestCodeTab.browser.test.tsx‎

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,3 +355,67 @@ it("answers a commit's diff link only once that commit's diff is shown", async (
355355
await screen.rerender(scoped(oid, url));
356356
await vi.waitFor(() => expect(settled).toHaveBeenCalledWith(url));
357357
});
358+
359+
it("folds a resolved conversation into avatars on its line until it is opened", async () => {
360+
setup({ paged: false });
361+
__setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS, diffFilesCollapsed: false });
362+
using _preferences = {
363+
[Symbol.dispose]() {
364+
__setClientSettingsForTests(DEFAULT_CLIENT_SETTINGS);
365+
},
366+
};
367+
const container = document.createElement("div");
368+
container.className = "flex h-[700px] w-[900px]";
369+
const withThread = (isResolved: boolean) => (
370+
<PullRequestCodeTab
371+
scrollerRef={() => {}}
372+
environmentId={EnvironmentId.make("environment")}
373+
reference={detail}
374+
detail={{
375+
...detail,
376+
reviewThreads: [
377+
{
378+
id: "thread",
379+
path: "a.ts",
380+
line: 3,
381+
side: "right",
382+
isResolved,
383+
isOutdated: false,
384+
comments: [
385+
{
386+
id: "comment",
387+
author: { login: "reviewer", name: null, avatarUrl: null },
388+
body: "Rename this.",
389+
createdAt: "2026-09-01T00:00:00Z",
390+
url: null,
391+
},
392+
],
393+
},
394+
],
395+
}}
396+
selectedCommitOid={null}
397+
onSelectedCommitChange={() => {}}
398+
onRefresh={() => {}}
399+
/>
400+
);
401+
await using screen = await render(withThread(true), { container });
402+
const marker = () => screen.getByRole("button", { name: "Show resolved conversation" });
403+
const card = (state: string) => screen.getByRole("button", { name: `${state} · 1 comment` });
404+
405+
await expect.element(marker()).toBeVisible();
406+
await expect.element(card("Resolved")).not.toBeInTheDocument();
407+
408+
await marker().click();
409+
await expect.element(card("Resolved")).toHaveAttribute("aria-expanded", "true");
410+
await expect.element(marker()).not.toBeInTheDocument();
411+
412+
// Reopened and resolved again under the reader, it stays open until they collapse it.
413+
await screen.rerender(withThread(false));
414+
await expect.element(card("Open")).toHaveAttribute("aria-expanded", "true");
415+
await screen.rerender(withThread(true));
416+
await expect.element(card("Resolved")).toHaveAttribute("aria-expanded", "true");
417+
418+
await card("Resolved").click();
419+
await expect.element(marker()).toBeVisible();
420+
await expect.element(card("Resolved")).not.toBeInTheDocument();
421+
});

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import { Toggle, ToggleGroup } from "../ui/toggle-group";
114114
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
115115
import {
116116
getReviewPositionAnchor,
117+
InlineReviewThreads,
117118
PendingReviewCommentCard,
118119
ReviewThreadCard,
119120
toViewerSide,
@@ -995,7 +996,7 @@ function PullRequestCodeTab({
995996
return true;
996997
};
997998

998-
const renderThreadCard = (thread: PullRequestReviewThread) => (
999+
const renderThreadCard = (thread: PullRequestReviewThread, onCollapse?: () => void) => (
9991000
<ReviewThreadCard
10001001
// Host thread ids can collide across pull requests.
10011002
key={`${reference.projectId}#${reference.number}:${thread.id}`}
@@ -1060,12 +1061,14 @@ function PullRequestCodeTab({
10601061
)
10611062
}
10621063
onReacted={onRefresh}
1064+
{...(onCollapse ? { onCollapse } : {})}
10631065
/>
10641066
);
10651067

10661068
const renderAnnotation = (...[annotation]: CodeViewAnnotationArgs<ReviewAnnotationGroup>) => (
1067-
<div className="py-1 font-sans text-foreground">
1068-
{annotation.metadata.threads.map(renderThreadCard)}
1069+
// Folded resolved conversations alone add no row, so the code reads straight through.
1070+
<div className="relative font-sans text-foreground has-[>:not([data-resolved-threads])]:py-1">
1071+
<InlineReviewThreads threads={annotation.metadata.threads} renderThread={renderThreadCard} />
10691072
{annotation.metadata.pending.map((comment) => (
10701073
<PendingReviewCommentCard
10711074
key={comment.id}

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

Lines changed: 92 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type {
22
EnvironmentId,
3+
PullRequestActor,
34
PullRequestDiffSide,
45
PullRequestRef,
56
PullRequestReviewPosition,
@@ -15,22 +16,23 @@ import {
1516
CircleCheckIcon,
1617
CircleIcon,
1718
} from "lucide-react";
18-
import { useRef, useState } from "react";
19+
import { type ReactNode, useRef, useState } from "react";
1920
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
2021

2122
import { RelativeTime } from "~/components/RelativeTime";
2223
import { cn } from "~/lib/utils";
2324
import { SpeechTextField, TextFieldSpeechControls } from "~/speech/useTextFieldSpeech";
2425

2526
import { Button } from "../ui/button";
27+
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
2628
import { PullRequestEditButton } from "./PullRequestEditButton";
2729
import { isCommentSubmitShortcut } from "../diffs/commentSubmitShortcut";
2830
import {
2931
editPullRequestThreadComment,
3032
mergePullRequestThreadComments,
3133
visibleBody,
3234
} from "./pullRequestDetail.logic";
33-
import { PullRequestActorLabel } from "./pullRequestPresentation";
35+
import { PullRequestActorAvatar, PullRequestActorLabel } from "./pullRequestPresentation";
3436
import { PullRequestMarkdown } from "./PullRequestMarkdown";
3537
import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor";
3638
import { PullRequestReactionBar } from "./PullRequestReactions";
@@ -114,6 +116,86 @@ export function PendingReviewCommentCard({
114116
);
115117
}
116118

119+
const MARKER_AVATAR_LIMIT = 3;
120+
121+
function ResolvedThreadsMarker({
122+
threads,
123+
onOpen,
124+
}: {
125+
threads: ReadonlyArray<PullRequestReviewThread>;
126+
onOpen: () => void;
127+
}) {
128+
const authors = new Map<string, PullRequestActor | null>();
129+
for (const thread of threads) {
130+
for (const comment of thread.comments) {
131+
authors.set(comment.author?.login ?? "ghost", comment.author);
132+
}
133+
}
134+
if (authors.size === 0) authors.set("ghost", null);
135+
const label =
136+
threads.length === 1
137+
? "Show resolved conversation"
138+
: `Show ${threads.length} resolved conversations`;
139+
return (
140+
<Tooltip>
141+
<TooltipTrigger
142+
render={
143+
<button
144+
type="button"
145+
data-resolved-threads
146+
aria-label={label}
147+
aria-expanded={false}
148+
// Sits on the commented line, which is the row above this zero-height annotation.
149+
className="absolute right-3 bottom-full flex h-[var(--diffs-line-height,20px)] cursor-pointer items-center -space-x-1 rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-inset"
150+
contentEditable={false}
151+
onPointerDown={(event) => event.stopPropagation()}
152+
onClick={onOpen}
153+
/>
154+
}
155+
>
156+
{[...authors].slice(0, MARKER_AVATAR_LIMIT).map(([login, author]) => (
157+
<PullRequestActorAvatar key={login} actor={author} className="ring-1 ring-background" />
158+
))}
159+
</TooltipTrigger>
160+
<TooltipPopup side="left">{label}</TooltipPopup>
161+
</Tooltip>
162+
);
163+
}
164+
165+
/** The conversations on one diff line. Resolved ones show as avatars until opened. */
166+
export function InlineReviewThreads({
167+
threads,
168+
renderThread,
169+
}: {
170+
threads: ReadonlyArray<PullRequestReviewThread>;
171+
renderThread: (thread: PullRequestReviewThread, onCollapse: () => void) => ReactNode;
172+
}) {
173+
const [opened, setOpened] = useState<ReadonlySet<string>>(() => new Set());
174+
// A conversation resolved while open stays open until the reader collapses it.
175+
const seenOpen = threads.filter((thread) => !thread.isResolved && !opened.has(thread.id));
176+
if (seenOpen.length > 0) {
177+
setOpened(new Set([...opened, ...seenOpen.map((thread) => thread.id)]));
178+
}
179+
const folded = threads.filter((thread) => thread.isResolved && !opened.has(thread.id));
180+
return (
181+
<>
182+
{folded.length > 0 ? (
183+
<ResolvedThreadsMarker
184+
threads={folded}
185+
onOpen={() => setOpened(new Set([...opened, ...folded.map((thread) => thread.id)]))}
186+
/>
187+
) : null}
188+
{threads.map((thread) =>
189+
folded.includes(thread)
190+
? null
191+
: renderThread(thread, () =>
192+
setOpened((current) => new Set([...current].filter((id) => id !== thread.id))),
193+
),
194+
)}
195+
</>
196+
);
197+
}
198+
117199
export function ReviewThreadCard({
118200
thread,
119201
workspaceRoot,
@@ -134,6 +216,7 @@ export function ReviewThreadCard({
134216
onEditComment,
135217
onToggleResolved,
136218
onReacted,
219+
onCollapse,
137220
}: {
138221
thread: PullRequestReviewThread;
139222
workspaceRoot: string;
@@ -158,8 +241,10 @@ export function ReviewThreadCard({
158241
onEditComment: (commentId: string, body: string) => Promise<boolean>;
159242
onToggleResolved: () => void;
160243
onReacted: () => void;
244+
/** Given on a diff line, where a resolved conversation folds away to its avatar marker. */
245+
onCollapse?: () => void;
161246
}) {
162-
const [expanded, setExpanded] = useState(!thread.isResolved);
247+
const [expanded, setExpanded] = useState(onCollapse !== undefined || !thread.isResolved);
163248
const [replying, setReplying] = useState(false);
164249
const [reply, setReply] = useState("");
165250
const [editingId, setEditingId] = useState<string | null>(null);
@@ -248,7 +333,10 @@ export function ReviewThreadCard({
248333
type="button"
249334
className="hover:text-foreground"
250335
aria-expanded={expanded}
251-
onClick={() => setExpanded((current) => !current)}
336+
onClick={() => {
337+
if (expanded && thread.isResolved && onCollapse) onCollapse();
338+
else setExpanded((current) => !current);
339+
}}
252340
>
253341
{thread.isResolved ? "Resolved" : "Open"} · {commentCount}{" "}
254342
{commentCount === 1 ? "comment" : "comments"}

0 commit comments

Comments
 (0)