Skip to content

feat: better notification type icons #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ export const NotificationRow: React.FC<IProps> = ({
};

const reason = formatReason(notification.reason);
const NotificationIcon = getNotificationTypeIcon(notification.subject.type);
const NotificationIcon = getNotificationTypeIcon(
notification.subject.type,
notification.subject.state,
);
const iconColor = getNotificationTypeIconColor(notification.subject.state);
const realIconColor = settings
? (settings.colors && iconColor) || ''
Expand Down
18 changes: 18 additions & 0 deletions src/utils/github-api.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,27 @@ describe('./utils/github-api.ts', () => {
expect(getNotificationTypeIcon('Issue').displayName).toBe(
'IssueOpenedIcon',
);
expect(getNotificationTypeIcon('Issue', 'draft').displayName).toBe(
'IssueDraftIcon',
);
expect(getNotificationTypeIcon('Issue', 'closed').displayName).toBe(
'IssueClosedIcon',
);
expect(getNotificationTypeIcon('Issue', 'reopened').displayName).toBe(
'IssueReopenedIcon',
);
expect(getNotificationTypeIcon('PullRequest').displayName).toBe(
'GitPullRequestIcon',
);
expect(getNotificationTypeIcon('PullRequest', 'draft').displayName).toBe(
'GitPullRequestDraftIcon',
);
expect(getNotificationTypeIcon('PullRequest', 'closed').displayName).toBe(
'GitPullRequestClosedIcon',
);
expect(getNotificationTypeIcon('PullRequest', 'merged').displayName).toBe(
'GitMergeIcon',
);
expect(getNotificationTypeIcon('Release').displayName).toBe('TagIcon');
expect(
getNotificationTypeIcon('RepositoryVulnerabilityAlert').displayName,
Expand Down
29 changes: 27 additions & 2 deletions src/utils/github-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ import {
AlertIcon,
CommentDiscussionIcon,
GitCommitIcon,
GitMergeIcon,
GitPullRequestClosedIcon,
GitPullRequestDraftIcon,
GitPullRequestIcon,
IssueClosedIcon,
IssueDraftIcon,
IssueOpenedIcon,
IssueReopenedIcon,
MailIcon,
OcticonProps,
QuestionIcon,
Expand Down Expand Up @@ -66,6 +72,7 @@ export function formatReason(reason: Reason): {

export function getNotificationTypeIcon(
type: SubjectType,
state?: StateType,
): React.FC<OcticonProps> {
switch (type) {
case 'CheckSuite':
Expand All @@ -75,9 +82,27 @@ export function getNotificationTypeIcon(
case 'Discussion':
return CommentDiscussionIcon;
case 'Issue':
return IssueOpenedIcon;
switch (state) {
case 'draft':
return IssueDraftIcon;
case 'closed':
return IssueClosedIcon;
case 'reopened':
return IssueReopenedIcon;
default:
return IssueOpenedIcon;
}
case 'PullRequest':
return GitPullRequestIcon;
switch (state) {
case 'draft':
return GitPullRequestDraftIcon;
case 'closed':
return GitPullRequestClosedIcon;
case 'merged':
return GitMergeIcon;
default:
return GitPullRequestIcon;
}
case 'Release':
return TagIcon;
case 'RepositoryInvitation':
Expand Down