Skip to content

Commit 861b362

Browse files
committed
feat(mobile): open a thread's pull requests from its list badge
Tapping the PR badge on a thread row opens the pull request directly. A thread with a stack or several linked pull requests opens a new Linked pull requests sheet that lists them in stack order; the Git sheet renders the same shared list.
1 parent fc43d38 commit 861b362

21 files changed

Lines changed: 505 additions & 153 deletions

‎apps/mobile/src/Stack.tsx‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { GitBranchesSheet } from "./features/threads/git/GitBranchesSheet";
6666
import { GitCommitSheet } from "./features/threads/git/GitCommitSheet";
6767
import { GitConfirmSheet } from "./features/threads/git/GitConfirmSheet";
6868
import { GitOverviewSheet } from "./features/threads/git/GitOverviewSheet";
69+
import { ThreadPullRequestsSheet } from "./features/threads/ThreadPullRequestsSheet";
6970
import { ThreadAgentsSheet } from "./features/threads/ThreadAgentsSheet";
7071
import { ThreadQueueSheet } from "./features/threads/ThreadQueueControl";
7172
import { ThreadRouteScreen } from "./features/threads/ThreadRouteScreen";
@@ -549,6 +550,7 @@ const WORKSPACE_OVERLAY_ROUTES = new Set([
549550
"SettingsLegal",
550551
"SettingsSheet",
551552
"ThreadAgents",
553+
"ThreadPullRequests",
552554
"ThreadQueue",
553555
"ThreadReviewComment",
554556
"ThreadDevicePreview",
@@ -868,6 +870,15 @@ const RootStackConfig = createWorkspaceStackNavigator({
868870
sheetGrabberVisible: true,
869871
},
870872
}),
873+
ThreadPullRequests: createNativeStackScreen({
874+
screen: ThreadPullRequestsSheet,
875+
linking: `${THREAD_LINKING_PREFIX}/pull-requests`,
876+
options: {
877+
...FORM_SHEET_PRESENTATION_OPTIONS,
878+
sheetAllowedDetents: [0.55, 0.92],
879+
sheetGrabberVisible: true,
880+
},
881+
}),
871882
GitCommit: createNativeStackScreen({
872883
screen: GitCommitSheet,
873884
linking: `${THREAD_LINKING_PREFIX}/git/commit`,

‎apps/mobile/src/features/home/HomeScreen.tsx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ import {
5858
ThreadListV2WorkingShelfHeader,
5959
} from "../threads/thread-list-v2-items";
6060
import { useThreadRowProviderInstanceResolver } from "../threads/thread-provider-instance";
61+
import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
62+
import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
6163
import {
6264
buildThreadListV2Items,
6365
getThreadListV2OrderedSection,
@@ -314,6 +316,14 @@ export function HomeScreen(props: HomeScreenProps) {
314316
const handleScrollBeginDrag = useCallback(() => {
315317
openSwipeableRef.current?.close();
316318
}, []);
319+
const openThreadPullRequests = useOpenThreadPullRequests();
320+
const handleOpenThreadPullRequests = useCallback(
321+
(thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
322+
openSwipeableRef.current?.close();
323+
openThreadPullRequests(thread, pr);
324+
},
325+
[openThreadPullRequests],
326+
);
317327
const onFabScroll = useFabScroll();
318328
const listRef = useRef<LegendListRef>(null);
319329
const searchMode = workspace?.state.tabs.threads.searchMode;
@@ -753,6 +763,7 @@ export function HomeScreen(props: HomeScreenProps) {
753763
)}
754764
searchQuery={props.searchQuery}
755765
onSelectThread={props.onSelectThread}
766+
onOpenThreadPullRequests={handleOpenThreadPullRequests}
756767
onDeleteThread={handleDeleteThread}
757768
onArchiveThread={props.onArchiveThread}
758769
onRenameThread={handleRenameThread}
@@ -786,6 +797,7 @@ export function HomeScreen(props: HomeScreenProps) {
786797
},
787798
[
788799
handleDeleteThread,
800+
handleOpenThreadPullRequests,
789801
activeReorderEnvironmentIds,
790802
handleMoveThread,
791803
handlePinThread,

‎apps/mobile/src/features/layout/AdaptiveWorkspaceLayout.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import { AndroidWorkspaceSidebar } from "../workspace/AndroidWorkspaceSidebar";
6666
import { useAndroidWorkspaceSelection } from "../workspace/useAndroidWorkspaceSelection";
6767
import { HomeListOptionsProvider } from "../home/home-list-options";
6868
import { ThreadNavigationSidebar } from "../threads/ThreadNavigationSidebar";
69+
import { useOpenThreadPullRequests } from "../threads/use-open-thread-pull-requests";
6970
import { RenderErrorBoundary, RenderFailureView } from "../../components/RenderErrorBoundary";
7071
import { WORKSPACE_PANE_TIMING } from "./workspace-pane-animation";
7172
import { WorkspaceInspectorPane } from "./workspace-inspector-pane";
@@ -440,6 +441,8 @@ function AdaptiveWorkspaceLayoutContent(
440441
});
441442
}, [navigation]);
442443

444+
const handleOpenThreadPullRequests = useOpenThreadPullRequests();
445+
443446
const handleNewThreadOnBranch = useCallback(
444447
(thread: EnvironmentThreadShell) => {
445448
navigation.navigate("NewTaskSheet", {
@@ -718,6 +721,7 @@ function AdaptiveWorkspaceLayoutContent(
718721
onNewThreadInProject={handleNewThreadInProject}
719722
onNewThreadOnBranch={handleNewThreadOnBranch}
720723
onSelectThread={handleSelectThread}
724+
onOpenThreadPullRequests={handleOpenThreadPullRequests}
721725
onSearchQueryChange={setPrimarySidebarSearchQuery}
722726
searchQuery={primarySidebarSearchQuery}
723727
/>

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

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import {
1818
pullRequestListRowsAreEqual,
1919
type EnvironmentPullRequestListEntry,
2020
} from "./pullRequestList";
21-
import { pullRequestStatus } from "./pullRequestStatus";
21+
import { pullRequestChecksStatus, pullRequestStatus } from "./pullRequestStatus";
2222
import { PullRequestGlyph } from "./pullRequestGlyphs";
2323

2424
export const PullRequestListRow = memo(
@@ -49,12 +49,7 @@ export const PullRequestListRow = memo(
4949
: "text-foreground-tertiary";
5050
const status = pullRequestStatus(item);
5151
const review = pullRequestListReviewStatus(item);
52-
const checkTint =
53-
item.checksState === "passing"
54-
? "accent-adaptive-emerald-600-400"
55-
: item.checksState === "failing"
56-
? "accent-danger-foreground"
57-
: "accent-warning-foreground";
52+
const checks = item.checksState ? pullRequestChecksStatus(item.checksState) : null;
5853
return (
5954
<View style={props.sidebar ? THREAD_LIST_V2_SIDEBAR_ROW_CONTAINER_STYLE : undefined}>
6055
<Menu
@@ -156,19 +151,9 @@ export const PullRequestListRow = memo(
156151
</Text>
157152
) : null}
158153
</View>
159-
{item.checksState ? (
154+
{checks ? (
160155
<View className="shrink-0" accessibilityLabel={`Checks ${item.checksState}`}>
161-
<SymbolView
162-
name={
163-
item.checksState === "passing"
164-
? "checkmark.circle"
165-
: item.checksState === "failing"
166-
? "xmark.circle.fill"
167-
: "clock"
168-
}
169-
size={13}
170-
tintColorClassName={checkTint}
171-
/>
156+
<SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
172157
</View>
173158
) : null}
174159
{review ? (

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import type {
22
PullRequestActivity,
33
PullRequestCheck,
4+
PullRequestChecksState,
45
PullRequestDetail,
56
PullRequestListEntry,
67
} from "@t3tools/contracts";
@@ -201,3 +202,11 @@ export function pullRequestBranchSummary(
201202
if (pr.baseComparison === "up-to-date") return "Up to date";
202203
return pr.mergeability === "mergeable" ? "No conflicts" : "Not reported";
203204
}
205+
206+
export function pullRequestChecksStatus(state: PullRequestChecksState) {
207+
if (state === "passing")
208+
return { icon: "checkmark.circle", tint: "accent-adaptive-emerald-600-400" } as const;
209+
if (state === "failing")
210+
return { icon: "xmark.circle.fill", tint: "accent-danger-foreground" } as const;
211+
return { icon: "clock", tint: "accent-warning-foreground" } as const;
212+
}
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
import type { EnvironmentThreadShell } from "@t3tools/client-runtime/state/shell";
2+
import {
3+
pullRequestListLines,
4+
resolveThreadPullRequestChains,
5+
type PullRequestListLine,
6+
} from "@t3tools/shared/threadPullRequests";
7+
import { memo, useMemo } from "react";
8+
import { Pressable, View } from "react-native";
9+
10+
import { SymbolView } from "../../components/ui/AppSymbol";
11+
import { AppText as Text } from "../../components/ui/AppText";
12+
import * as Dialog from "../../components/ui/Dialog";
13+
import { cn } from "../../lib/cn";
14+
import { relativeTime } from "../../lib/time";
15+
import type { EnvironmentRuntimeState } from "../../state/remote-runtime-types";
16+
import { PullRequestGlyph } from "../pull-requests/pullRequestGlyphs";
17+
import { pullRequestListReviewStatus } from "../pull-requests/pullRequestList";
18+
import { PullRequestAvatar, PullRequestDiffStats } from "../pull-requests/PullRequestPresentation";
19+
import { pullRequestChecksStatus, pullRequestStatus } from "../pull-requests/pullRequestStatus";
20+
21+
export function useLinkedPullRequestLines(
22+
thread: EnvironmentThreadShell | null,
23+
runtime: EnvironmentRuntimeState | null,
24+
) {
25+
const supported = runtime?.serverConfig?.environment.capabilities.threadPullRequests === true;
26+
const pullRequests = thread?.pullRequests;
27+
return useMemo(() => {
28+
const chains = resolveThreadPullRequestChains(supported ? (pullRequests ?? []) : []);
29+
const open = chains.filter((chain) => chain.layers.some(isOpenLink));
30+
const done = chains.filter((chain) => !chain.layers.some(isOpenLink));
31+
return [...pullRequestListLines(open), ...pullRequestListLines(done)];
32+
}, [pullRequests, supported]);
33+
}
34+
35+
function isOpenLink(link: PullRequestListLine["link"]) {
36+
return link.snapshot === null || link.snapshot.state === "open";
37+
}
38+
39+
export function linkedPullRequestKey(line: PullRequestListLine) {
40+
return `${line.link.host}/${line.link.repository}#${line.link.number}`;
41+
}
42+
43+
export const LinkedPullRequestRow = memo(function LinkedPullRequestRow(props: {
44+
readonly line: PullRequestListLine;
45+
readonly separator: boolean;
46+
readonly openPullRequest: (url: string) => Promise<boolean>;
47+
}) {
48+
const { link, depth, stack } = props.line;
49+
const snapshot = link.snapshot;
50+
const status = snapshot === null ? null : pullRequestStatus(snapshot);
51+
const open = snapshot === null || snapshot.state === "open";
52+
const checks =
53+
open && snapshot?.checksState ? pullRequestChecksStatus(snapshot.checksState) : null;
54+
const review =
55+
open && snapshot?.reviewDecision
56+
? pullRequestListReviewStatus({
57+
reviewDecision: snapshot.reviewDecision,
58+
viewerReviewRequested: false,
59+
})
60+
: null;
61+
const watching = open && link.watch !== undefined;
62+
const additions = snapshot?.additions ?? 0;
63+
const deletions = snapshot?.deletions ?? 0;
64+
return (
65+
<Pressable
66+
accessibilityRole="button"
67+
accessibilityLabel={`Pull request ${link.number}, ${snapshot?.title ?? "waiting for host state"}${status ? `, ${status.label}` : ""}, ${link.repository}${stack ? `, stack of ${stack.size}` : ""}${watching ? ", watching" : ""}`}
68+
onPress={() => {
69+
void props.openPullRequest(link.url).then((opened) => {
70+
if (!opened) Dialog.alert("Unable to open PR", "The pull request could not be opened.");
71+
});
72+
}}
73+
// Steps in per layer like the web list, capped so deep stacks keep their width.
74+
style={{ paddingLeft: 16 + Math.min(depth, 3) * 16 }}
75+
className="flex-row gap-3 pr-4 active:bg-row-hover"
76+
>
77+
{depth > 0 ? <View className="-ml-2 w-px self-stretch bg-border" /> : null}
78+
<View className="self-start pt-2.5">
79+
<SymbolView
80+
name={status?.icon ?? PullRequestGlyph.pullRequest}
81+
size={20}
82+
tintColorClassName={status?.tint ?? "accent-icon-muted"}
83+
/>
84+
</View>
85+
<View
86+
className={cn(
87+
"min-w-0 flex-1 gap-1 py-2.5",
88+
props.separator && "border-b border-border-subtle",
89+
)}
90+
>
91+
<View className="flex-row items-center gap-1.5">
92+
{snapshot?.author ? <PullRequestAvatar actor={snapshot.author} size={16} /> : null}
93+
<Text className="min-w-0 shrink text-xs text-foreground-muted" numberOfLines={1}>
94+
{link.repository}
95+
</Text>
96+
<Text className="shrink-0 text-xs text-foreground-tertiary">#{link.number}</Text>
97+
<View className="flex-1" />
98+
{stack ? (
99+
<View className="flex-row items-center gap-1">
100+
<SymbolView
101+
name={PullRequestGlyph.stack}
102+
size={12}
103+
tintColorClassName="accent-foreground-muted"
104+
/>
105+
<Text className="text-2xs tabular-nums text-foreground-muted">{stack.size}</Text>
106+
</View>
107+
) : null}
108+
{watching ? (
109+
<SymbolView name="eye" size={13} tintColorClassName="accent-foreground-muted" />
110+
) : null}
111+
{checks ? (
112+
<SymbolView name={checks.icon} size={13} tintColorClassName={checks.tint} />
113+
) : null}
114+
{review ? (
115+
<SymbolView name={review.icon} size={13} tintColorClassName={review.tint} />
116+
) : null}
117+
{additions + deletions > 0 ? (
118+
<PullRequestDiffStats additions={additions} deletions={deletions} compact />
119+
) : null}
120+
{snapshot?.updatedAt ? (
121+
<Text className="text-2xs tabular-nums text-foreground-tertiary">
122+
{relativeTime(snapshot.updatedAt)}
123+
</Text>
124+
) : null}
125+
</View>
126+
<Text
127+
className="text-base leading-5 font-t3-medium text-foreground"
128+
numberOfLines={2}
129+
ellipsizeMode="tail"
130+
>
131+
{snapshot?.title ?? "Waiting for host state"}
132+
</Text>
133+
</View>
134+
</Pressable>
135+
);
136+
});

‎apps/mobile/src/features/threads/ThreadNavigationSidebar.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import {
6565
ThreadListV2WorkingShelfHeader,
6666
} from "./thread-list-v2-items";
6767
import { useThreadRowProviderInstanceResolver } from "./thread-provider-instance";
68+
import type { ThreadPrPresentation } from "../../state/thread-pr-presentation";
6869
import {
6970
buildThreadListV2Items,
7071
getThreadListV2OrderedSection,
@@ -93,6 +94,10 @@ interface ThreadNavigationSidebarProps {
9394
readonly onNewThreadInProject: (project: EnvironmentProject) => void;
9495
readonly onSearchQueryChange: (query: string) => void;
9596
readonly onSelectThread: (thread: EnvironmentThreadShell) => void;
97+
readonly onOpenThreadPullRequests: (
98+
thread: EnvironmentThreadShell,
99+
pr: ThreadPrPresentation,
100+
) => void;
96101
readonly onRequestVisibility: () => void;
97102
readonly searchQuery: string;
98103
}
@@ -557,6 +562,13 @@ function ThreadNavigationSidebarPane(
557562
},
558563
[props.onSelectThread],
559564
);
565+
const handleOpenThreadPullRequests = useCallback(
566+
(thread: EnvironmentThreadShell, pr: ThreadPrPresentation) => {
567+
props.onOpenThreadPullRequests(thread, pr);
568+
openSwipeableRef.current?.close();
569+
},
570+
[props.onOpenThreadPullRequests],
571+
);
560572
const handleScrollBeginDrag = useCallback(() => {
561573
openSwipeableRef.current?.close();
562574
}, []);
@@ -684,6 +696,7 @@ function ThreadNavigationSidebarPane(
684696
}
685697
fullSwipeWidth={props.width - 20}
686698
onSelectThread={handleSelectThread}
699+
onOpenThreadPullRequests={handleOpenThreadPullRequests}
687700
onDeleteThread={confirmDeleteThread}
688701
onArchiveThread={archiveThread}
689702
onRenameThread={renameThread}
@@ -759,6 +772,7 @@ function ThreadNavigationSidebarPane(
759772
activeReorderEnvironmentIds,
760773
confirmDeletePendingTask,
761774
confirmDeleteThread,
775+
handleOpenThreadPullRequests,
762776
handleSelectThread,
763777
handleSwipeableClose,
764778
handleSwipeableWillOpen,

0 commit comments

Comments
 (0)