-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathMetricGroup.tsx
More file actions
109 lines (93 loc) · 2.8 KB
/
MetricGroup.tsx
File metadata and controls
109 lines (93 loc) · 2.8 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
import type { FC } from 'react';
import {
CommentIcon,
IssueOpenedIcon,
MilestoneIcon,
TagIcon,
} from '@primer/octicons-react';
import { useAppContext } from '../../hooks/useAppContext';
import { type GitifyNotification, IconColor } from '../../types';
import { getPullRequestReviewIcon } from '../../utils/icons';
import { MetricPill } from './MetricPill';
export interface MetricGroupProps {
notification: GitifyNotification;
}
export const MetricGroup: FC<MetricGroupProps> = ({
notification,
}: MetricGroupProps) => {
const { settings } = useAppContext();
const linkedIssues = notification.subject.linkedIssues ?? [];
const hasLinkedIssues = linkedIssues.length > 0;
const linkedIssuesPillDescription = hasLinkedIssues
? `Linked to ${
linkedIssues.length > 1 ? 'issues' : 'issue'
} ${linkedIssues.join(', ')}`
: '';
const commentCount = notification.subject.commentCount ?? 0;
const hasComments = commentCount > 0;
const commentsPillDescription = hasComments
? `${notification.subject.commentCount} ${
notification.subject.commentCount > 1 ? 'comments' : 'comment'
}`
: '';
const labels = notification.subject.labels ?? [];
const hasLabels = labels.length > 0;
const labelsPillDescription = hasLabels
? labels.map((label) => `🏷️ ${label}`).join(', ')
: '';
const milestone = notification.subject.milestone;
return (
settings.showPills && (
<div className="flex gap-1">
{hasLinkedIssues && (
<MetricPill
color={IconColor.GRAY}
icon={IssueOpenedIcon}
metric={linkedIssues.length}
title={linkedIssuesPillDescription}
/>
)}
{notification.subject.reviews?.map((review) => {
const icon = getPullRequestReviewIcon(review);
if (!icon) {
return null;
}
return (
<MetricPill
color={icon.color}
icon={icon.type}
key={review.state}
metric={review.users.length}
title={icon.description}
/>
);
})}
{hasComments && (
<MetricPill
color={IconColor.GRAY}
icon={CommentIcon}
metric={commentCount}
title={commentsPillDescription}
/>
)}
{hasLabels && (
<MetricPill
color={IconColor.GRAY}
icon={TagIcon}
metric={labels.length}
title={labelsPillDescription}
/>
)}
{milestone && (
<MetricPill
color={
milestone.state === 'OPEN' ? IconColor.GREEN : IconColor.PURPLE
}
icon={MilestoneIcon}
title={milestone.title}
/>
)}
</div>
)
);
};