-
Notifications
You must be signed in to change notification settings - Fork 543
Expand file tree
/
Copy pathpr-badge.tsx
More file actions
86 lines (83 loc) · 3.1 KB
/
Copy pathpr-badge.tsx
File metadata and controls
86 lines (83 loc) · 3.1 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
import { ExternalLink } from 'lucide-react';
import { PrMergeLine } from '@renderer/lib/components/pr-merge-line';
import { Popover, PopoverContent, PopoverTrigger } from '@renderer/lib/ui/popover';
import { cn } from '@renderer/utils/utils';
import { getPrNumber, type PullRequest } from '@shared/core/pull-requests/pull-requests';
import { rpc } from '../ipc';
import { Button } from '../ui/button';
import { RelativeTime } from '../ui/relative-time';
import { Tooltip, TooltipContent, TooltipTrigger } from '../ui/tooltip';
import { PrNumberBadge } from './pr-number-badge';
import { StatusIcon } from './pr-status-icon';
interface PrBadgeProps {
variant?: 'default' | 'compact';
pr: PullRequest;
className?: string;
hoverDelay?: number;
}
export function PrBadge({ variant = 'default', pr, className, hoverDelay }: PrBadgeProps) {
const renderBadge = () => {
switch (variant) {
case 'default':
return (
<div
className={cn(
'flex h-5 max-w-52 items-center gap-1.5 rounded-md bg-background-2 px-1.5 leading-none',
className
)}
>
<StatusIcon className="size-3" pr={pr} disableTooltip />
<span className="shrink-0 text-xs leading-none text-foreground-muted">
#{getPrNumber(pr) ?? 0}
</span>
<span className="truncate text-xs leading-none text-foreground-muted">{pr.title}</span>
</div>
);
case 'compact':
return (
<div className={cn('flex h-5 items-center justify-center px-1 leading-none', className)}>
<StatusIcon className="size-3" pr={pr} disableTooltip />
</div>
);
}
};
return (
<Popover>
<PopoverTrigger className="flex items-center leading-none" openOnHover delay={hoverDelay}>
{renderBadge()}
</PopoverTrigger>
<PopoverContent className="w-auto max-w-sm min-w-72">
<div className="flex flex-col gap-2">
<div className="no-wrap flex items-center justify-between gap-2">
<div className="flex min-w-0 items-center gap-2">
<StatusIcon pr={pr} className="size-3" />
<span className="min-w-0 truncate text-sm leading-snug text-foreground">
{pr.title}
</span>
<PrNumberBadge number={getPrNumber(pr) ?? 0} />
<Tooltip>
<TooltipTrigger>
<Button
variant="ghost"
size="icon-xs"
className="cursor-pointer"
onClick={() => rpc.app.openExternal(pr.url)}
>
<ExternalLink className="size-3.5" />
</Button>
</TooltipTrigger>
<TooltipContent>Open PR on GitHub</TooltipContent>
</Tooltip>
</div>
<RelativeTime
value={pr.createdAt}
className="text-xs text-foreground-passive"
compact
/>
</div>
<PrMergeLine pr={pr} />
</div>
</PopoverContent>
</Popover>
);
}