Skip to content

Commit c0f849f

Browse files
committed
feat(review): refine comment navigation and move guide context into chapter rail
1 parent 4e425ca commit c0f849f

11 files changed

Lines changed: 354 additions & 255 deletions

‎apps/mobile/src/features/pull-requests/PullRequestCommentControls.tsx‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,14 @@ export function PullRequestCommentControls({
215215
title: "Add to composer",
216216
attributes: { disabled: !agent.canAsk || agent.busy },
217217
},
218-
...(comment.url ? [{ id: "open", title: "Open on host" }] : []),
218+
...(comment.url
219+
? [
220+
{
221+
id: "open",
222+
title: detail.data?.provider === "github" ? "Open in GitHub" : "Open on host",
223+
},
224+
]
225+
: []),
219226
]}
220227
onPressAction={({ nativeEvent }) => {
221228
if (nativeEvent.event === "resolve") onResolve?.();

‎apps/mobile/src/features/pull-requests/PullRequestCommentsSheet.tsx‎

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { Alert, Modal, Pressable, ScrollView, View } from "react-native";
44
import { SafeAreaView } from "react-native-safe-area-context";
55
import type { PullRequestReviewThread } from "@t3tools/contracts";
66
import { AppText as Text } from "../../components/AppText";
7+
import { SegmentedControl } from "../../components/SegmentedControl";
78
import { ControlPill } from "../../components/ControlPill";
89
import { composerPullRequests } from "../../state/pull-requests";
910
import { useAtomCommand } from "../../state/use-atom-command";
@@ -109,8 +110,23 @@ export function PullRequestCommentsSheet({
109110
}) {
110111
const navigation = useNavigation();
111112
const draft = usePullRequestReviewDraft(params);
112-
const [showResolved, setShowResolved] = useState(false);
113-
const threads = draft.threads.filter((thread) => showResolved || !thread.isResolved);
113+
const [status, setStatus] = useState<"resolved" | "unresolved" | "pending">("unresolved");
114+
const resolved = draft.threads.filter((thread) => thread.isResolved);
115+
const unresolved = draft.threads.filter((thread) => !thread.isResolved);
116+
// Removing the last draft also removes its tab; stay on an available status.
117+
const selectedStatus =
118+
status === "pending" && draft.comments.length === 0 ? "unresolved" : status;
119+
if (selectedStatus !== status) setStatus(selectedStatus);
120+
const threads =
121+
selectedStatus === "resolved" ? resolved : selectedStatus === "unresolved" ? unresolved : [];
122+
const pending = selectedStatus === "pending" ? draft.comments : [];
123+
const options = [
124+
{ value: "unresolved" as const, label: "Unresolved", badge: unresolved.length },
125+
{ value: "resolved" as const, label: "Resolved", badge: resolved.length },
126+
...(draft.comments.length
127+
? [{ value: "pending" as const, label: "Pending", badge: draft.comments.length }]
128+
: []),
129+
];
114130
return (
115131
<Modal
116132
visible={visible}
@@ -123,16 +139,17 @@ export function PullRequestCommentsSheet({
123139
<Text className="flex-1 text-lg font-t3-semibold">Comments</Text>
124140
<ControlPill icon="xmark" accessibilityLabel="Close comments" onPress={onClose} />
125141
</View>
142+
<View className="px-4 pt-3">
143+
<SegmentedControl
144+
options={options}
145+
selected={selectedStatus}
146+
onSelect={setStatus}
147+
variant="tabs"
148+
size="compact"
149+
/>
150+
</View>
126151
<ScrollView contentContainerStyle={{ padding: 16, gap: 12 }}>
127-
<Pressable
128-
onPress={() => setShowResolved(!showResolved)}
129-
accessibilityRole="checkbox"
130-
accessibilityState={{ checked: showResolved }}
131-
className="py-2"
132-
>
133-
<Text className="text-sm">{showResolved ? "Hide resolved" : "Show resolved"}</Text>
134-
</Pressable>
135-
{draft.comments.map((comment) => (
152+
{pending.map((comment) => (
136153
<View
137154
key={comment.id}
138155
className="gap-2 rounded-2xl border border-border-subtle bg-grouped-card p-3"
@@ -179,8 +196,10 @@ export function PullRequestCommentsSheet({
179196
}}
180197
/>
181198
))}
182-
{!threads.length && !draft.comments.length ? (
183-
<Text className="text-sm text-foreground-muted">No unresolved comments.</Text>
199+
{!threads.length && !pending.length ? (
200+
<Text className="text-sm text-foreground-muted">
201+
{selectedStatus === "resolved" ? "No resolved comments." : "No unresolved comments."}
202+
</Text>
184203
) : null}
185204
</ScrollView>
186205
</SafeAreaView>

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -969,17 +969,14 @@ function PullRequestCodeTab({
969969
return {
970970
title: candidate.title,
971971
reviewed: chapterReviewComplete && reviewedCount === members.length,
972-
detail: (
973-
<>
974-
{index !== chapterPosition ? (
972+
stat,
973+
detail:
974+
index !== chapterPosition ? (
975975
<span>
976976
{reviewedCount} of {members.length} files reviewed
977977
{chapterReviewComplete ? "" : " (loaded)"}
978978
</span>
979-
) : null}
980-
<PullRequestDiffStat additions={stat.additions} deletions={stat.deletions} />
981-
</>
982-
),
979+
) : null,
983980
...(filesViewed.enabled && canSetChapterViewed
984981
? {
985982
review: {

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
MessageSquarePlusIcon,
66
MoreHorizontalIcon,
77
TextIcon,
8+
ExternalLinkIcon,
89
} from "lucide-react";
10+
import { readLocalApi } from "~/localApi";
911
import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
1012
import { Button } from "../ui/button";
1113
import {
@@ -24,12 +26,14 @@ export function PullRequestCommentActions({
2426
body,
2527
url,
2628
onEdit,
29+
onOpen,
2730
resolution,
2831
onCopyLink,
2932
disabled,
3033
onAddToComposer,
3134
}: {
3235
body: string;
36+
onOpen?: ((url: string) => void) | undefined;
3337
url: string | null;
3438
onCopyLink?: (() => Promise<string | null>) | undefined;
3539
disabled?: boolean | undefined;
@@ -66,6 +70,14 @@ export function PullRequestCommentActions({
6670
<MenuSeparator />
6771
</>
6872
) : null}
73+
{url ? (
74+
<MenuItem
75+
onClick={() => (onOpen ? onOpen(url) : void readLocalApi()?.shell.openExternal(url))}
76+
>
77+
<ExternalLinkIcon />
78+
Open in GitHub
79+
</MenuItem>
80+
) : null}
6981
{onEdit ? <MenuItem onClick={onEdit}>Edit comment</MenuItem> : null}
7082
<MenuSub>
7183
<MenuSubTrigger>

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

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { useState } from "react";
1010
import { reviewLineRangeLabel } from "@t3tools/client-runtime/review-selection";
1111
import { Button } from "../ui/button";
1212
import { Badge } from "../ui/badge";
13+
import { Toggle, ToggleGroup } from "../ui/toggle-group";
1314
import { Popover, PopoverPopup, PopoverTrigger, PopoverTitle } from "../ui/popover";
1415
import {
1516
getReviewPositionAnchor,
@@ -47,7 +48,9 @@ export function PullRequestCommentsPopover({
4748
onAddPendingToComposer?: ((comment: PendingReviewComment) => void) | undefined;
4849
}) {
4950
const [open, setOpen] = useState(false);
50-
const [showResolved, setShowResolved] = useState(false);
51+
const [selectedStatus, setSelectedStatus] = useState<"resolved" | "unresolved" | "pending">(
52+
"unresolved",
53+
);
5154
const pending = usePendingReviewComments(reference, detail.reviewThreads);
5255
const actions = useReviewThreadActions(environmentId, reference, detail, onRefresh);
5356
// Hosted drafts are represented by the merged pending list, so they get one checklist entry.
@@ -58,6 +61,11 @@ export function PullRequestCommentsPopover({
5861
const unresolved = threads.filter((thread) => !thread.isResolved);
5962
const resolved = threads.filter((thread) => thread.isResolved);
6063
const openCount = unresolved.length + pending.length;
64+
const status =
65+
selectedStatus === "pending" && pending.length === 0 ? "unresolved" : selectedStatus;
66+
if (status !== selectedStatus) setSelectedStatus(status);
67+
const visibleThreads =
68+
status === "resolved" ? resolved : status === "unresolved" ? unresolved : [];
6169
const jump = (location: CommentLocation) => {
6270
setOpen(false);
6371
onOpenComment(location);
@@ -75,12 +83,9 @@ export function PullRequestCommentsPopover({
7583
</Badge>
7684
</PopoverTrigger>
7785
<PopoverPopup align="end" padding="none" width="auto">
78-
<div className="flex max-h-[min(75vh,48rem)] w-[min(32rem,calc(100vw-2rem))] flex-col">
86+
<div className="flex max-h-[min(75vh,48rem)] w-[min(36rem,calc(100vw-2rem))] min-w-0 flex-col">
7987
<div className="flex items-center gap-2 border-b border-border/60 px-3 py-2">
8088
<PopoverTitle>Comments</PopoverTitle>
81-
<span className="text-xs text-muted-foreground">
82-
{unresolved.length} unresolved · {pending.length} pending
83-
</span>
8489
<Button
8590
size="icon-xs"
8691
variant="ghost-muted"
@@ -91,15 +96,50 @@ export function PullRequestCommentsPopover({
9196
<XIcon className="size-3.5" />
9297
</Button>
9398
</div>
94-
<div className="min-h-0 overflow-y-auto py-2">
99+
<div className="border-b border-border/60 px-3 py-2">
100+
<ToggleGroup
101+
variant="segmented"
102+
className="w-full"
103+
aria-label="Comment status"
104+
value={[status]}
105+
onValueChange={(values) => {
106+
const next = values[0];
107+
if (next === "resolved" || next === "unresolved" || next === "pending")
108+
setSelectedStatus(next);
109+
}}
110+
>
111+
<Toggle value="unresolved" className="flex-1">
112+
Unresolved{" "}
113+
<Badge variant="secondary" size="sm">
114+
{unresolved.length}
115+
</Badge>
116+
</Toggle>
117+
<Toggle value="resolved" className="flex-1">
118+
Resolved{" "}
119+
<Badge variant="secondary" size="sm">
120+
{resolved.length}
121+
</Badge>
122+
</Toggle>
123+
{pending.length > 0 ? (
124+
<Toggle value="pending" className="flex-1">
125+
Pending{" "}
126+
<Badge variant="secondary" size="sm">
127+
{pending.length}
128+
</Badge>
129+
</Toggle>
130+
) : null}
131+
</ToggleGroup>
132+
</div>
133+
<div className="min-h-0 min-w-0 overflow-x-hidden overflow-y-auto py-2 [overflow-wrap:anywhere]">
95134
{open ? (
96135
<>
97-
{[...unresolved, ...(showResolved ? resolved : [])].map((thread) => (
136+
{visibleThreads.map((thread) => (
98137
<div key={thread.id}>
99138
<div className="mx-3 mt-2">
100139
<Button
101140
size="xs"
102141
variant="ghost-muted"
142+
className="max-w-full"
103143
onClick={() =>
104144
jump({
105145
path: thread.path,
@@ -132,12 +172,13 @@ export function PullRequestCommentsPopover({
132172
/>
133173
</div>
134174
))}
135-
{pending.map((comment) => (
175+
{(status === "pending" ? pending : []).map((comment) => (
136176
<div key={comment.id}>
137177
<div className="mx-3 mt-2">
138178
<Button
139179
size="xs"
140180
variant="ghost-muted"
181+
className="max-w-full"
141182
onClick={() =>
142183
jump({
143184
path: comment.path,
@@ -163,24 +204,12 @@ export function PullRequestCommentsPopover({
163204
/>
164205
</div>
165206
))}
166-
{openCount === 0 && (!showResolved || resolved.length === 0) ? (
167-
<p className="px-4 py-5 text-sm text-muted-foreground">No open comments.</p>
207+
{visibleThreads.length === 0 && (status !== "pending" || pending.length === 0) ? (
208+
<p className="px-4 py-5 text-sm text-muted-foreground">No {status} comments.</p>
168209
) : null}
169210
</>
170211
) : null}
171212
</div>
172-
{resolved.length ? (
173-
<div className="border-t border-border/60 px-3 py-2">
174-
<Button
175-
size="xs"
176-
variant="ghost-muted"
177-
onClick={() => setShowResolved((previous) => !previous)}
178-
>
179-
{showResolved ? "Hide" : "Show"} {resolved.length} resolved{" "}
180-
{resolved.length === 1 ? "thread" : "threads"}
181-
</Button>
182-
</div>
183-
) : null}
184213
</div>
185214
</PopoverPopup>
186215
</Popover>

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

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import { readLocalApi } from "~/localApi";
2828
import { pullRequestEnvironment } from "~/state/pullRequests";
2929
import { RelativeTime } from "~/components/RelativeTime";
3030

31-
import { Button } from "../ui/button";
3231
import { PullRequestEditButton } from "./PullRequestEditButton";
3332
import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
3433
import { toastManager } from "../ui/toast";
@@ -168,20 +167,6 @@ function ReviewStateBadge({ state }: { state: string }) {
168167
);
169168
}
170169

171-
function OpenOnHostButton({ url, onOpen }: { url: string | null; onOpen: (url: string) => void }) {
172-
return url === null ? null : (
173-
<Button
174-
size="icon-xs"
175-
variant="ghost-muted"
176-
className="-mr-1 -mt-1 shrink-0"
177-
aria-label="Open activity on host"
178-
onClick={() => onOpen(url)}
179-
>
180-
<ExternalLinkIcon className="size-3" />
181-
</Button>
182-
);
183-
}
184-
185170
function ConversationCard({
186171
event,
187172
editable,
@@ -247,6 +232,7 @@ function ConversationCard({
247232
<PullRequestCommentActions
248233
body={event.body ?? ""}
249234
url={event.url}
235+
onOpen={onOpen}
250236
onEdit={editable !== null && !editing ? () => setEditing(true) : undefined}
251237
onAddToComposer={
252238
event.comment && reactions.onAddCommentToComposer
@@ -274,7 +260,6 @@ function ConversationCard({
274260
onRefresh={reactions.onRefresh}
275261
/>
276262
) : null}
277-
<OpenOnHostButton url={event.url} onOpen={onOpen} />
278263
</div>
279264
</div>
280265
{editing && editable !== null ? (
@@ -632,7 +617,7 @@ function ReviewVerdictEvent({
632617
onRefresh={reactions.onRefresh}
633618
/>
634619
) : null}
635-
<OpenOnHostButton url={event.url} onOpen={onOpen} />
620+
<PullRequestCommentActions body={event.body ?? ""} url={event.url} onOpen={onOpen} />
636621
</div>
637622
{event.body ? (
638623
<TimelineBody

0 commit comments

Comments
 (0)