Repository navigation
Expand file tree
/
Copy pathThreadPullRequestsPanel.tsx
More file actions
771 lines (755 loc) · 28.2 KB
/
Copy pathThreadPullRequestsPanel.tsx
File metadata and controls
771 lines (755 loc) · 28.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
import { canStartThreadPullRequestWatch } from "@t3tools/client-runtime/thread-pull-request-compatibility";
import type {
DevinReviewSummary,
ProjectId,
ScopedThreadRef,
ThreadPullRequestLink,
} from "@t3tools/contracts";
import {
sourceControlClients,
UNKNOWN_SOURCE_CONTROL_CLIENT,
} from "@t3tools/client-runtime/source-control-clients";
import {
PULL_REQUEST_WATCH_FOLLOW_UP_LIMIT,
pullRequestWatchStatusLabel,
} from "@t3tools/shared/pullRequestWatch";
import {
pullRequestListLines,
visibleThreadPullRequests,
type PullRequestListLine,
} from "@t3tools/client-runtime/thread-pull-requests";
import {
ArrowUpRightIcon,
EyeIcon,
EyeOffIcon,
LinkIcon,
MoreHorizontalIcon,
PauseIcon,
PlayIcon,
PlusIcon,
} from "lucide-react";
import { LegendList } from "@legendapp/list/react";
import { msg, T, useGT, useMessages, Var } from "gt-react";
import { memo, useState } from "react";
import {
COMPOSER_PULL_REQUEST_DRAG_TYPE,
encodePullRequestDragPayload,
} from "~/components/chat/composerMentionDrag";
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
import { findProjectForChangeRequest } from "@t3tools/client-runtime/change-request-links";
import { pullRequestLinkPanelTarget, useOpenPrLink } from "~/lib/openPullRequestLink";
import { useClientSettings } from "~/hooks/useSettings";
import { usePrimaryEnvironmentId } from "~/state/environments";
import { usePullRequestIntentPrefetch } from "./usePullRequestIntentPrefetch";
import { cn } from "~/lib/utils";
import { useShortcutModifierState } from "~/shortcutModifierState";
import { useProjects, useServerConfigs, useThreadShell } from "~/state/entities";
import { openPullRequestDevinReview } from "~/rightPanelStore";
import { devinReviewEnvironment } from "~/state/devinReview";
import { useEnvironmentQuery } from "~/state/query";
import { DevinIcon } from "../Icons";
import { Badge } from "../ui/badge";
import {
devinReviewFindingCountLabel,
devinReviewStatusPresentation,
devinReviewSummaryHasNews,
devinReviewSummaryKey,
devinReviewablePullRequests,
} from "../devinReview/devinReview.logic";
import { PullRequestChangeBreakdownStat } from "./PullRequestChangeBreakdownStat";
import { PullRequestsUnavailableState } from "./PullRequestsUnavailableState";
import { threadEnvironment } from "~/state/threads";
import { useAtomCommand } from "~/state/use-atom-command";
import { RelativeTime } from "~/components/RelativeTime";
import { ThreadDetailsIssueRows } from "../chat/ThreadDetailsIssueRows";
import { Button } from "../ui/button";
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
import { MiddleTruncate } from "../ui/middle-truncate";
import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
import { openLinkPullRequestDialog } from "./LinkPullRequestDialog";
import {
PULL_REQUEST_ROW_CLASS,
PULL_REQUEST_ROW_NUMBER_CLASS,
PullRequestRowAuthor,
PullRequestRowBranches,
PullRequestRowGlyph,
PullRequestRowLines,
} from "./PullRequestListRow";
import {
PullRequestDiffStat,
PullRequestReviewDecisionGlyph,
pullRequestChecksStatePresentation,
} from "./pullRequestPresentation";
import { PullRequestGlyph } from "./pullRequestIcons";
import { pullRequestQuickActions } from "./pullRequestList.logic";
import { PullRequestSpeedActions, PullRequestSpeedModeContext } from "./PullRequestSpeedActions";
import { changeRequestTermKind } from "./changeRequestTerm";
const SOURCE_LABELS: Record<ThreadPullRequestLink["source"], string> = {
manual: msg("Linked by you"),
created: msg("Created from this thread"),
agent: msg("Linked by the agent"),
stack: msg("Found in the stack"),
"stack-dismissed": msg("Dismissed", { $context: "pull request link source" }),
};
function ChecksGlyph({
state,
}: {
state: NonNullable<ThreadPullRequestLink["snapshot"]>["checksState"] & string;
}) {
const resolve = useMessages();
const presentation = pullRequestChecksStatePresentation(state, resolve);
return (
<Tooltip>
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
<presentation.Icon
role="img"
aria-label={presentation.label}
className={cn("size-3.5", presentation.toneClassName)}
/>
</TooltipTrigger>
<TooltipPopup>{presentation.label}</TooltipPopup>
</Tooltip>
);
}
type WatchAction = "watch" | "pause" | "resume" | "stop";
/** Devin's status and open findings for one row; opens the pull request on its Devin Review tab. */
function DevinReviewRowBadge(props: { summary: DevinReviewSummary; onOpen: () => void }) {
const { summary } = props;
const gt = useGT();
const resolve = useMessages();
const status = devinReviewStatusPresentation(summary, resolve);
const findings = devinReviewFindingCountLabel(
summary.openFindingCount,
summary.findingCount,
resolve,
);
return (
<Tooltip>
<TooltipTrigger
render={
<Badge
size="sm"
variant={status.variant}
render={<button type="button" />}
aria-label={gt("Devin Review: {status}, {findings}", {
status: status.label,
findings,
})}
onClick={props.onOpen}
/>
}
>
<DevinIcon aria-hidden />
{summary.openFindingCount > 0 ? (
<span className="tabular-nums">{summary.openFindingCount}</span>
) : null}
</TooltipTrigger>
<TooltipPopup>
{gt("Devin Review: {status} · {findings}", { status: status.label, findings })}
</TooltipPopup>
</Tooltip>
);
}
/** Fork: what an open pull request's watch is waiting on, with the follow-ups it has spent. */
function WatchStatusLine({ line: { link, depth } }: { line: PullRequestListLine }) {
const gt = useGT();
const watch = link.watch;
if (watch === undefined || (link.snapshot !== null && link.snapshot.state !== "open")) {
return null;
}
return (
<div
className="flex items-center gap-1.5 pr-2 pb-1 text-2xs text-muted-foreground"
style={{ paddingLeft: `${2 + Math.min(depth, 8) * 0.75}rem` }}
>
{watch.paused === true ? (
<PauseIcon aria-label={gt("Watch paused")} className="size-3 shrink-0" />
) : (
<EyeIcon aria-label={gt("Watching")} className="size-3 shrink-0" />
)}
<span className="min-w-0 truncate">{pullRequestWatchStatusLabel(watch, link.snapshot)}</span>
<span className="ml-auto shrink-0 tabular-nums">
{gt("{used}/{limit} follow-ups", {
used: watch.followUps ?? 0,
limit: PULL_REQUEST_WATCH_FOLLOW_UP_LIMIT,
})}
</span>
</div>
);
}
function LinkRowImpl({
line,
threadRef,
projectId,
speedMode,
onUnlink,
onWatch,
onIntent,
canPause,
canStartWatch,
devinSummary,
}: {
line: PullRequestListLine;
threadRef: ScopedThreadRef;
projectId: ProjectId | null;
speedMode: boolean;
onUnlink: (link: ThreadPullRequestLink) => void;
/** Null when the environment cannot watch pull requests. */
onWatch: ((link: ThreadPullRequestLink, action: WatchAction) => void) | null;
/** The environment can pause a watch, and shows its status line (fork servers). */
canPause: boolean;
onIntent: (link: ThreadPullRequestLink | null) => void;
canStartWatch: boolean;
/** Shown only when Devin has something to say about the pull request. */
devinSummary: DevinReviewSummary | null;
}) {
const gt = useGT();
const resolve = useMessages();
const openPrLink = useOpenPrLink(threadRef);
const [menuOpen, setMenuOpen] = useState(false);
const [menuPosition, setMenuPosition] = useState<{ x: number; y: number } | null>(null);
const menuAnchor = menuPosition
? { getBoundingClientRect: () => new DOMRect(menuPosition.x, menuPosition.y, 0, 0) }
: undefined;
const { link, depth, stack } = line;
const snapshot = link.snapshot;
const open = snapshot === null || snapshot.state === "open";
const watching = link.watch !== undefined;
const paused = link.watch?.paused === true;
const linkHost =
sourceControlClients.findByChangeRequestUrl(link.url) ?? UNKNOWN_SOURCE_CONTROL_CLIENT;
const linkHostActions = linkHost.changeRequestActions;
const actionEntry =
projectId !== null && snapshot !== null && snapshot.state !== "merged"
? {
environmentId: threadRef.environmentId,
projectId,
host: link.host,
repository: link.repository,
number: link.number,
state: snapshot.state,
isDraft: snapshot.isDraft,
...(link.stack === null ? {} : { stack: link.stack }),
}
: null;
const hasQuickActions =
actionEntry !== null && pullRequestQuickActions(actionEntry, linkHostActions).length > 0;
return (
<div
className={cn(PULL_REQUEST_ROW_CLASS, "relative hover:bg-accent/60")}
onPointerEnter={() => onIntent(link)}
onPointerLeave={(event) => {
if (!event.currentTarget.contains(document.activeElement)) onIntent(null);
}}
onFocus={() => onIntent(link)}
onBlur={(event) => {
if (!event.currentTarget.matches(":hover")) onIntent(null);
}}
onContextMenu={(event) => {
event.preventDefault();
event.stopPropagation();
setMenuPosition({ x: event.clientX, y: event.clientY });
setMenuOpen(true);
}}
style={{ paddingLeft: `${0.5 + Math.min(depth, 8) * 0.75}rem` }}
>
{depth > 0 ? <span aria-hidden className="-ml-2 h-6 w-px shrink-0 bg-border/70" /> : null}
{snapshot === null ? (
<PullRequestGlyph.pullRequest
aria-label={gt("Waiting for host state")}
className="size-4 shrink-0 text-muted-foreground"
/>
) : (
<PullRequestRowGlyph
state={snapshot.state}
isDraft={snapshot.isDraft}
mergeability={snapshot.mergeability}
baseBranch={snapshot.baseBranch}
/>
)}
<a
href={link.url}
onClick={(event) => openPrLink(event, link.url, threadRef)}
// Outside drops use the URL; the composer uses this context-chip payload.
onDragStart={
snapshot === null
? undefined
: (event) =>
event.dataTransfer.setData(
COMPOSER_PULL_REQUEST_DRAG_TYPE,
encodePullRequestDragPayload({
number: link.number,
title: snapshot.title,
url: link.url,
headBranch: snapshot.headBranch,
baseBranch: snapshot.baseBranch,
state: snapshot.state,
isDraft: snapshot.isDraft,
}),
)
}
className="flex min-w-0 flex-1"
>
<PullRequestRowLines
number={
<Tooltip>
<TooltipTrigger render={<span className={PULL_REQUEST_ROW_NUMBER_CLASS} />}>
#{link.number}
</TooltipTrigger>
<TooltipPopup>
{resolve(SOURCE_LABELS[link.source])} · <RelativeTime timestamp={link.linkedAt} />
</TooltipPopup>
</Tooltip>
}
title={snapshot?.title ?? link.repository}
signals={
open ? (
<>
{watching && !canPause ? (
<Tooltip>
<TooltipTrigger render={<span className="inline-flex shrink-0" />}>
<EyeIcon role="img" aria-label={gt("Watching")} className="size-3.5" />
</TooltipTrigger>
<TooltipPopup>
<T>
Watching: the agent wakes when checks finish, someone comments, or the
branch conflicts
</T>
</TooltipPopup>
</Tooltip>
) : null}
{snapshot?.checksState ? <ChecksGlyph state={snapshot.checksState} /> : null}
{snapshot?.reviewDecision ? (
<PullRequestReviewDecisionGlyph decision={snapshot.reviewDecision} />
) : null}
</>
) : null
}
status={
projectId === null ? (
<PullRequestDiffStat
additions={snapshot?.additions ?? 0}
deletions={snapshot?.deletions ?? 0}
className="font-mono"
/>
) : (
<PullRequestChangeBreakdownStat
environmentId={threadRef.environmentId}
reference={{
projectId,
host: link.host,
repository: link.repository,
number: link.number,
}}
additions={snapshot?.additions ?? 0}
deletions={snapshot?.deletions ?? 0}
className="font-mono"
/>
)
}
meta={
<>
{stack ? (
<Tooltip>
<TooltipTrigger
render={
<span className="inline-flex shrink-0 items-center gap-0.5 text-foreground/70" />
}
>
<PullRequestGlyph.stack aria-hidden className="size-3" />
{stack.size}
</TooltipTrigger>
<TooltipPopup>
{stack.kind === "native"
? gt("{host} stack of {size}: merging a layer lands the ones below it.", {
host: sourceControlClients.hostLabelForChangeRequestUrl(link.url),
size: stack.size,
})
: gt(
"{size} {terms, select, mr {merge requests} cr {change requests} other {pull requests}} chained by base branch.",
{
size: stack.size,
terms: changeRequestTermKind(linkHost.changeRequest),
},
)}
</TooltipPopup>
</Tooltip>
) : null}
{snapshot?.author ? (
<PullRequestRowAuthor
actor={snapshot.author}
className="shrink-0"
labelClassName="max-w-28"
/>
) : null}
{snapshot !== null ? (
<>
<Tooltip>
<TooltipTrigger render={<span className="flex min-w-0 max-w-32 font-mono" />}>
<MiddleTruncate value={link.repository} showTitle={false} />
</TooltipTrigger>
<TooltipPopup>{link.repository}</TooltipPopup>
</Tooltip>
<PullRequestRowBranches head={snapshot.headBranch} base={snapshot.baseBranch} />
</>
) : (
<span className="truncate font-mono">
{link.host}/{link.repository}
</span>
)}
</>
}
updatedAt={snapshot?.updatedAt}
/>
</a>
{devinSummary !== null && projectId !== null ? (
<DevinReviewRowBadge
summary={devinSummary}
onOpen={() =>
openPullRequestDevinReview(threadRef, {
projectId,
host: link.host,
repository: link.repository,
number: link.number,
url: link.url,
})
}
/>
) : null}
{actionEntry !== null ? (
<PullRequestSpeedActions
entry={actionEntry}
hostActions={linkHostActions}
terminology={linkHost.changeRequest}
/>
) : null}
<span
className={cn(
"absolute right-0 bottom-0.5 flex items-center rounded-r-md bg-background pr-1 pl-5",
"[mask-image:linear-gradient(to_right,transparent,black_1rem)]",
// Hidden controls would intercept link taps on touch screens.
"pointer-events-none opacity-0 group-hover/pr-row:pointer-events-auto group-hover/pr-row:opacity-100",
"has-[[data-popup-open]]:pointer-events-auto has-[[data-popup-open]]:opacity-100",
"has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100",
"group-has-[[data-pull-request-action-pending=true]]/pr-row:hidden",
speedMode && hasQuickActions && "hidden",
)}
>
<span aria-hidden className="absolute inset-0 bg-accent/60" />
<Menu
open={menuOpen}
onOpenChange={(open) => {
setMenuOpen(open);
if (!open) setMenuPosition(null);
}}
>
<MenuTrigger
render={
<Button
variant="ghost"
size="icon-micro"
aria-label={gt("Actions for #{number}", { number: link.number })}
className="relative"
>
<MoreHorizontalIcon className="size-3.5" />
</Button>
}
/>
<MenuPopup
anchor={menuAnchor}
align={menuPosition ? "start" : "end"}
side="bottom"
sideOffset={menuPosition ? 0 : 4}
>
<MenuItem
onClick={() =>
void writeTextToClipboard(link.url, {
target: "link",
unavailableMessage: msg("Clipboard API is unavailable while copying link."),
failureMessage: msg("Failed to copy link to the clipboard."),
})
}
>
<LinkIcon className="size-3.5" />
<T>Copy link</T>
</MenuItem>
<MenuItem onClick={(event) => openPrLink(event, link.url, threadRef)}>
<ArrowUpRightIcon className="size-3.5" />
<T context="verb, open a link">Open</T>
</MenuItem>
{onWatch !== null && open && !watching && canStartWatch ? (
<MenuItem onClick={() => onWatch(link, "watch")}>
<EyeIcon className="size-3.5" />
{canPause ? gt("Watch and follow up") : gt("Watch for changes")}
</MenuItem>
) : null}
{onWatch !== null && watching && canPause ? (
<MenuItem onClick={() => onWatch(link, paused ? "resume" : "pause")}>
{paused ? <PlayIcon className="size-3.5" /> : <PauseIcon className="size-3.5" />}
{paused ? gt("Resume watching") : gt("Pause watching")}
</MenuItem>
) : null}
{onWatch !== null && watching ? (
<MenuItem onClick={() => onWatch(link, "stop")}>
<EyeOffIcon className="size-3.5" />
<T>Stop watching</T>
</MenuItem>
) : null}
<MenuItem onClick={() => onUnlink(link)}>
<PullRequestGlyph.unlink className="size-3.5" />
{link.source === "stack" ? gt("Dismiss from thread") : gt("Unlink from thread")}
</MenuItem>
</MenuPopup>
</Menu>
</span>
</div>
);
}
const LinkRow = memo(LinkRowImpl);
function latestSyncedAt(links: ReadonlyArray<ThreadPullRequestLink>): string | null {
let latest: string | null = null;
for (const link of links) {
const at = link.snapshot?.syncedAt;
if (at !== undefined && (latest === null || at > latest)) latest = at;
}
return latest;
}
const lineKey = (line: PullRequestListLine) =>
`${line.link.host}/${line.link.repository}#${line.link.number}`;
export function ThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThreadRef }) {
const gt = useGT();
const configs = useServerConfigs();
if (configs.get(threadRef.environmentId) === undefined) {
return (
<PullRequestsUnavailableState
title={gt("Linked items unavailable")}
error={gt("The thread's environment is not available.")}
/>
);
}
return <EnabledThreadPullRequestsPanel threadRef={threadRef} />;
}
function EnabledThreadPullRequestsPanel({ threadRef }: { threadRef: ScopedThreadRef }) {
const gt = useGT();
const thread = useThreadShell(threadRef);
const issues = thread?.issues ?? [];
const projects = useProjects();
const environmentProjects = projects
.filter((project) => project.environmentId === threadRef.environmentId)
.toSorted((left, right) =>
left.id === thread?.projectId ? -1 : right.id === thread?.projectId ? 1 : 0,
);
// Derive lines before later hooks to preserve compiler caching and avoid LegendList renders.
const links = visibleThreadPullRequests(thread?.pullRequests ?? []);
const openCount = links.filter(
(link) => link.snapshot === null || link.snapshot.state === "open",
).length;
const lastSynced = latestSyncedAt(links);
const linkCount = links.length;
const modifiers = useShortcutModifierState(true);
const speedMode =
modifiers.shiftKey && !modifiers.metaKey && !modifiers.ctrlKey && !modifiers.altKey;
const openLinkDialog = () => openLinkPullRequestDialog(threadRef);
const unlink = useAtomCommand(threadEnvironment.unlinkPullRequest, { reportFailure: true });
const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: true });
const capabilities = useServerConfigs().get(threadRef.environmentId)?.environment.capabilities;
const primaryEnvironmentId = usePrimaryEnvironmentId();
const opensInApp = useClientSettings((settings) => settings.pullRequestLinksOpenInApp);
const prefetch = usePullRequestIntentPrefetch((target) =>
links.some(
(link) =>
link.number === target.number &&
link.repository.toLowerCase() === target.repository.toLowerCase(),
),
);
const intendLink = (link: ThreadPullRequestLink | null) => {
const target =
link === null || !opensInApp
? null
: pullRequestLinkPanelTarget({
url: link.url,
environmentId: threadRef.environmentId,
primaryEnvironmentId,
lendHostProject: true,
});
prefetch(
target?.host === undefined
? null
: {
environmentId: target.project.environmentId,
projectId: target.project.id,
host: target.host,
repository: target.repository,
number: target.number,
},
);
};
const supportsWatch = capabilities?.threadPullRequestWatch === true;
const supportsWatchPause = capabilities?.threadPullRequestWatchPause === true;
const lines = (() => pullRequestListLines(links))();
const canStartWatch = thread !== null && canStartThreadPullRequestWatch(thread);
// One read for every GitHub row; the server takes at most 20 links.
const devinUrls = devinReviewablePullRequests(links)
.slice(0, 20)
.map((link) => link.url);
const devinSummaries = useEnvironmentQuery(
devinUrls.length === 0
? null
: devinReviewEnvironment.summaries({
environmentId: threadRef.environmentId,
input: { urls: devinUrls },
}),
).data;
const devinSummaryByKey = new Map(
(devinSummaries?.reviews ?? [])
.filter(devinReviewSummaryHasNews)
.map((summary) => [devinReviewSummaryKey(summary.repository, summary.number), summary]),
);
const handleUnlink = (link: ThreadPullRequestLink) => {
void unlink({
environmentId: threadRef.environmentId,
input: {
threadId: threadRef.threadId,
host: link.host,
repository: link.repository,
number: link.number,
},
});
};
const handleWatch = (link: ThreadPullRequestLink, action: WatchAction) => {
void watch({
environmentId: threadRef.environmentId,
input: {
threadId: threadRef.threadId,
host: link.host,
repository: link.repository,
number: link.number,
watching: action !== "stop",
...(action === "pause" ? { paused: true } : action === "resume" ? { paused: false } : {}),
},
});
};
// Legend re-renders visible rows only when data or extraData changes, so everything the rows
// read from outside their line goes in here.
const rowInputs = (() => ({
speedMode,
environmentProjects,
capabilities,
supportsWatch,
supportsWatchPause,
opensInApp,
primaryEnvironmentId,
thread,
devinSummaryByKey,
}))();
if (linkCount === 0 && issues.length === 0) {
return (
<div className="flex h-full flex-col items-center justify-center gap-2 p-6 text-center">
<PullRequestGlyph.link aria-hidden className="size-6 text-muted-foreground/60" />
<p className="text-sm font-medium">
<T>No linked pull requests</T>
</p>
<p className="max-w-60 text-xs text-muted-foreground">
<T>
Pull requests the agent opens from this thread land here. Link your own from the list or
a URL.
</T>
</p>
<Button size="sm" variant="outline" onClick={openLinkDialog}>
<PlusIcon className="size-3.5" />
<T>Link pull request</T>
</Button>
</div>
);
}
return (
<PullRequestSpeedModeContext value={speedMode}>
<div className="flex h-full min-h-0 flex-col">
{/* Threads that run a stack or a sweep link hundreds of pull requests; only the rows in
view are mounted. */}
<LegendList<PullRequestListLine>
data={lines}
keyExtractor={lineKey}
extraData={rowInputs}
ListHeaderComponent={
issues.length > 0 ? (
<>
<section aria-label={gt("Linked issues")} className="flex flex-col">
<h2 className="px-2 py-1 text-xs font-medium text-muted-foreground">
<T>Issues</T>
</h2>
<ThreadDetailsIssueRows
links={issues}
threadRef={threadRef}
compact={false}
mountScope="linked-items"
/>
</section>
{linkCount > 0 ? (
<h2 className="mt-2 border-t border-border/60 px-3 pt-2 pb-1 text-xs font-medium text-muted-foreground">
<T>Pull requests</T>
</h2>
) : null}
</>
) : null
}
renderItem={({ item: line }) => (
<>
<LinkRow
line={line}
threadRef={threadRef}
projectId={
capabilities?.pullRequests === true
? (findProjectForChangeRequest(environmentProjects, line.link)?.id ??
thread?.projectId ??
null)
: null
}
speedMode={speedMode}
onUnlink={handleUnlink}
onWatch={supportsWatch ? handleWatch : null}
onIntent={intendLink}
canPause={supportsWatchPause}
canStartWatch={canStartWatch}
devinSummary={
devinSummaryByKey.get(
devinReviewSummaryKey(line.link.repository, line.link.number),
) ?? null
}
/>
{supportsWatchPause ? <WatchStatusLine line={line} /> : null}
</>
)}
estimatedItemSize={44}
drawDistance={440}
className="min-h-0 flex-1 overscroll-contain p-1.5"
/>
<footer className="flex items-center justify-between border-t border-border/60 px-2 py-1.5 text-2xs text-muted-foreground">
<span>
{linkCount > 0
? gt(
"{openCount, plural, one {{openCount} open} other {{openCount} open}} · {linkCount, plural, one {{linkCount} linked} other {{linkCount} linked}}",
{ openCount, linkCount },
)
: null}
{lastSynced ? (
<>
{" · "}
<T context="followed by a relative time such as 5m ago or just now">
synced{" "}
<Var>
<RelativeTime timestamp={lastSynced} />
</Var>
</T>
</>
) : null}
</span>
<Button size="xs" variant="ghost" onClick={openLinkDialog}>
<PlusIcon className="size-3.5" />
<T context="verb, button">Link pull request</T>
</Button>
</footer>
</div>
</PullRequestSpeedModeContext>
);
}