diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index ed5b3f543..517b5d7f9 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -16,11 +16,11 @@ import { import { AppContext } from '../context/App'; import type { Notification } from '../typesGithub'; import { openExternalLink } from '../utils/comms'; +import { formatForDisplay, openInBrowser } from '../utils/helpers'; import { getNotificationTypeIcon, getNotificationTypeIconColor, -} from '../utils/github-api'; -import { formatForDisplay, openInBrowser } from '../utils/helpers'; +} from '../utils/icons'; import { formatReason } from '../utils/reason'; interface IProps { diff --git a/src/types.ts b/src/types.ts index 1b318fb84..fb4f00fb2 100644 --- a/src/types.ts +++ b/src/types.ts @@ -93,3 +93,10 @@ export interface FormattedReason { title: string; description: string; } + +export enum IconColor { + GREEN = 'text-green-500', + RED = 'text-red-500', + PURPLE = 'text-purple-500', + GRAY = 'text-gray-500 dark:text-gray-300', +} diff --git a/src/utils/__snapshots__/github-api.test.ts.snap b/src/utils/__snapshots__/github-api.test.ts.snap deleted file mode 100644 index 2c5335a0f..000000000 --- a/src/utils/__snapshots__/github-api.test.ts.snap +++ /dev/null @@ -1,31 +0,0 @@ -// Jest Snapshot v1, https://goo.gl/fbAQLP - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 1`] = `"text-gray-500 dark:text-gray-300"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 2`] = `"text-red-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 3`] = `"text-gray-500 dark:text-gray-300"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 4`] = `"text-green-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for check suite 5`] = `"text-gray-500 dark:text-gray-300"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 1`] = `"text-green-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 2`] = `"text-red-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 3`] = `"text-purple-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 4`] = `"text-gray-500 dark:text-gray-300"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 5`] = `"text-purple-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 6`] = `"text-gray-500 dark:text-gray-300"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 8`] = `"text-green-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 9`] = `"text-purple-500"`; - -exports[`utils/github-api.ts getNotificationTypeIconColor should format the notification color for state 10`] = `"text-gray-500 dark:text-gray-300"`; diff --git a/src/utils/__snapshots__/icons.test.ts.snap b/src/utils/__snapshots__/icons.test.ts.snap new file mode 100644 index 000000000..40d0bfd9a --- /dev/null +++ b/src/utils/__snapshots__/icons.test.ts.snap @@ -0,0 +1,31 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for check suite 1`] = `"text-gray-500 dark:text-gray-300"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for check suite 2`] = `"text-red-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for check suite 3`] = `"text-gray-500 dark:text-gray-300"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for check suite 4`] = `"text-green-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for check suite 5`] = `"text-gray-500 dark:text-gray-300"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 1`] = `"text-green-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 2`] = `"text-red-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 3`] = `"text-purple-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 4`] = `"text-gray-500 dark:text-gray-300"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 5`] = `"text-purple-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 6`] = `"text-gray-500 dark:text-gray-300"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 7`] = `"text-green-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 8`] = `"text-green-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 9`] = `"text-purple-500"`; + +exports[`utils/icons.ts getNotificationTypeIconColor should format the notification color for state 10`] = `"text-gray-500 dark:text-gray-300"`; diff --git a/src/utils/github-api.test.ts b/src/utils/icons.test.ts similarity index 98% rename from src/utils/github-api.test.ts rename to src/utils/icons.test.ts index 70ebd6b3a..f80e600ae 100644 --- a/src/utils/github-api.test.ts +++ b/src/utils/icons.test.ts @@ -1,10 +1,7 @@ import type { StateType, Subject, SubjectType } from '../typesGithub'; -import { - getNotificationTypeIcon, - getNotificationTypeIconColor, -} from './github-api'; +import { getNotificationTypeIcon, getNotificationTypeIconColor } from './icons'; -describe('utils/github-api.ts', () => { +describe('utils/icons.ts', () => { describe('getNotificationTypeIcon - should get the notification type icon', () => { expect( getNotificationTypeIcon( diff --git a/src/utils/github-api.ts b/src/utils/icons.ts similarity index 93% rename from src/utils/github-api.ts rename to src/utils/icons.ts index f392fdfe4..a7cef5e02 100644 --- a/src/utils/github-api.ts +++ b/src/utils/icons.ts @@ -24,6 +24,7 @@ import { XIcon, } from '@primer/octicons-react'; import type { FC } from 'react'; +import { IconColor } from '../types'; import type { Subject } from '../typesGithub'; export function getNotificationTypeIcon(subject: Subject): FC { @@ -92,21 +93,21 @@ export function getNotificationTypeIcon(subject: Subject): FC { } } -export function getNotificationTypeIconColor(subject: Subject): string { +export function getNotificationTypeIconColor(subject: Subject): IconColor { switch (subject.state) { case 'open': case 'reopened': case 'ANSWERED': case 'success': - return 'text-green-500'; + return IconColor.GREEN; case 'closed': case 'failure': - return 'text-red-500'; + return IconColor.RED; case 'completed': case 'RESOLVED': case 'merged': - return 'text-purple-500'; + return IconColor.PURPLE; default: - return 'text-gray-500 dark:text-gray-300'; + return IconColor.GRAY; } }