Open History to see the last commit
1import type {
2 PullRequestActor,
3 PullRequestMergeability,
4 PullRequestState,
5} from "@t3tools/contracts";
6import type { ReactNode } from "react";
7
8import { cn } from "~/lib/utils";
9import { RelativeTime } from "~/components/RelativeTime";
10
11import { MiddleTruncate } from "../ui/middle-truncate";
12import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
13import {
14 PullRequestActorAvatar,
15 PullRequestConflictGlyph,
16 PullRequestStateGlyph,
17} from "./pullRequestPresentation";
18
19export const PULL_REQUEST_ROW_CLASS =
20 "group/pr-row flex w-full items-center gap-2 rounded-md py-1 pr-1 text-left";
21
22export const PULL_REQUEST_ROW_NUMBER_CLASS =
23 "shrink-0 font-mono text-xs tabular-nums text-muted-foreground";
24
25export function PullRequestRowGlyph({
26 state,
27 isDraft,
28 mergeability,
29 baseBranch,
30 below,
31 className,
32}: {
33 state: PullRequestState;
34 isDraft: boolean;
35 mergeability?: PullRequestMergeability | undefined;
36 baseBranch?: string | undefined;
37 below?: ReactNode;
38 className?: string;
39}) {
40 return (
41 <span className={cn("flex w-4 shrink-0 flex-col items-center gap-0.5", className)}>
42 <span className="relative inline-flex">
43 <PullRequestStateGlyph state={state} isDraft={isDraft} />
44 {/* The wrapper takes the offset, not the icon, so the tooltip trigger inside keeps the
45 badge's size and anchors the popup to it. */}
46 <span className="absolute -right-1 -bottom-1 inline-flex">
47 <PullRequestConflictGlyph
48 state={state}
49 isDraft={isDraft}
50 {...(mergeability === undefined ? {} : { mergeability })}
51 {...(baseBranch === undefined ? {} : { baseBranch })}
52 className="size-3 fill-background [stroke-width:2.5]"
53 />
54 </span>
55 </span>
56 {below ? <span className="inline-flex text-2xs">{below}</span> : null}
57 </span>
58 );
59}
60
61export function PullRequestRowLines({
62 number,
63 title,
64 status,
65 signals,
66 meta,
67 metaClassName,
68 updatedAt,
69}: {
70 number: ReactNode;
71 title: ReactNode;
72 status?: ReactNode;
73 signals?: ReactNode;
74 meta?: ReactNode;
75 metaClassName?: string;
76 updatedAt?: string | null | undefined;
77}) {
78 return (
79 <span className="min-w-0 flex-1">
80 <span className="flex min-w-0 items-center gap-1.5">
81 {number}
82 <span className="min-w-0 truncate text-sm">{title}</span>
83 {signals ? (
84 <span className="flex shrink-0 items-center gap-1 text-2xs">{signals}</span>
85 ) : null}
86 {status ? (
87 <span className="ml-auto flex shrink-0 items-center gap-1.5 text-2xs">{status}</span>
88 ) : null}
89 </span>
90 <span
91 className={cn(
92 "flex min-w-0 items-center gap-1.5 overflow-hidden text-2xs text-muted-foreground",
93 metaClassName,
94 )}
95 >
96 {meta}
97 {updatedAt ? (
98 <span className="ml-auto shrink-0 whitespace-nowrap tabular-nums">
99 <RelativeTime timestamp={updatedAt} />
100 </span>
101 ) : null}
102 </span>
103 </span>
104 );
105}
106
107export function PullRequestRowAuthor({
108 actor,
109 className,
110 labelClassName,
111}: {
112 actor: PullRequestActor | null;
113 className?: string;
114 labelClassName?: string;
115}) {
116 const login = actor?.login ?? "ghost";
117 return (
118 <Tooltip>
119 <TooltipTrigger
120 render={<span className={cn("inline-flex min-w-0 items-center gap-1", className)} />}
121 >
122 <PullRequestActorAvatar actor={actor} className="size-3.5" />
123 <span className={cn("truncate", labelClassName)}>{login}</span>
124 </TooltipTrigger>
125 <TooltipPopup side="top">
126 {actor?.name && actor.name !== login ? `${actor.name} (@${login})` : login}
127 </TooltipPopup>
128 </Tooltip>
129 );
130}
131
132export function PullRequestRowBranches({ head, base }: { head: string; base: string }) {
133 return (
134 <span className="flex min-w-0 items-center gap-1 font-mono">
135 <MiddleTruncate value={head} />
136 <span className="shrink-0">→</span>
137 <MiddleTruncate value={base} className="max-w-[45%] shrink-0" />
138 </span>
139 );
140}