Open History to see the last commit
1import {
2 capitalizeTerm,
3 sourceControlClients,
4} from "@t3tools/client-runtime/source-control-clients";
5import { useAtomCommand } from "~/state/use-atom-command";
6import type {
7 EnvironmentId,
8 PullRequestActor,
9 PullRequestComment,
10 PullRequestDetailView,
11 PullRequestRef,
12 ScopedThreadRef,
13} from "@t3tools/contracts";
14import {
15 ChevronDownIcon,
16 CircleCheckIcon,
17 ExternalLinkIcon,
18 FileCode2Icon,
19 GitCommitHorizontalIcon,
20 MessageSquareIcon,
21 MessageSquarePlusIcon,
22} from "lucide-react";
23import { useState, type ReactNode } from "react";
24
25import { cn } from "~/lib/utils";
26import { readLocalApi } from "~/localApi";
27import { pullRequestEnvironment } from "~/state/pullRequests";
28import { RelativeTime } from "~/components/RelativeTime";
29
30import { Button } from "../ui/button";
31import { PullRequestEditButton } from "./PullRequestEditButton";
32import { Collapsible, CollapsiblePanel, CollapsibleTrigger } from "../ui/collapsible";
33import { toastManager } from "../ui/toast";
34import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
35import {
36 buildPullRequestTimeline,
37 groupPullRequestTimelineConversations,
38 type PullRequestTimelineRow,
39 isPullRequestVerdictStale,
40 newestPullRequestCommitAt,
41 pullRequestReviewOutcome,
42 type PullRequestChatSubject,
43 type PullRequestReviewOutcome,
44 type PullRequestTimelineEvent,
45 type PullRequestTimelineThread,
46} from "./pullRequestDetail.logic";
47import { canEditPullRequestComment } from "@t3tools/client-runtime/pull-request-editing";
48import { PullRequestMarkdown } from "./PullRequestMarkdown";
49import { PullRequestMoreReplies } from "./PullRequestMoreReplies";
50import { PullRequestMarkdownEditor } from "./PullRequestMarkdownEditor";
51import { PullRequestReactionBar } from "./PullRequestReactions";
52import {
53 PullRequestActorAvatar,
54 PullRequestDiffStat,
55 PullRequestMetaLine,
56 PullRequestReviewOutcomeIcon,
57 pullRequestReviewOutcomeLabel,
58 pullRequestReviewOutcomeStaleLabel,
59 pullRequestReviewOutcomeToneClassName,
60} from "./pullRequestPresentation";
61import { PullRequestGlyph } from "./pullRequestIcons";
62import {
63 type PullRequestCompletionScope,
64 pullRequestCompletionScope,
65} from "./PullRequestMarkdownTextarea";
66import { LegendList, type LegendListRef } from "@legendapp/list/react";
67
68interface ReactionSurface {
69 readonly canReact: boolean;
70 /** Absent where there is no composer beside the panel to add a remark to. */
71 readonly onAddToChat?: ((comment: PullRequestComment) => void) | undefined;
72 readonly environmentId: EnvironmentId;
73 readonly threadRef: ScopedThreadRef | null;
74 readonly reference: PullRequestRef;
75 readonly completionScope: PullRequestCompletionScope | null;
76 readonly onRefresh: () => void;
77}
78
79function TimelineBody({
80 body,
81 markdown,
82 cwd,
83 environmentId,
84 threadRef,
85}: {
86 body: string;
87 markdown: boolean;
88 cwd: string;
89 environmentId: EnvironmentId;
90 threadRef: ScopedThreadRef | null;
91}) {
92 return (
93 <div className="mt-3">
94 {markdown ? (
95 <PullRequestMarkdown
96 text={body}
97 cwd={cwd}
98 environmentId={environmentId}
99 threadRef={threadRef}
100 />
101 ) : (
102 <p className="whitespace-pre-wrap text-xs text-muted-foreground">{body}</p>
103 )}
104 </div>
105 );
106}
107
108function ActorName({ actor }: { actor: PullRequestActor | null }) {
109 return <span className="font-semibold text-foreground">{actor?.login ?? "ghost"}</span>;
110}
111
112function TimelineMarker({
113 children,
114 className,
115}: {
116 children: ReactNode;
117 className?: string | undefined;
118}) {
119 return (
120 <span
121 className={cn(
122 "absolute left-0 top-1/2 z-10 flex size-8 -translate-y-1/2 items-center justify-center bg-background",
123 className,
124 )}
125 >
126 {children}
127 </span>
128 );
129}
130
131function IconMarker({ icon, className }: { icon: ReactNode; className?: string | undefined }) {
132 return (
133 <TimelineMarker className={className}>
134 <span className="flex size-7 items-center justify-center bg-background text-muted-foreground">
135 {icon}
136 </span>
137 </TimelineMarker>
138 );
139}
140
141function ActorTimelineMarker({
142 actors,
143 className,
144 fallback,
145 muted = false,
146}: {
147 actors: ReadonlyArray<PullRequestActor>;
148 className?: string | undefined;
149 fallback: ReactNode;
150 muted?: boolean;
151}) {
152 const actor = actors[0];
153 return actor === undefined ? (
154 <IconMarker className={className} icon={fallback} />
155 ) : (
156 <TimelineMarker className={className}>
157 <PullRequestActorAvatar
158 actor={actor}
159 className={cn(
160 "size-7 bg-muted text-3xs transition-opacity",
161 muted && "opacity-45 grayscale",
162 )}
163 />
164 </TimelineMarker>
165 );
166}
167
168function friendlyReviewState(value: string): string {
169 const words = value.toLowerCase().replaceAll("_", " ").replaceAll("-", " ");
170 return words.replace(/^\w/u, (letter) => letter.toUpperCase());
171}
172
173function ReviewStateBadge({ state }: { state: string }) {
174 return (
175 <span className="text-3xs font-medium text-muted-foreground">{friendlyReviewState(state)}</span>
176 );
177}
178
179function AddToChatButton({
180 comment,
181 reactions,
182}: {
183 comment: PullRequestComment;
184 reactions: ReactionSurface;
185}) {
186 const onAddToChat = reactions.onAddToChat;
187 return onAddToChat === undefined ? null : (
188 <Tooltip>
189 <TooltipTrigger
190 render={
191 <Button
192 size="icon-xs"
193 variant="ghost-muted"
194 className="-mt-1 shrink-0"
195 aria-label="Add to chat"
196 onClick={() => onAddToChat(comment)}
197 />
198 }
199 >
200 <MessageSquarePlusIcon className="size-3" />
201 </TooltipTrigger>
202 <TooltipPopup>Add to chat</TooltipPopup>
203 </Tooltip>
204 );
205}
206
207function OpenOnHostButton({ url, onOpen }: { url: string | null; onOpen: (url: string) => void }) {
208 return url === null ? null : (
209 <Button
210 size="icon-xs"
211 variant="ghost-muted"
212 className="-mr-1 shrink-0"
213 aria-label="Open activity on host"
214 onClick={() => onOpen(url)}
215 >
216 <ExternalLinkIcon className="size-3" />
217 </Button>
218 );
219}
220
221function ConversationCard({
222 event,
223 editable,
224 cwd,
225 onOpen,
226 reactions,
227 showPath = true,
228 reply = false,
229}: {
230 event: PullRequestTimelineEvent;
231 editable: PullRequestComment | null;
232 cwd: string;
233 onOpen: (url: string) => void;
234 reactions: ReactionSurface;
235 showPath?: boolean;
236 /** A reply goes with its conversation, from the card that heads it. */
237 reply?: boolean;
238}) {
239 const [editing, setEditing] = useState(false);
240 const [saving, setSaving] = useState(false);
241 const updateComment = useAtomCommand(pullRequestEnvironment.updateComment, {
242 reportFailure: false,
243 });
244
245 const save = async (body: string) => {
246 if (editable === null || saving || editable.kind === "review") return;
247 setSaving(true);
248 const result = await updateComment({
249 environmentId: reactions.environmentId,
250 input: { ...reactions.reference, commentId: editable.id, kind: editable.kind, body },
251 });
252 setSaving(false);
253 if (result._tag === "Failure") {
254 toastManager.add({ type: "error", title: "Could not save the comment" });
255 return;
256 }
257 setEditing(false);
258 reactions.onRefresh();
259 };
260
261 return (
262 <article className="group py-2">
263 <div className="px-2">
264 <div className="flex min-w-0 flex-wrap items-center gap-2">
265 <div className="min-w-0 flex-1">
266 <div className="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs">
267 <ActorName actor={event.actor} />
268 <span className="text-muted-foreground">{event.title}</span>
269 {event.reviewState ? <ReviewStateBadge state={event.reviewState} /> : null}
270 </div>
271 <PullRequestMetaLine className="mt-1 flex-wrap text-2xs text-muted-foreground">
272 <span>
273 <RelativeTime timestamp={event.at} />
274 </span>
275 {showPath && event.path ? (
276 <span className="inline-flex min-w-0 items-center gap-1">
277 <FileCode2Icon aria-hidden className="size-3 shrink-0" />
278 <span className="truncate">{event.path}</span>
279 </span>
280 ) : null}
281 </PullRequestMetaLine>
282 </div>
283 {editable !== null && !editing ? (
284 <PullRequestEditButton aria-label="Edit comment" onClick={() => setEditing(true)} />
285 ) : null}
286 {event.body && event.comment && !reply ? (
287 <AddToChatButton comment={event.comment} reactions={reactions} />
288 ) : null}
289 {reactions.canReact || event.reactions.length > 0 ? (
290 <PullRequestReactionBar
291 className="ml-auto justify-end"
292 reactions={event.reactions}
293 canReact={reactions.canReact}
294 subjectId={event.id}
295 environmentId={reactions.environmentId}
296 reference={reactions.reference}
297 onRefresh={reactions.onRefresh}
298 />
299 ) : null}
300 <OpenOnHostButton url={event.url} onOpen={onOpen} />
301 </div>
302 </div>
303 {editing && editable !== null ? (
304 <div className="px-2 pb-2 pt-3">
305 <PullRequestMarkdownEditor
306 value={editable.body}
307 cwd={cwd}
308 environmentId={reactions.environmentId}
309 completionScope={reactions.completionScope}
310 threadRef={reactions.threadRef}
311 label="Edit comment"
312 saving={saving}
313 onSave={(body) => void save(body)}
314 onCancel={() => setEditing(false)}
315 />
316 </div>
317 ) : event.body ? (
318 <div className="px-2 pb-2">
319 <TimelineBody
320 body={event.body}
321 markdown={event.markdown}
322 cwd={cwd}
323 environmentId={reactions.environmentId}
324 threadRef={reactions.threadRef}
325 />
326 </div>
327 ) : null}
328 </article>
329 );
330}
331
332function uniqueConversationActors(events: ReadonlyArray<PullRequestTimelineEvent>) {
333 const actors = new Map<string, PullRequestActor>();
334 for (const event of events) {
335 const actor = event.actor;
336 if (actor !== null && !actors.has(actor.login)) actors.set(actor.login, actor);
337 }
338 return [...actors.values()];
339}
340
341function ConversationGroup({
342 events,
343 editable,
344 cwd,
345 onOpen,
346 reactions,
347}: {
348 events: ReadonlyArray<PullRequestTimelineEvent>;
349 editable: ReadonlyMap<string, PullRequestComment>;
350 cwd: string;
351 onOpen: (url: string) => void;
352 reactions: ReactionSurface;
353}) {
354 const [open, setOpen] = useState(false);
355 const actors = uniqueConversationActors(events);
356 const first = events[0];
357 if (first === undefined) return null;
358
359 return (
360 <div className="relative mb-5 pl-12 [contain-intrinsic-block-size:48px] [content-visibility:auto]">
361 <ActorTimelineMarker
362 actors={actors}
363 className="top-6"
364 fallback={<MessageSquareIcon className="size-3.5" />}
365 muted={!open}
366 />
367 <Collapsible open={open} onOpenChange={setOpen}>
368 <div>
369 <CollapsibleTrigger
370 className={cn(
371 "flex w-full min-w-0 items-center gap-3 py-2 text-left transition-opacity hover:opacity-100",
372 open ? "text-foreground opacity-100" : "text-muted-foreground opacity-55",
373 )}
374 >
375 <span className="min-w-0 flex-1">
376 <span className="block text-xs font-semibold">
377 {events.length.toLocaleString()} {events.length === 1 ? "comment" : "comments"}
378 </span>
379 <span className="block truncate text-3xs text-muted-foreground">
380 {actors.length.toLocaleString()} {actors.length === 1 ? "author" : "authors"} ·{" "}
381 <RelativeTime timestamp={first.at} />
382 </span>
383 </span>
384 <ChevronDownIcon
385 aria-hidden
386 className={cn(
387 "size-3.5 shrink-0 text-muted-foreground transition-transform",
388 open && "rotate-180",
389 )}
390 />
391 </CollapsibleTrigger>
392 <CollapsiblePanel>
393 {open ? (
394 <div className="mt-1 space-y-1">
395 {events.map((event) => (
396 <ConversationCard
397 // Host comment ids can collide across pull requests.
398 key={`${reactions.reference.projectId}#${reactions.reference.number}:${event.id}`}
399 event={event}
400 editable={editable.get(event.id) ?? null}
401 cwd={cwd}
402 onOpen={onOpen}
403 reactions={reactions}
404 />
405 ))}
406 </div>
407 ) : null}
408 </CollapsiblePanel>
409 </div>
410 </Collapsible>
411 </div>
412 );
413}
414
415function ReviewThreadEvent({
416 event,
417 thread,
418 editable,
419 cwd,
420 onOpen,
421 reactions,
422}: {
423 event: PullRequestTimelineEvent;
424 thread: PullRequestTimelineThread;
425 editable: ReadonlyMap<string, PullRequestComment>;
426 cwd: string;
427 onOpen: (url: string) => void;
428 reactions: ReactionSurface;
429}) {
430 const dismissed = pullRequestReviewOutcome(event.reviewState) === "dismissed";
431 const [expanded, setExpanded] = useState(!thread.isResolved && !dismissed);
432 const replyCount = thread.replies.length + thread.moreReplies;
433
434 return (
435 <div className="group relative mb-5 pl-12 [contain-intrinsic-block-size:48px] [content-visibility:auto]">
436 <ActorTimelineMarker
437 actors={event.actor ? [event.actor] : []}
438 className="top-4"
439 fallback={<MessageSquareIcon className="size-3.5" />}
440 muted={!expanded}
441 />
442 <button
443 type="button"
444 className="flex w-full min-w-0 items-center gap-2 px-2 py-2 text-left text-2xs text-muted-foreground hover:text-foreground"
445 aria-expanded={expanded}
446 onClick={() => setExpanded((current) => !current)}
447 >
448 <FileCode2Icon aria-hidden className="size-3 shrink-0" />
449 <span className="min-w-0 truncate font-mono">
450 {thread.line === null ? thread.path : `${thread.path}:${thread.line}`}
451 </span>
452 {thread.isResolved ? (
453 <span className="inline-flex shrink-0 items-center gap-1 font-medium text-success-foreground">
454 <CircleCheckIcon aria-hidden className="size-3" />
455 Resolved
456 </span>
457 ) : null}
458 {dismissed ? <span className="shrink-0 font-medium">Review dismissed</span> : null}
459 {thread.isOutdated ? <span className="shrink-0 font-medium">Outdated</span> : null}
460 {expanded ? null : (
461 <span className="shrink-0">
462 · {event.actor?.login ?? "ghost"}
463 {replyCount > 0 ? (
464 <>
465 {" "}
466 · {replyCount.toLocaleString()} {replyCount === 1 ? "reply" : "replies"}
467 </>
468 ) : null}
469 </span>
470 )}
471 <ChevronDownIcon
472 aria-hidden
473 className={cn("ml-auto size-3.5 shrink-0 transition-transform", expanded && "rotate-180")}
474 />
475 </button>
476 {expanded ? (
477 <>
478 <ConversationCard
479 event={event}
480 editable={editable.get(event.id) ?? null}
481 cwd={cwd}
482 onOpen={onOpen}
483 reactions={reactions}
484 showPath={false}
485 />
486 {thread.replies.length > 0 ? (
487 <div className="ml-2 space-y-1 border-l border-border/60 pl-3">
488 {thread.replies.map((reply) => (
489 <ConversationCard
490 key={reply.id}
491 event={reply}
492 editable={editable.get(reply.id) ?? null}
493 cwd={cwd}
494 onOpen={onOpen}
495 reactions={reactions}
496 showPath={false}
497 reply
498 />
499 ))}
500 </div>
501 ) : null}
502 </>
503 ) : null}
504 {thread.hasMoreReplies ? (
505 <div className="px-2">
506 <PullRequestMoreReplies {...thread} />
507 </div>
508 ) : null}
509 </div>
510 );
511}
512
513function CommitEvent({
514 event,
515 onOpen,
516}: {
517 event: PullRequestTimelineEvent;
518 onOpen: (oid: string) => void;
519}) {
520 return (
521 <button
522 type="button"
523 className="group relative mb-5 block w-full cursor-pointer rounded-sm pl-12 text-left outline-none [contain-intrinsic-block-size:48px] [content-visibility:auto] focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring"
524 aria-label={`View commit ${event.id}`}
525 onClick={() => onOpen(event.id)}
526 >
527 <ActorTimelineMarker
528 actors={event.commitAuthors}
529 fallback={<GitCommitHorizontalIcon className="size-3.5" />}
530 />
531 <div className="flex min-w-0 items-center gap-2.5 py-1.5">
532 <div className="min-w-0 flex-1">
533 <div className="truncate text-xs font-semibold text-foreground transition-colors group-hover:text-primary">
534 {event.body ?? "Untitled commit"}
535 </div>
536 <div className="mt-1 flex flex-wrap items-center gap-x-2 gap-y-0.5 text-3xs text-muted-foreground">
537 <code className="font-mono">{event.id.slice(0, 7)}</code>
538 <span>
539 <RelativeTime timestamp={event.at} />
540 </span>
541 </div>
542 </div>
543 {event.additions !== null && event.deletions !== null ? (
544 <PullRequestDiffStat
545 additions={event.additions}
546 deletions={event.deletions}
547 className="ml-auto shrink-0 font-mono text-3xs"
548 />
549 ) : null}
550 </div>
551 </button>
552 );
553}
554
555function LifecycleEvent({ event, term }: { event: PullRequestTimelineEvent; term: string }) {
556 const title = capitalizeTerm(term);
557 const presentation =
558 event.kind === "opened"
559 ? {
560 icon: <PullRequestGlyph.pullRequest className="size-3.5" />,
561 label: `${title} opened`,
562 }
563 : event.kind === "merged"
564 ? {
565 icon: <PullRequestGlyph.merged className="size-3.5" />,
566 label: `${title} merged`,
567 }
568 : {
569 icon: <PullRequestGlyph.closed className="size-3.5" />,
570 label: `${title} closed`,
571 };
572
573 return (
574 <div className="relative mb-5 pl-12 [contain-intrinsic-block-size:48px] [content-visibility:auto]">
575 <IconMarker icon={presentation.icon} />
576 <div className="py-1.5 text-xs">
577 <div className="flex flex-wrap items-center gap-1.5">
578 {event.actor ? <ActorName actor={event.actor} /> : null}
579 <span className="font-semibold text-foreground">{presentation.label}</span>
580 </div>
581 <div className="mt-0.5 text-2xs text-muted-foreground">
582 <RelativeTime timestamp={event.at} />
583 </div>
584 </div>
585 </div>
586 );
587}
588
589function ReviewVerdictEvent({
590 event,
591 outcome,
592 stale,
593 cwd,
594 onOpen,
595 reactions,
596}: {
597 event: PullRequestTimelineEvent;
598 outcome: PullRequestReviewOutcome;
599 stale: boolean;
600 cwd: string;
601 onOpen: (url: string) => void;
602 reactions: ReactionSurface;
603}) {
604 return (
605 <div className="group relative mb-5 pl-12 [contain-intrinsic-block-size:48px] [content-visibility:auto]">
606 <ActorTimelineMarker
607 actors={event.actor ? [event.actor] : []}
608 className="top-6"
609 fallback={<PullRequestReviewOutcomeIcon outcome={outcome} />}
610 />
611 <div className="flex min-w-0 flex-wrap items-center gap-2 py-1.5">
612 <div className="min-w-0 flex-1">
613 <div className="flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-1 text-xs">
614 <ActorName actor={event.actor} />
615 <Tooltip disabled={!stale}>
616 <TooltipTrigger
617 render={
618 <span
619 className={cn(
620 "font-medium lowercase",
621 stale
622 ? "text-muted-foreground opacity-70"
623 : pullRequestReviewOutcomeToneClassName(outcome),
624 )}
625 />
626 }
627 >
628 {pullRequestReviewOutcomeLabel(outcome)}
629 {stale ? <span className="sr-only">, before the latest commits</span> : null}
630 </TooltipTrigger>
631 <TooltipPopup>{pullRequestReviewOutcomeStaleLabel(outcome)}</TooltipPopup>
632 </Tooltip>
633 </div>
634 <div className="mt-0.5 flex min-w-0 flex-wrap items-center gap-x-2 gap-y-1">
635 <PullRequestMetaLine className="flex-wrap text-2xs text-muted-foreground">
636 <span>
637 <RelativeTime timestamp={event.at} />
638 </span>
639 {event.path ? (
640 <span className="inline-flex min-w-0 items-center gap-1">
641 <FileCode2Icon aria-hidden className="size-3 shrink-0" />
642 <span className="truncate">{event.path}</span>
643 </span>
644 ) : null}
645 </PullRequestMetaLine>
646 </div>
647 </div>
648 {event.body && event.comment ? (
649 <AddToChatButton comment={event.comment} reactions={reactions} />
650 ) : null}
651 {reactions.canReact || event.reactions.length > 0 ? (
652 <PullRequestReactionBar
653 className="ml-auto justify-end"
654 reactions={event.reactions}
655 canReact={reactions.canReact}
656 subjectId={event.id}
657 environmentId={reactions.environmentId}
658 reference={reactions.reference}
659 onRefresh={reactions.onRefresh}
660 />
661 ) : null}
662 <OpenOnHostButton url={event.url} onOpen={onOpen} />
663 </div>
664 {event.body ? (
665 <TimelineBody
666 body={event.body}
667 markdown={event.markdown}
668 cwd={cwd}
669 environmentId={reactions.environmentId}
670 threadRef={reactions.threadRef}
671 />
672 ) : null}
673 </div>
674 );
675}
676
677export function PullRequestTimelineTab({
678 scrollerRef,
679 detail,
680 environmentId,
681 threadRef = null,
682 reference,
683 order,
684 onOpenCommit,
685 onAddToChat,
686 onRefresh,
687}: {
688 scrollerRef: (node: HTMLElement | null) => void;
689 detail: PullRequestDetailView;
690 environmentId: EnvironmentId;
691 threadRef?: ScopedThreadRef | null;
692 reference: PullRequestRef;
693 order: "newest" | "oldest";
694 onOpenCommit: (oid: string) => void;
695 onAddToChat?: (subject: PullRequestChatSubject) => void;
696 onRefresh: () => void;
697}) {
698 const events = buildPullRequestTimeline(detail);
699 const term = sourceControlClients.get(detail.provider).changeRequest.singular;
700 const newestCommitAt = newestPullRequestCommitAt(detail.commits);
701 const reactions: ReactionSurface = {
702 canReact: detail.capabilities.reactions === true,
703 onAddToChat: onAddToChat && ((comment) => onAddToChat({ kind: "comment", comment })),
704 environmentId,
705 threadRef,
706 reference,
707 completionScope: pullRequestCompletionScope(detail, environmentId, reference),
708 onRefresh,
709 };
710 const editable = new Map(
711 events
712 .flatMap((event) => [event, ...(event.thread?.replies ?? [])])
713 .flatMap((event) => (event.comment ? [event.comment] : []))
714 .filter((comment) => canEditPullRequestComment(detail, comment))
715 .map((comment) => [comment.id, comment] as const),
716 );
717 const orderedEvents = order === "newest" ? events : events.toReversed();
718 const rows = groupPullRequestTimelineConversations(orderedEvents);
719 const openOnHost = (url: string) => {
720 void readLocalApi()?.shell.openExternal(url);
721 };
722
723 const rowKey = (row: PullRequestTimelineRow) => {
724 if (row.kind === "comments") return `comments:${row.events[0]?.id ?? "empty"}`;
725 const event = row.event;
726 // A thread's resolution or dismissal remounts it, so its disclosure starts in the new state.
727 return event.thread === undefined
728 ? event.id
729 : `thread:${event.id}:${event.thread.isResolved}:${pullRequestReviewOutcome(event.reviewState) === "dismissed"}`;
730 };
731 const renderRow = ({ item: row }: { item: PullRequestTimelineRow }) => {
732 if (row.kind === "comments") {
733 return (
734 <ConversationGroup
735 events={row.events}
736 editable={editable}
737 cwd={detail.workspaceRoot}
738 onOpen={openOnHost}
739 reactions={reactions}
740 />
741 );
742 }
743 const event = row.event;
744 if (event.thread !== undefined) {
745 return (
746 <ReviewThreadEvent
747 event={event}
748 thread={event.thread}
749 editable={editable}
750 cwd={detail.workspaceRoot}
751 onOpen={openOnHost}
752 reactions={reactions}
753 />
754 );
755 }
756 if (event.kind === "commit") return <CommitEvent event={event} onOpen={onOpenCommit} />;
757 const outcome = pullRequestReviewOutcome(event.reviewState);
758 if (outcome !== null) {
759 return (
760 <ReviewVerdictEvent
761 event={event}
762 outcome={outcome}
763 stale={isPullRequestVerdictStale(event.at, newestCommitAt)}
764 cwd={detail.workspaceRoot}
765 onOpen={openOnHost}
766 reactions={reactions}
767 />
768 );
769 }
770 return <LifecycleEvent event={event} term={term} />;
771 };
772
773 if (events.length === 0) {
774 return (
775 <div ref={scrollerRef} className="scrollbar-gutter-both h-full overflow-y-auto px-4 py-5">
776 <div className="flex flex-col items-center justify-center py-16 text-center text-muted-foreground">
777 <PullRequestGlyph.pullRequest className="mb-2 size-5" />
778 <p className="text-xs">No activity yet.</p>
779 </div>
780 </div>
781 );
782 }
783
784 // Virtualized: a large pull request has thousands of events, and mounting every one stalls
785 // the page. The connector line is drawn by the content container, behind the rows.
786 return (
787 <LegendList<PullRequestTimelineRow>
788 ref={(list: LegendListRef | null) => scrollerRef(list?.getScrollableNode() ?? null)}
789 data={rows}
790 extraData={{ editable, reactions, newestCommitAt }}
791 keyExtractor={rowKey}
792 renderItem={renderRow}
793 estimatedItemSize={140}
794 className="scrollbar-gutter-both h-full px-4"
795 contentContainerClassName="relative mx-auto w-full max-w-3xl before:absolute before:bottom-10 before:left-[15px] before:top-6 before:w-px before:bg-border/45"
796 ListHeaderComponent={<div className="h-5" />}
797 ListFooterComponent={<div className="h-5" />}
798 />
799 );
800}