diff --git a/src/renderer/components/avatars/AvatarWithFallback.tsx b/src/renderer/components/avatars/AvatarWithFallback.tsx index 93a51ae02..fc6607372 100644 --- a/src/renderer/components/avatars/AvatarWithFallback.tsx +++ b/src/renderer/components/avatars/AvatarWithFallback.tsx @@ -1,12 +1,12 @@ import type React from 'react'; import { useState } from 'react'; -import { FeedPersonIcon, MarkGithubIcon } from '@primer/octicons-react'; import { Avatar, Stack, Truncate } from '@primer/react'; import { type Link, Size } from '../../types'; import type { UserType } from '../../typesGitHub'; -import { isNonHumanUser } from '../../utils/helpers'; +import { getDefaultUserIcon } from '../../utils/icons'; +import { isNonHumanUser } from '../../utils/notifications/filters/userType'; export interface IAvatarWithFallback { src?: Link; @@ -26,7 +26,7 @@ export const AvatarWithFallback: React.FC = ({ const [isBroken, setIsBroken] = useState(false); const isNonHuman = isNonHumanUser(userType); - const DefaultUserIcon = isNonHuman ? MarkGithubIcon : FeedPersonIcon; + const DefaultUserIcon = getDefaultUserIcon(userType); // TODO explore using AnchoredOverlay component (https://primer.style/components/anchored-overlay/react/alpha) to render Avatar Card on hover return ( diff --git a/src/renderer/utils/helpers.test.ts b/src/renderer/utils/helpers.test.ts index 5b3d1634c..ffaa1e939 100644 --- a/src/renderer/utils/helpers.test.ts +++ b/src/renderer/utils/helpers.test.ts @@ -23,7 +23,6 @@ import { getChevronDetails, getPlatformFromHostname, isEnterpriseServerHost, - isNonHumanUser, } from './helpers'; describe('renderer/utils/helpers.ts', () => { @@ -553,12 +552,4 @@ describe('renderer/utils/helpers.ts', () => { }); }); }); - - it('isNonHumanUser', () => { - expect(isNonHumanUser('User')).toBe(false); - expect(isNonHumanUser('EnterpriseUserAccount')).toBe(false); - expect(isNonHumanUser('Bot')).toBe(true); - expect(isNonHumanUser('Organization')).toBe(true); - expect(isNonHumanUser('Mannequin')).toBe(true); - }); }); diff --git a/src/renderer/utils/helpers.ts b/src/renderer/utils/helpers.ts index a660e9f47..be4b47566 100644 --- a/src/renderer/utils/helpers.ts +++ b/src/renderer/utils/helpers.ts @@ -6,7 +6,7 @@ import { import { logError, logWarn } from '../../shared/logger'; import type { Chevron, Hostname, Link } from '../types'; -import type { Notification, UserType } from '../typesGitHub'; +import type { Notification } from '../typesGitHub'; import { getHtmlUrl, getLatestDiscussion } from './api/client'; import type { PlatformType } from './auth/types'; import { Constants } from './constants'; @@ -210,7 +210,3 @@ export function getChevronDetails( label: `Show ${type} notifications`, }; } - -export function isNonHumanUser(type: UserType): boolean { - return type === 'Bot' || type === 'Organization' || type === 'Mannequin'; -} diff --git a/src/renderer/utils/icons.test.ts b/src/renderer/utils/icons.test.ts index 4c935f6a1..c037d27f5 100644 --- a/src/renderer/utils/icons.test.ts +++ b/src/renderer/utils/icons.test.ts @@ -1,4 +1,11 @@ -import { CheckIcon, CommentIcon, FileDiffIcon } from '@primer/octicons-react'; +import { + CheckIcon, + CommentIcon, + FeedPersonIcon, + FileDiffIcon, + MarkGithubIcon, + OrganizationIcon, +} from '@primer/octicons-react'; import { IconColor } from '../types'; import type { GitifyPullRequestReview, @@ -8,6 +15,7 @@ import type { } from '../typesGitHub'; import { getAuthMethodIcon, + getDefaultUserIcon, getNotificationTypeIcon, getNotificationTypeIconColor, getPlatformIcon, @@ -412,6 +420,14 @@ describe('renderer/utils/icons.ts', () => { expect(getPlatformIcon('GitHub Enterprise Server')).toMatchSnapshot(); }); + + describe('getDefaultUserIcon', () => { + expect(getDefaultUserIcon('Bot')).toBe(MarkGithubIcon); + expect(getDefaultUserIcon('EnterpriseUserAccount')).toBe(FeedPersonIcon); + expect(getDefaultUserIcon('Mannequin')).toBe(MarkGithubIcon); + expect(getDefaultUserIcon('Organization')).toBe(OrganizationIcon); + expect(getDefaultUserIcon('User')).toBe(FeedPersonIcon); + }); }); function createSubjectMock(mocks: { diff --git a/src/renderer/utils/icons.ts b/src/renderer/utils/icons.ts index 8641f913e..46996a806 100644 --- a/src/renderer/utils/icons.ts +++ b/src/renderer/utils/icons.ts @@ -7,6 +7,7 @@ import { DiscussionClosedIcon, DiscussionDuplicateIcon, DiscussionOutdatedIcon, + FeedPersonIcon, FileDiffIcon, GitCommitIcon, GitMergeIcon, @@ -21,6 +22,7 @@ import { MailIcon, MarkGithubIcon, type OcticonProps, + OrganizationIcon, PersonIcon, QuestionIcon, RocketIcon, @@ -32,7 +34,11 @@ import { } from '@primer/octicons-react'; import type { FC } from 'react'; import { IconColor, type PullRequestApprovalIcon } from '../types'; -import type { GitifyPullRequestReview, Subject } from '../typesGitHub'; +import type { + GitifyPullRequestReview, + Subject, + UserType, +} from '../typesGitHub'; import type { AuthMethod, PlatformType } from './auth/types'; export function getNotificationTypeIcon(subject: Subject): FC { @@ -180,3 +186,15 @@ export function getPlatformIcon( return MarkGithubIcon; } } + +export function getDefaultUserIcon(userType: UserType) { + switch (userType) { + case 'Bot': + case 'Mannequin': + return MarkGithubIcon; + case 'Organization': + return OrganizationIcon; + default: + return FeedPersonIcon; + } +} diff --git a/src/renderer/utils/notifications/filters/userType.test.ts b/src/renderer/utils/notifications/filters/userType.test.ts new file mode 100644 index 000000000..6d19be2bf --- /dev/null +++ b/src/renderer/utils/notifications/filters/userType.test.ts @@ -0,0 +1,15 @@ +import { isNonHumanUser } from './userType'; + +describe('renderer/utils/notifications/filters/userType.ts', () => { + afterEach(() => { + jest.clearAllMocks(); + }); + + it('isNonHumanUser', () => { + expect(isNonHumanUser('User')).toBe(false); + expect(isNonHumanUser('EnterpriseUserAccount')).toBe(false); + expect(isNonHumanUser('Bot')).toBe(true); + expect(isNonHumanUser('Organization')).toBe(true); + expect(isNonHumanUser('Mannequin')).toBe(true); + }); +}); diff --git a/src/renderer/utils/notifications/filters/userType.ts b/src/renderer/utils/notifications/filters/userType.ts index 774d21829..0597934db 100644 --- a/src/renderer/utils/notifications/filters/userType.ts +++ b/src/renderer/utils/notifications/filters/userType.ts @@ -60,3 +60,7 @@ export function filterNotificationByUserType( return notification.subject?.user?.type === userType; } + +export function isNonHumanUser(type: UserType): boolean { + return type === 'Bot' || type === 'Organization' || type === 'Mannequin'; +} diff --git a/src/renderer/utils/subject.ts b/src/renderer/utils/subject.ts index 9bb85c02c..1f18e8038 100644 --- a/src/renderer/utils/subject.ts +++ b/src/renderer/utils/subject.ts @@ -297,7 +297,7 @@ export async function getLatestReviewForReviewers( // Find the most recent review for each reviewer const latestReviews: PullRequestReview[] = []; - const sortedReviews = prReviews.data.reverse(); + const sortedReviews = prReviews.data.reverse(); for (const prReview of sortedReviews) { const reviewerFound = latestReviews.find( (review) => review.user.login === prReview.user.login,