diff --git a/src/renderer/__mocks__/notifications-mocks.ts b/src/renderer/__mocks__/notifications-mocks.ts index 338731d4e..27b320014 100644 --- a/src/renderer/__mocks__/notifications-mocks.ts +++ b/src/renderer/__mocks__/notifications-mocks.ts @@ -2,6 +2,7 @@ import { Constants } from '../constants'; import type { AccountNotifications, GitifyNotification, + GitifyReason, GitifyRepository, GitifySubject, Hostname, @@ -53,6 +54,11 @@ export function createPartialMockNotification( user: mockGitifyUser, hasRequiredScopes: true, }, + reason: { + code: 'subscribed', + title: 'Updated', + description: "You're watching the repository.", + } as GitifyReason, subject: subject as GitifySubject, repository: { name: 'notifications-test', diff --git a/src/renderer/components/notifications/NotificationFooter.tsx b/src/renderer/components/notifications/NotificationFooter.tsx index 9bc01181a..b3f2c40b5 100644 --- a/src/renderer/components/notifications/NotificationFooter.tsx +++ b/src/renderer/components/notifications/NotificationFooter.tsx @@ -5,7 +5,6 @@ import { RelativeTime, Stack, Text } from '@primer/react'; import { type GitifyNotification, Opacity, Size } from '../../types'; import { cn } from '../../utils/cn'; import { openUserProfile } from '../../utils/links'; -import { getReasonDetails } from '../../utils/reason'; import { AvatarWithFallback } from '../avatars/AvatarWithFallback'; import { MetricGroup } from '../metrics/MetricGroup'; @@ -16,8 +15,6 @@ interface NotificationFooterProps { export const NotificationFooter: FC = ({ notification, }: NotificationFooterProps) => { - const reason = getReasonDetails(notification.reason); - return ( = ({ )} - - {reason.title} + + {notification.reason.title} diff --git a/src/renderer/types.ts b/src/renderer/types.ts index 7939504a5..bbf6231b9 100644 --- a/src/renderer/types.ts +++ b/src/renderer/types.ts @@ -277,7 +277,7 @@ export interface GitifyNotification { /** When the notification was last updated */ updatedAt: string; /** Reason for receiving the notification */ - reason: Reason; + reason: GitifyReason; /** Subject details (what the notification is about) */ subject: GitifySubject; /** Repository context */ @@ -288,6 +288,18 @@ export interface GitifyNotification { order: number; } +/** + * Notification reason details + */ +export interface GitifyReason { + /** Reason code */ + code: Reason; + /** Reason title */ + title: string; + /** Reason description */ + description: string; +} + /** * Subject information combining REST and GraphQL enriched data. */ diff --git a/src/renderer/utils/api/__mocks__/response-mocks.ts b/src/renderer/utils/api/__mocks__/response-mocks.ts index 575872792..cadf5514c 100644 --- a/src/renderer/utils/api/__mocks__/response-mocks.ts +++ b/src/renderer/utils/api/__mocks__/response-mocks.ts @@ -51,7 +51,11 @@ export const mockGitHubNotifications: GitifyNotification[] = [ order: 0, id: '138661096', unread: true, - reason: 'subscribed', + reason: { + code: 'subscribed', + title: 'Updated', + description: "You're watching the repository.", + }, updatedAt: '2017-05-20T17:51:57Z', subject: { title: 'I am a robot and this is a test!', @@ -83,7 +87,11 @@ export const mockGitHubNotifications: GitifyNotification[] = [ order: 1, id: '148827438', unread: true, - reason: 'author', + reason: { + code: 'author', + title: 'Authored', + description: 'You created the thread.', + }, updatedAt: '2017-05-20T17:06:34Z', subject: { title: 'Improve the UI', @@ -119,7 +127,11 @@ export const mockEnterpriseNotifications: GitifyNotification[] = [ order: 0, id: '3', unread: true, - reason: 'subscribed', + reason: { + code: 'subscribed', + title: 'Updated', + description: "You're watching the repository.", + }, updatedAt: '2017-05-20T13:02:48Z', subject: { title: 'Release 0.0.1', @@ -136,7 +148,11 @@ export const mockEnterpriseNotifications: GitifyNotification[] = [ order: 1, id: '4', unread: true, - reason: 'subscribed', + reason: { + code: 'subscribed', + title: 'Updated', + description: "You're watching the repository.", + }, updatedAt: '2017-05-20T15:52:20Z', subject: { title: 'Bump Version', diff --git a/src/renderer/utils/api/transform.ts b/src/renderer/utils/api/transform.ts index 63b747394..f299d6a7b 100644 --- a/src/renderer/utils/api/transform.ts +++ b/src/renderer/utils/api/transform.ts @@ -2,6 +2,7 @@ import type { Account, GitifyNotification, GitifyOwner, + GitifyReason, GitifyRepository, GitifySubject, Link, @@ -9,6 +10,7 @@ import type { SubjectType, UserType, } from '../../types'; +import { getReasonDetails } from '../reason'; import type { RawGitHubNotification } from './types'; /** @@ -27,7 +29,7 @@ export function transformNotification( id: raw.id, unread: raw.unread, updatedAt: raw.updated_at, - reason: raw.reason as Reason, + reason: transformReason(raw.reason), subject: transformSubject(raw.subject), repository: transformRepository(raw.repository), account, @@ -35,6 +37,16 @@ export function transformNotification( }; } +function transformReason(raw: RawGitHubNotification['reason']): GitifyReason { + const reasonDetails = getReasonDetails(raw as Reason); + + return { + code: raw as Reason, + title: reasonDetails.title, + description: reasonDetails.description, + }; +} + function transformSubject( raw: RawGitHubNotification['subject'], ): GitifySubject { diff --git a/src/renderer/utils/notifications/filters/filter.test.ts b/src/renderer/utils/notifications/filters/filter.test.ts index 3d53bcef6..13d543c11 100644 --- a/src/renderer/utils/notifications/filters/filter.test.ts +++ b/src/renderer/utils/notifications/filters/filter.test.ts @@ -76,8 +76,8 @@ describe('renderer/utils/notifications/filters/filter.ts', () => { }); it('should filter notifications by reasons when provided', async () => { - mockNotifications[0].reason = 'subscribed'; - mockNotifications[1].reason = 'manual'; + mockNotifications[0].reason.code = 'subscribed'; + mockNotifications[1].reason.code = 'manual'; const result = filterBaseNotifications(mockNotifications, { ...mockSettings, filterReasons: ['manual'], diff --git a/src/renderer/utils/notifications/filters/reason.ts b/src/renderer/utils/notifications/filters/reason.ts index eddf66c7e..c0472a333 100644 --- a/src/renderer/utils/notifications/filters/reason.ts +++ b/src/renderer/utils/notifications/filters/reason.ts @@ -42,6 +42,6 @@ export const reasonFilter: Filter = { notification: GitifyNotification, reason: Reason, ): boolean { - return notification.reason === reason; + return notification.reason.code === reason; }, };