diff --git a/src/components/NotificationRow.tsx b/src/components/NotificationRow.tsx index 44c049c0a..58c790219 100644 --- a/src/components/NotificationRow.tsx +++ b/src/components/NotificationRow.tsx @@ -7,7 +7,7 @@ import { getNotificationTypeIcon, getNotificationTypeIconColor, } from '../utils/github-api'; -import { openInBrowser } from '../utils/helpers'; +import { formatForDisplay, openInBrowser } from '../utils/helpers'; import { Notification } from '../typesGithub'; import { AppContext } from '../context/App'; @@ -61,10 +61,17 @@ export const NotificationRow: React.FC = ({ const updatedAt = formatDistanceToNow(parseISO(notification.updated_at), { addSuffix: true, }); + const notificationTitle = formatForDisplay([ + notification.subject.state, + notification.subject.type, + ]); return (
-
+
diff --git a/src/components/__snapshots__/NotificationRow.test.tsx.snap b/src/components/__snapshots__/NotificationRow.test.tsx.snap index 643122d32..13da2c7fc 100644 --- a/src/components/__snapshots__/NotificationRow.test.tsx.snap +++ b/src/components/__snapshots__/NotificationRow.test.tsx.snap @@ -6,6 +6,7 @@ exports[`components/Notification.js should render itself & its children 1`] = ` >
{ `${mockedSingleNotification.repository.html_url}?${mockedNotificationReferrer}`, ); }); + + it('formatForDisplay', () => { + expect(formatForDisplay(null)).toBe(''); + expect(formatForDisplay([])).toBe(''); + expect(formatForDisplay(['open', 'PullRequest'])).toBe( + 'Open Pull Request', + ); + expect(formatForDisplay(['OUTDATED', 'Discussion'])).toBe( + 'Outdated Discussion', + ); + expect(formatForDisplay(['not_planned', 'Issue'])).toBe( + 'Not Planned Issue', + ); + }); }); }); diff --git a/src/utils/helpers.ts b/src/utils/helpers.ts index 322fb6286..995e67563 100644 --- a/src/utils/helpers.ts +++ b/src/utils/helpers.ts @@ -225,6 +225,21 @@ export async function generateGitHubWebUrl( return url; } +export function formatForDisplay(text: string[]) { + if (!text) { + return ''; + } + + return text + .join(' ') + .replace(/([a-z])([A-Z])/g, '$1 $2') // Add space between lowercase character followed by an uppercase character + .replace(/_/g, ' ') // Replace underscores with spaces + .replace(/\w+/g, (word) => { + // Convert to proper case (capitalize first letter of each word) + return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase(); + }); +} + export async function openInBrowser( notification: Notification, accounts: AuthState,