Skip to content

Commit 0080084

Browse files
arifali123builderorinmaria-rcks
authored
fix(mobile): group settled PR threads in the continue menu (#27941)
Co-authored-by: Orin <[email protected]> Co-authored-by: maria-rcks <[email protected]>
1 parent 511238c commit 0080084

8 files changed

Lines changed: 151 additions & 47 deletions

File tree

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,13 @@ export function PullRequestAgentRow(props: {
1919
title={props.title ?? action.title}
2020
icon="sparkles"
2121
accessibilityLabel={props.title ?? action.title}
22-
menu={agent.threads.length > 1}
22+
menu={agent.chooseThread && !action.attributes.disabled}
2323
onPress={
24-
action.attributes.disabled || agent.threads.length > 1
25-
? undefined
26-
: () => agent.start(props.task)
24+
action.attributes.disabled || agent.chooseThread ? undefined : () => agent.start(props.task)
2725
}
2826
/>
2927
);
30-
if (agent.threads.length <= 1 || action.attributes.disabled) return row;
28+
if (!agent.chooseThread || action.attributes.disabled) return row;
3129
return (
3230
<Menu
3331
title={props.title ?? action.title}

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

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Animated from "react-native-reanimated";
33
import { PR_ROW_LAYOUT } from "./pullRequestAnimations";
44
import { useNavigation } from "@react-navigation/native";
55
import type { PullRequestDetail } from "@t3tools/contracts";
6+
import type { MenuAction } from "@react-native-menu/menu";
67
import type { ReactNode } from "react";
78
import { Platform, Pressable, View } from "react-native";
89
import { useSafeAreaInsets } from "react-native-safe-area-context";
@@ -128,7 +129,7 @@ export function PullRequestActionToolbar(props: {
128129
).changeRequest;
129130
const threadLabel = agent.threads.length ? "Continue thread" : `Work on ${shortLabel}`;
130131
const primaryLabel = pendingReview ? `Submit review · ${draft.comments.length}` : threadLabel;
131-
const chooseThread = agent.threads.length > 1;
132+
const chooseThread = agent.chooseThread;
132133
const agentActions = agent.actions.filter((action) => action.task !== "ask");
133134
const open = (mode: "review" | "comment") =>
134135
navigation.navigate("PullRequestReview", { ...props.params, mode });
@@ -193,17 +194,6 @@ export function PullRequestActionToolbar(props: {
193194
</View>
194195
);
195196
}
196-
const nativeThreadItems = threadMenuItems.map((item) => (
197-
<Toolbar.MenuAction
198-
key={item.id}
199-
icon={item.image}
200-
subtitle={"subtitle" in item ? item.subtitle : undefined}
201-
disabled={"attributes" in item && item.attributes.disabled}
202-
onPress={() => agent.select(item.id)}
203-
>
204-
<Toolbar.Label>{item.title}</Toolbar.Label>
205-
</Toolbar.MenuAction>
206-
));
207197
const primaryControl = showPrimary ? (
208198
!pendingReview && chooseThread ? (
209199
<Toolbar.Menu
@@ -222,7 +212,7 @@ export function PullRequestActionToolbar(props: {
222212
disabled={primaryDisabled}
223213
separateBackground
224214
>
225-
{nativeThreadItems}
215+
{renderThreadMenuItems(threadMenuItems, agent.select)}
226216
</Toolbar.Menu>
227217
) : (
228218
<Toolbar.Button
@@ -256,17 +246,7 @@ export function PullRequestActionToolbar(props: {
256246
{agentActions.map((action) =>
257247
chooseThread && !action.disabled ? (
258248
<Toolbar.Menu key={action.task} title={action.title} icon={action.icon}>
259-
{agent.threadActions(action.task).map((item) => (
260-
<Toolbar.MenuAction
261-
key={item.id}
262-
icon={item.image}
263-
subtitle={"subtitle" in item ? item.subtitle : undefined}
264-
disabled={"attributes" in item && item.attributes.disabled}
265-
onPress={() => agent.select(item.id)}
266-
>
267-
<Toolbar.Label>{item.title}</Toolbar.Label>
268-
</Toolbar.MenuAction>
269-
))}
249+
{renderThreadMenuItems(agent.threadActions(action.task), agent.select)}
270250
</Toolbar.Menu>
271251
) : (
272252
<Toolbar.MenuAction
@@ -308,3 +288,23 @@ export function PullRequestActionToolbar(props: {
308288
</Toolbar>
309289
);
310290
}
291+
292+
function renderThreadMenuItems(items: MenuAction[], select: (id: string) => void): ReactNode {
293+
return items.map((item) =>
294+
item.subactions ? (
295+
<Toolbar.Menu key={item.id} title={item.title} icon={item.image}>
296+
{renderThreadMenuItems(item.subactions, select)}
297+
</Toolbar.Menu>
298+
) : (
299+
<Toolbar.MenuAction
300+
key={item.id}
301+
icon={item.image}
302+
subtitle={item.subtitle}
303+
disabled={item.attributes?.disabled}
304+
onPress={() => item.id && select(item.id)}
305+
>
306+
<Toolbar.Label>{item.title}</Toolbar.Label>
307+
</Toolbar.MenuAction>
308+
),
309+
);
310+
}

‎apps/mobile/src/features/pull-requests/pullRequestAgentTasks.test.ts‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {
33
appendPullRequestAgentPrompt,
44
pullRequestAgentPrompt,
55
pullRequestAgentThread,
6+
pullRequestAgentThreadActions,
67
} from "./pullRequestAgentTasks";
78
import { IsoDateTime, ProjectId, ThreadId } from "@t3tools/contracts";
89
import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients";
@@ -27,7 +28,30 @@ describe("PR agent tasks", () => {
2728
archivedAt: IsoDateTime.make("2026-10-09T10:00:00.000Z"),
2829
};
2930
expect(pullRequestAgentThread([thread, archived])).toBeUndefined();
31+
expect(pullRequestAgentThread([archived])).toBeUndefined();
32+
const settled = { ...thread, settled: true };
33+
expect(pullRequestAgentThread([settled])).toBeUndefined();
34+
expect(pullRequestAgentThread([settled], settled.id)).toBe(settled);
35+
expect(pullRequestAgentThread([thread, { ...settled, id: archived.id }])).toBeUndefined();
3036
expect(pullRequestAgentThread([thread, archived], archived.id)).toBe(archived);
37+
const actions = pullRequestAgentThreadActions([settled, archived], "ask", true);
38+
expect(actions.map((action) => action.title)).toEqual([
39+
"Start a new thread",
40+
"Existing work",
41+
"Settled threads",
42+
]);
43+
expect(actions[2]?.subactions).toMatchObject([
44+
{ id: `ask:${settled.id}`, subtitle: "Settled thread" },
45+
]);
46+
expect(pullRequestAgentThreadActions([thread], "ask", false)).toMatchObject([
47+
{ id: `ask:${thread.id}`, subtitle: "Continue thread" },
48+
]);
49+
expect(
50+
pullRequestAgentThreadActions([settled], "feedback", false)[0]?.subactions,
51+
).toMatchObject([{ id: `feedback:${settled.id}`, attributes: { disabled: false } }]);
52+
expect(pullRequestAgentThreadActions([archived], "feedback", true)[1]).toMatchObject({
53+
attributes: { disabled: true },
54+
});
3155
});
3256
it("replaces the helper's own text when switching tasks, keeping user edits", () => {
3357
const first = appendPullRequestAgentPrompt("My question", "explain", GITHUB);

‎apps/mobile/src/features/pull-requests/pullRequestAgentTasks.ts‎

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {
22
sourceControlClients,
33
type ChangeRequestTerminology,
44
} from "@t3tools/client-runtime/source-control-clients";
5+
import type { MenuAction } from "@react-native-menu/menu";
56
import type { PullRequestDetail, PullRequestLinkedThreadsResult } from "@t3tools/contracts";
67

78
export type PullRequestAgentTask = "ask" | "explain" | "feedback" | "conflicts" | "watch";
@@ -11,7 +12,39 @@ export function pullRequestAgentThread(
1112
threadId?: string,
1213
) {
1314
if (threadId) return threads.find((thread) => thread.id === threadId);
14-
return threads.length === 1 ? threads[0] : undefined;
15+
return threads.length === 1 && !threads[0]?.settled && !threads[0]?.archivedAt
16+
? threads[0]
17+
: undefined;
18+
}
19+
20+
export function pullRequestAgentThreadActions(
21+
threads: PullRequestLinkedThreadsResult["threads"],
22+
task: PullRequestAgentTask,
23+
canAsk: boolean,
24+
): MenuAction[] {
25+
const active: MenuAction[] = [];
26+
const settled: MenuAction[] = [];
27+
for (const thread of threads) {
28+
const action = {
29+
id: `${task}:${thread.id}`,
30+
title: thread.title,
31+
subtitle: thread.archivedAt
32+
? "Archived thread"
33+
: thread.settled
34+
? "Settled thread"
35+
: "Continue thread",
36+
image: "bubble.left.and.bubble.right",
37+
attributes: { disabled: task !== "ask" && Boolean(thread.archivedAt) },
38+
};
39+
(thread.settled ? settled : active).push(action);
40+
}
41+
return [
42+
...(canAsk ? [{ id: `${task}:new`, title: "Start a new thread", image: "plus" }] : []),
43+
...active,
44+
...(settled.length
45+
? [{ id: `${task}:settled`, title: "Settled threads", subactions: settled }]
46+
: []),
47+
];
1548
}
1649

1750
export function pullRequestAgentPrompt(

‎apps/mobile/src/features/pull-requests/usePullRequestAgentActions.ts‎

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { Platform } from "react-native";
12
import type { PullRequestDetail } from "@t3tools/contracts";
23
import {
34
pullRequestAgentActions,
45
pullRequestAgentThread,
6+
pullRequestAgentThreadActions,
57
type PullRequestAgentTask,
68
} from "./pullRequestAgentTasks";
79
import type { PullRequestParams } from "./usePullRequestDiff";
@@ -28,24 +30,30 @@ export function usePullRequestAgentActions(
2830
if (!links.canAsk || actions.find((action) => action.task === task)?.disabled) return;
2931
void links.ask(thread?.archivedAt ? undefined : thread, task);
3032
};
31-
const threadActions = (task: PullRequestAgentTask) => [
32-
...links.threads.map((thread) => ({
33-
id: `${task}:${thread.id}`,
34-
title: thread.title,
35-
subtitle: thread.archivedAt ? "Archived thread" : "Continue thread",
36-
image: "bubble.left.and.bubble.right",
37-
attributes: { disabled: task !== "ask" && Boolean(thread.archivedAt) },
38-
})),
39-
...(links.canAsk ? [{ id: `${task}:new`, title: "Start a new thread", image: "plus" }] : []),
40-
];
33+
const chooseThread =
34+
links.threads.length > 1 || links.threads.some((thread) => thread.settled || thread.archivedAt);
35+
const threadActions = (task: PullRequestAgentTask) =>
36+
pullRequestAgentThreadActions(links.threads, task, links.canAsk);
4137
const menuAction = (task: PullRequestAgentTask) => {
4238
const action = actions.find((action) => action.task === task);
39+
const items = threadActions(task);
40+
// Android supports only one submenu level beneath each helper action.
41+
const subactions =
42+
Platform.OS === "android"
43+
? items.flatMap(
44+
(item) =>
45+
item.subactions?.map((child) => ({
46+
...child,
47+
title: `Settled: ${child.title}`,
48+
})) ?? [item],
49+
)
50+
: items;
4351
return {
4452
id: task,
4553
title: action?.title ?? "Open thread",
4654
image: action?.icon,
4755
attributes: { disabled: disabled || !links.canAsk || action?.disabled },
48-
...(links.threads.length > 1 ? { subactions: threadActions(task) } : {}),
56+
...(chooseThread ? { subactions } : {}),
4957
};
5058
};
5159
const select = (event: string) => {
@@ -55,5 +63,5 @@ export function usePullRequestAgentActions(
5563
if (action)
5664
start(action.task, event === action.task ? undefined : event.slice(action.task.length + 1));
5765
};
58-
return { ...links, actions, disabled, start, threadActions, menuAction, select };
66+
return { ...links, actions, disabled, chooseThread, start, threadActions, menuAction, select };
5967
}

‎apps/server/src/pullRequest/linkedThreads.test.ts‎

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { listLinkedPullRequestThreads } from "./linkedThreads.ts";
99
const encodePayload = Schema.encodeEffect(Schema.fromJsonString(Schema.Unknown));
1010

1111
it.effect(
12-
"finds active and archived threads for exactly one pull request, excluding deleted, dismissed, and side chat links",
12+
"finds active, settled, and archived threads for exactly one pull request, excluding deleted, dismissed, and side chat links",
1313
() =>
1414
Effect.gen(function* () {
1515
const sql = yield* SqlClient.SqlClient;
@@ -46,6 +46,14 @@ it.effect(
4646
number: 7,
4747
source: "manual",
4848
},
49+
{ id: "settled", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
50+
{
51+
id: "auto-settled",
52+
host: "github.com",
53+
repository: "acme/web",
54+
number: 7,
55+
source: "manual",
56+
},
4957
{ id: "active", host: "github.com", repository: "acme/web", number: 7, source: "manual" },
5058
{
5159
id: "archived",
@@ -94,6 +102,8 @@ it.effect(
94102
for (const fixture of fixtures) {
95103
const payload = yield* encodePayload({
96104
linkedPullRequest: null,
105+
settledOverride: ["settled", "archived"].includes(fixture.id) ? "settled" : null,
106+
settledAt: fixture.id === "auto-settled" ? archivedAt : null,
97107
...(fixture.id === "side-chat" ? { lineage: { sideChat: true } } : {}),
98108
pullRequests: [{ ...fixture, linkedAt: createdAt, snapshot: null, stack: null }],
99109
});
@@ -165,8 +175,28 @@ it.effect(
165175
});
166176
expect(result).toEqual({
167177
threads: [
168-
{ id: "archived", projectId: "project-1", title: "archived", archivedAt },
169-
{ id: "active", projectId: "project-1", title: "active", archivedAt: null },
178+
{ id: "archived", projectId: "project-1", title: "archived", archivedAt, settled: true },
179+
{
180+
id: "active",
181+
projectId: "project-1",
182+
title: "active",
183+
archivedAt: null,
184+
settled: false,
185+
},
186+
{
187+
id: "auto-settled",
188+
projectId: "project-1",
189+
title: "auto-settled",
190+
archivedAt: null,
191+
settled: true,
192+
},
193+
{
194+
id: "settled",
195+
projectId: "project-1",
196+
title: "settled",
197+
archivedAt: null,
198+
settled: true,
199+
},
170200
],
171201
});
172202
assert.deepStrictEqual(

‎apps/server/src/pullRequest/linkedThreads.ts‎

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ export const listLinkedPullRequestThreads = Effect.fn("listLinkedPullRequestThre
2323
projectId: string;
2424
title: string;
2525
archivedAt: string | null;
26+
settled: number;
2627
host: string;
2728
repository: string;
2829
number: number;
2930
url: string;
3031
}>`
3132
SELECT t.thread_id AS id, t.project_id AS "projectId", t.title,
32-
t.archived_at AS "archivedAt", json_extract(link.value, '$.host') AS host,
33+
t.archived_at AS "archivedAt",
34+
(json_extract(t.payload_json, '$.settledAt') IS NOT NULL
35+
OR json_extract(t.payload_json, '$.settledOverride') IS 'settled') AS settled,
36+
json_extract(link.value, '$.host') AS host,
3337
json_extract(link.value, '$.repository') AS repository,
3438
json_extract(link.value, '$.number') AS number,
3539
json_extract(link.value, '$.url') AS url,
@@ -44,7 +48,13 @@ export const listLinkedPullRequestThreads = Effect.fn("listLinkedPullRequestThre
4448
`.pipe(NodeSqliteClient.readOnly);
4549
const threads = rows
4650
.filter((row) => threadPullRequestKeysEqual(row, key))
47-
.map(({ id, projectId, title, archivedAt }) => ({ id, projectId, title, archivedAt }));
51+
.map(({ id, projectId, title, archivedAt, settled }) => ({
52+
id,
53+
projectId,
54+
title,
55+
archivedAt,
56+
settled: settled === 1,
57+
}));
4858
return yield* decodeLinkedThreads({ threads });
4959
},
5060
Effect.mapError(

‎packages/contracts/src/pullRequest.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,7 @@ export const PullRequestLinkedThreadsResult = Schema.Struct({
453453
projectId: ProjectId,
454454
title: Schema.String,
455455
archivedAt: Schema.NullOr(IsoDateTime),
456+
settled: Schema.optionalKey(Schema.Boolean),
456457
}),
457458
),
458459
});

0 commit comments

Comments
 (0)