Skip to content

Commit 8c7f936

Browse files
committed
feat: format display attributes on GitifyNotification
Signed-off-by: Adam Setch <[email protected]>
1 parent 57b2203 commit 8c7f936

23 files changed

+389
-266
lines changed

src/renderer/components/metrics/MetricGroup.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
4949
describe('comment pills', () => {
5050
it('should render when no comments', async () => {
5151
const mockNotification = mockSingleNotification;
52-
mockNotification.subject.comments = null;
52+
mockNotification.subject.commentCount = null;
5353

5454
const props = {
5555
notification: mockNotification,
@@ -61,7 +61,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
6161

6262
it('should render when 1 comment', async () => {
6363
const mockNotification = mockSingleNotification;
64-
mockNotification.subject.comments = 1;
64+
mockNotification.subject.commentCount = 1;
6565

6666
const props = {
6767
notification: mockNotification,
@@ -73,7 +73,7 @@ describe('renderer/components/metrics/MetricGroup.tsx', () => {
7373

7474
it('should render when more than 1 comments', async () => {
7575
const mockNotification = mockSingleNotification;
76-
mockNotification.subject.comments = 2;
76+
mockNotification.subject.commentCount = 2;
7777

7878
const props = {
7979
notification: mockNotification,

src/renderer/components/metrics/MetricGroup.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,38 @@ export const MetricGroup: FC<MetricGroupProps> = ({
2121
}: MetricGroupProps) => {
2222
const { settings } = useAppContext();
2323

24-
const commentsPillDescription = `${notification.subject.comments} ${
25-
notification.subject.comments > 1 ? 'comments' : 'comment'
26-
}`;
24+
const linkedIssues = notification.subject.linkedIssues ?? [];
25+
const hasLinkedIssues = linkedIssues.length > 0;
26+
const linkedIssuesPillDescription = hasLinkedIssues
27+
? `Linked to ${
28+
linkedIssues.length > 1 ? 'issues' : 'issue'
29+
} ${linkedIssues.join(', ')}`
30+
: '';
2731

28-
const labelsPillDescription = notification.subject.labels
29-
?.map((label) => `🏷️ ${label}`)
30-
.join(', ');
32+
const commentCount = notification.subject.commentCount ?? 0;
33+
const hasComments = commentCount > 0;
34+
const commentsPillDescription = hasComments
35+
? `${notification.subject.commentCount} ${
36+
notification.subject.commentCount > 1 ? 'comments' : 'comment'
37+
}`
38+
: '';
3139

32-
const linkedIssuesPillDescription = `Linked to ${
33-
notification.subject.linkedIssues?.length > 1 ? 'issues' : 'issue'
34-
} ${notification.subject?.linkedIssues?.join(', ')}`;
40+
const labels = notification.subject.labels ?? [];
41+
const hasLabels = labels.length > 0;
42+
const labelsPillDescription = hasLabels
43+
? labels.map((label) => `🏷️ ${label}`).join(', ')
44+
: '';
45+
46+
const milestone = notification.subject.milestone;
3547

3648
return (
3749
settings.showPills && (
3850
<div className="flex gap-1">
39-
{notification.subject?.linkedIssues?.length > 0 && (
51+
{hasLinkedIssues && (
4052
<MetricPill
4153
color={IconColor.GRAY}
4254
icon={IssueOpenedIcon}
43-
metric={notification.subject.linkedIssues.length}
55+
metric={linkedIssues.length}
4456
title={linkedIssuesPillDescription}
4557
/>
4658
)}
@@ -62,33 +74,29 @@ export const MetricGroup: FC<MetricGroupProps> = ({
6274
);
6375
})}
6476

65-
{notification.subject?.comments > 0 && (
77+
{hasComments && (
6678
<MetricPill
6779
color={IconColor.GRAY}
6880
icon={CommentIcon}
69-
metric={notification.subject.comments}
81+
metric={commentCount}
7082
title={commentsPillDescription}
7183
/>
7284
)}
7385

74-
{notification.subject?.labels?.length > 0 && (
86+
{hasLabels && (
7587
<MetricPill
7688
color={IconColor.GRAY}
7789
icon={TagIcon}
78-
metric={notification.subject.labels.length}
90+
metric={labels.length}
7991
title={labelsPillDescription}
8092
/>
8193
)}
8294

83-
{notification.subject.milestone && (
95+
{milestone && (
8496
<MetricPill
85-
color={
86-
notification.subject.milestone.state === 'OPEN'
87-
? IconColor.GREEN
88-
: IconColor.RED
89-
}
97+
color={milestone.state === 'OPEN' ? IconColor.GREEN : IconColor.RED}
9098
icon={MilestoneIcon}
91-
title={notification.subject.milestone.title}
99+
title={milestone.title}
92100
/>
93101
)}
94102
</div>

src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap

Lines changed: 30 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/notifications/__snapshots__/NotificationFooter.test.tsx.snap

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/renderer/components/notifications/__snapshots__/NotificationHeader.test.tsx.snap

Lines changed: 18 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)