Skip to content

Commit 37d9b28

Browse files
committed
feat(review): add PR-wide comment tracking and keep guide files together
1 parent 4548dd2 commit 37d9b28

26 files changed

Lines changed: 1478 additions & 156 deletions

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

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { usePullRequestThreads } from "./usePullRequestThreads";
12
import { canEditPullRequestComment } from "@t3tools/client-runtime/review-editing";
23
import { PullRequestCommentComposer } from "./PullRequestCommentComposer";
34
import { SafeAreaView } from "react-native-safe-area-context";
@@ -32,6 +33,7 @@ export function PullRequestCommentControls({
3233
comment,
3334
onEdit,
3435
onUnresolve,
36+
onResolve,
3537
disabled,
3638
render,
3739
}: {
@@ -47,12 +49,15 @@ export function PullRequestCommentControls({
4749
};
4850
onEdit?: (() => void) | undefined;
4951
onUnresolve?: (() => void) | undefined;
52+
onResolve?: (() => void) | undefined;
5053
disabled?: boolean;
5154
render?: (slots: { actions: ReactNode; reactions: ReactNode }) => ReactNode;
5255
}) {
5356
const target = pullRequestTarget(params);
5457
const detail = useEnvironmentQuery(composerPullRequests.detail(target));
5558
const activity = useEnvironmentQuery(composerPullRequests.activity(target));
59+
const agent = usePullRequestThreads(params, detail.data);
60+
const markdown = `${comment.author?.login ? `**${comment.author.login}**\n\n` : ""}${comment.body}${comment.url ? `\n\n[View comment](${comment.url})` : ""}`;
5661
const allowed = useAtomValue(
5762
composerPullRequests.setReaction.permissionAtom(target.environmentId),
5863
);
@@ -178,6 +183,15 @@ export function PullRequestCommentControls({
178183
<ControlPillMenu
179184
title="Comment actions"
180185
actions={[
186+
...(onResolve
187+
? [
188+
{
189+
id: "resolve",
190+
title: "Resolve thread",
191+
attributes: { disabled: Boolean(disabled) },
192+
},
193+
]
194+
: []),
181195
...(onUnresolve
182196
? [
183197
{
@@ -188,18 +202,32 @@ export function PullRequestCommentControls({
188202
]
189203
: []),
190204
...(onEdit || canEdit ? [{ id: "edit", title: "Edit comment" }] : []),
191-
{ id: "copy", title: "Copy comment" },
192-
...(comment.url
193-
? [
194-
{ id: "copy-link", title: "Copy link" },
195-
{ id: "open", title: "Open on host" },
196-
]
197-
: []),
205+
{
206+
id: "copy-menu",
207+
title: "Copy",
208+
subactions: [
209+
...(comment.url ? [{ id: "copy-link", title: "Link to comment" }] : []),
210+
{ id: "copy", title: "Copy as Markdown" },
211+
],
212+
},
213+
{
214+
id: "composer",
215+
title: "Add to composer",
216+
attributes: { disabled: !agent.canAsk || agent.busy },
217+
},
218+
...(comment.url ? [{ id: "open", title: "Open on host" }] : []),
198219
]}
199220
onPressAction={({ nativeEvent }) => {
200-
if (nativeEvent.event === "unresolve") onUnresolve?.();
221+
if (nativeEvent.event === "resolve") onResolve?.();
222+
else if (nativeEvent.event === "composer")
223+
void agent.ask(
224+
agent.threads.length === 1 ? agent.threads[0] : undefined,
225+
"ask",
226+
markdown,
227+
);
228+
else if (nativeEvent.event === "unresolve") onUnresolve?.();
201229
else if (nativeEvent.event === "edit") edit();
202-
else if (nativeEvent.event === "copy") void Clipboard.setStringAsync(comment.body);
230+
else if (nativeEvent.event === "copy") void Clipboard.setStringAsync(markdown);
203231
else if (nativeEvent.event === "copy-link" && comment.url)
204232
void Clipboard.setStringAsync(comment.url);
205233
else if (nativeEvent.event === "open" && comment.url) void Linking.openURL(comment.url);
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
import { useNavigation } from "@react-navigation/native";
2+
import { useState } from "react";
3+
import { Alert, Modal, Pressable, ScrollView, View } from "react-native";
4+
import { SafeAreaView } from "react-native-safe-area-context";
5+
import type { PullRequestReviewThread } from "@t3tools/contracts";
6+
import { AppText as Text } from "../../components/AppText";
7+
import { ControlPill } from "../../components/ControlPill";
8+
import { composerPullRequests } from "../../state/pull-requests";
9+
import { useAtomCommand } from "../../state/use-atom-command";
10+
import { useEnvironmentQuery } from "../../state/query";
11+
import { PullRequestCommentControls } from "./PullRequestCommentControls";
12+
import { PullRequestMarkdown } from "./PullRequestMarkdown";
13+
import { PullRequestAvatar } from "./PullRequestPresentation";
14+
import {
15+
PullRequestPendingBadge,
16+
PullRequestPendingCommentActions,
17+
} from "./PullRequestPendingComment";
18+
import { usePullRequestReviewDraft } from "./usePullRequestReviewDraft";
19+
import { pullRequestTarget, type PullRequestParams } from "./usePullRequestDiff";
20+
import { usePullRequestPermissions } from "./usePullRequestPermissions";
21+
import { relativeTime } from "../../lib/time";
22+
23+
function CommentThread({
24+
params,
25+
thread,
26+
onOpen,
27+
}: {
28+
params: PullRequestParams;
29+
thread: PullRequestReviewThread;
30+
onOpen: () => void;
31+
}) {
32+
const target = pullRequestTarget(params);
33+
const detail = useEnvironmentQuery(composerPullRequests.detail(target));
34+
const activity = useEnvironmentQuery(composerPullRequests.activity(target));
35+
const permissions = usePullRequestPermissions(params, detail.data);
36+
const resolve = useAtomCommand(composerPullRequests.setThreadResolution, {
37+
reportFailure: false,
38+
});
39+
const [busy, setBusy] = useState(false);
40+
const first = thread.comments[0];
41+
if (!first) return null;
42+
const toggle = async () => {
43+
if (busy) return;
44+
setBusy(true);
45+
const result = await resolve({
46+
...target,
47+
input: { ...target.input, threadId: thread.id, resolved: !thread.isResolved },
48+
});
49+
setBusy(false);
50+
if (result._tag === "Failure") Alert.alert("Could not update the thread", "Try again.");
51+
else activity.refresh();
52+
};
53+
const canResolve = permissions.canResolve && thread.canResolve !== false;
54+
return (
55+
<View className="overflow-hidden rounded-2xl border border-border-subtle bg-grouped-card">
56+
<Pressable
57+
onPress={onOpen}
58+
accessibilityRole="button"
59+
accessibilityLabel={`Open discussion in ${thread.path}`}
60+
className="border-b border-border-subtle px-3 py-2"
61+
>
62+
<Text className="font-mono text-2xs text-foreground-muted" numberOfLines={2}>
63+
{thread.path}
64+
{thread.line ? `:${thread.line}` : ""}
65+
</Text>
66+
</Pressable>
67+
<PullRequestCommentControls
68+
params={params}
69+
comment={{ ...first, url: first.url ?? null }}
70+
disabled={busy}
71+
onResolve={canResolve && !thread.isResolved ? () => void toggle() : undefined}
72+
onUnresolve={canResolve && thread.isResolved ? () => void toggle() : undefined}
73+
render={({ actions, reactions }) => (
74+
<View className="gap-2 p-3">
75+
<View className="flex-row items-center gap-2">
76+
<PullRequestAvatar actor={first.author} size={24} />
77+
<Text className="min-w-0 flex-1 text-xs font-t3-medium" numberOfLines={1}>
78+
{first.author?.login ?? "Unknown author"}
79+
</Text>
80+
<Text className="text-2xs text-foreground-muted">
81+
{relativeTime(first.createdAt)}
82+
</Text>
83+
{actions}
84+
</View>
85+
{thread.isResolved ? (
86+
<Text className="text-xs text-foreground-muted">
87+
Resolved · {thread.commentCount ?? thread.comments.length} comments
88+
</Text>
89+
) : (
90+
<PullRequestMarkdown markdown={first.body} />
91+
)}
92+
{reactions}
93+
<Pressable accessibilityRole="button" onPress={onOpen} className="py-2">
94+
<Text className="text-xs text-foreground-muted">
95+
{thread.isResolved
96+
? "Expand discussion"
97+
: `${Math.max(0, (thread.commentCount ?? thread.comments.length) - 1)} replies · Open discussion`}
98+
</Text>
99+
</Pressable>
100+
</View>
101+
)}
102+
/>
103+
</View>
104+
);
105+
}
106+
107+
/** One PR-wide checklist remains accessible while switching review tabs. */
108+
export function PullRequestCommentsSheet({
109+
params,
110+
visible,
111+
onClose,
112+
}: {
113+
params: PullRequestParams;
114+
visible: boolean;
115+
onClose: () => void;
116+
}) {
117+
const navigation = useNavigation();
118+
const draft = usePullRequestReviewDraft(params);
119+
const [showResolved, setShowResolved] = useState(false);
120+
const threads = draft.threads.filter((thread) => showResolved || !thread.isResolved);
121+
return (
122+
<Modal
123+
visible={visible}
124+
animationType="slide"
125+
presentationStyle="pageSheet"
126+
onRequestClose={onClose}
127+
>
128+
<SafeAreaView className="flex-1 bg-screen">
129+
<View className="flex-row items-center gap-3 border-b border-border-subtle px-4 py-3">
130+
<Text className="flex-1 text-lg font-t3-semibold">Comments</Text>
131+
<ControlPill icon="xmark" accessibilityLabel="Close comments" onPress={onClose} />
132+
</View>
133+
<ScrollView contentContainerStyle={{ padding: 16, gap: 12 }}>
134+
<Pressable
135+
onPress={() => setShowResolved(!showResolved)}
136+
accessibilityRole="checkbox"
137+
accessibilityState={{ checked: showResolved }}
138+
className="py-2"
139+
>
140+
<Text className="text-sm">{showResolved ? "Hide resolved" : "Show resolved"}</Text>
141+
</Pressable>
142+
{draft.comments.map((comment) => (
143+
<View
144+
key={comment.id}
145+
className="gap-2 rounded-2xl border border-border-subtle bg-grouped-card p-3"
146+
>
147+
<View className="flex-row items-center gap-2">
148+
<PullRequestPendingBadge />
149+
<View className="flex-1" />
150+
<PullRequestPendingCommentActions params={params} comment={comment} />
151+
</View>
152+
<Text className="font-mono text-2xs text-foreground-muted" numberOfLines={2}>
153+
{comment.path}
154+
</Text>
155+
<PullRequestMarkdown markdown={comment.body} />
156+
<Pressable
157+
accessibilityRole="button"
158+
onPress={() => {
159+
onClose();
160+
navigation.navigate("PullRequestInlineComment", {
161+
...params,
162+
draftId: comment.id,
163+
path: comment.path,
164+
position: comment.position,
165+
headSha: comment.headSha,
166+
code: comment.code,
167+
...(comment.oldPath ? { oldPath: comment.oldPath } : {}),
168+
});
169+
}}
170+
>
171+
<Text className="py-2 text-xs text-foreground-muted">Open pending comment</Text>
172+
</Pressable>
173+
</View>
174+
))}
175+
{threads.map((thread) => (
176+
<CommentThread
177+
key={thread.id}
178+
params={params}
179+
thread={thread}
180+
onOpen={() => {
181+
onClose();
182+
navigation.navigate("PullRequestDiscussion", {
183+
...params,
184+
discussionId: thread.id,
185+
});
186+
}}
187+
/>
188+
))}
189+
{!threads.length && !draft.comments.length ? (
190+
<Text className="text-sm text-foreground-muted">No unresolved comments.</Text>
191+
) : null}
192+
</ScrollView>
193+
</SafeAreaView>
194+
</Modal>
195+
);
196+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ function Discussion({ params }: { params: PullRequestParams & { readonly discuss
242242
params={params}
243243
comment={{ ...comment, url: comment.url ?? null }}
244244
onUnresolve={resolved && canResolve ? () => void toggleResolved() : undefined}
245+
onResolve={
246+
!resolved && canResolve && index === 0
247+
? () => void toggleResolved()
248+
: undefined
249+
}
245250
disabled={busy}
246251
render={({ actions, reactions }) => (
247252
<>

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

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { usePullRequestThreads } from "./usePullRequestThreads";
2+
import { composerPullRequests } from "../../state/pull-requests";
3+
import { useEnvironmentQuery } from "../../state/query";
4+
import { pullRequestTarget } from "./usePullRequestDiff";
15
import * as Clipboard from "expo-clipboard";
26
import { Alert, View } from "react-native";
37
import { AppText as Text } from "../../components/AppText";
@@ -27,17 +31,37 @@ export function PullRequestPendingCommentActions({
2731
onEdit?: () => void;
2832
}) {
2933
const actions = usePendingReviewCommentActions(params);
34+
const detail = useEnvironmentQuery(composerPullRequests.detail(pullRequestTarget(params)));
35+
const agent = usePullRequestThreads(params, detail.data, comment.path);
36+
const markdown = `**Pending comment on ${comment.path}**\n\n${comment.body}`;
3037
return (
3138
<ControlPillMenu
3239
title="Comment actions"
3340
actions={[
3441
...(onEdit
3542
? [{ id: "edit", title: "Edit comment", attributes: { disabled: actions.busy } }]
3643
: []),
37-
{ id: "copy", title: "Copy comment" },
38-
...(comment.hostedComment || actions.canSave
39-
? [{ id: "copy-link", title: "Copy link", attributes: { disabled: actions.busy } }]
40-
: []),
44+
{
45+
id: "copy-menu",
46+
title: "Copy",
47+
subactions: [
48+
...(comment.hostedComment || actions.canSave
49+
? [
50+
{
51+
id: "copy-link",
52+
title: "Link to comment",
53+
attributes: { disabled: actions.busy },
54+
},
55+
]
56+
: []),
57+
{ id: "copy", title: "Copy as Markdown" },
58+
],
59+
},
60+
{
61+
id: "composer",
62+
title: "Add to composer",
63+
attributes: { disabled: !agent.canAsk || agent.busy },
64+
},
4165
...(!comment.hostedComment || actions.canDiscard
4266
? [
4367
{
@@ -50,7 +74,13 @@ export function PullRequestPendingCommentActions({
5074
]}
5175
onPressAction={({ nativeEvent }) => {
5276
if (nativeEvent.event === "edit") onEdit?.();
53-
else if (nativeEvent.event === "copy") void Clipboard.setStringAsync(comment.body);
77+
else if (nativeEvent.event === "copy") void Clipboard.setStringAsync(markdown);
78+
else if (nativeEvent.event === "composer")
79+
void agent.ask(
80+
agent.threads.length === 1 ? agent.threads[0] : undefined,
81+
"ask",
82+
markdown,
83+
);
5484
else if (nativeEvent.event === "copy-link") void actions.copyLink(comment);
5585
else if (nativeEvent.event === "discard")
5686
Alert.alert("Discard this comment?", "Your other review comments will be kept.", [

0 commit comments

Comments
 (0)