From 13a019e8f97481a11a75f8f80242f7c3487a4b0f Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 21 Jan 2025 12:31:04 -0500 Subject: [PATCH 1/2] feat: migrate to RelativeTime component Signed-off-by: Adam Setch --- .../notifications/NotificationFooter.tsx | 29 +++++----------- src/renderer/utils/helpers.test.ts | 33 ------------------- src/renderer/utils/helpers.ts | 13 -------- 3 files changed, 8 insertions(+), 67 deletions(-) diff --git a/src/renderer/components/notifications/NotificationFooter.tsx b/src/renderer/components/notifications/NotificationFooter.tsx index 09f3cea4f..2b5bd34e1 100644 --- a/src/renderer/components/notifications/NotificationFooter.tsx +++ b/src/renderer/components/notifications/NotificationFooter.tsx @@ -1,15 +1,12 @@ import type { FC, MouseEvent } from 'react'; import { FeedPersonIcon, MarkGithubIcon } from '@primer/octicons-react'; -import { Avatar } from '@primer/react'; +import { Avatar, RelativeTime } from '@primer/react'; import { IconColor, Opacity, Size } from '../../types'; import type { Notification } from '../../typesGitHub'; import { cn } from '../../utils/cn'; -import { - formatNotificationUpdatedAt, - isNonHumanUser, -} from '../../utils/helpers'; +import { isNonHumanUser } from '../../utils/helpers'; import { openUserProfile } from '../../utils/links'; import { formatReason } from '../../utils/reason'; import { Pills } from './Pills'; @@ -23,11 +20,6 @@ export const NotificationFooter: FC = ({ }: INotificationFooter) => { const reason = formatReason(notification.reason); - const updatedAt = formatNotificationUpdatedAt(notification); - const updatedLabel = notification.subject.user - ? `${notification.subject.user.login} updated ${updatedAt}` - : `Updated ${updatedAt}`; - return (
{notification.subject.user ? ( @@ -53,17 +45,12 @@ export const NotificationFooter: FC = ({ )} )} - - {reason.title} - - - {updatedAt} + + + {reason.title} + + +
diff --git a/src/renderer/utils/helpers.test.ts b/src/renderer/utils/helpers.test.ts index b1abe7b8f..5b3d1634c 100644 --- a/src/renderer/utils/helpers.test.ts +++ b/src/renderer/utils/helpers.test.ts @@ -18,7 +18,6 @@ import * as apiRequests from './api/request'; import { formatForDisplay, - formatNotificationUpdatedAt, generateGitHubWebUrl, generateNotificationReferrerId, getChevronDetails, @@ -534,38 +533,6 @@ describe('renderer/utils/helpers.ts', () => { 'Not Planned Issue', ); }); - - describe('formatNotificationUpdatedAt', () => { - it('should use updated_at if last_read_at is null', () => { - const notification = { - ...mockSingleNotification, - last_read_at: null, - updated_at: '2021-06-23T17:00:00Z', - }; - - expect(formatNotificationUpdatedAt(notification)).toContain('ago'); - }); - - it('should return empty if all dates are null', () => { - const notification = { - ...mockSingleNotification, - last_read_at: null, - updated_at: null, - }; - - expect(formatNotificationUpdatedAt(notification)).toBe(''); - }); - - it('should return empty if unable to parse dates', () => { - const notification = { - ...mockSingleNotification, - last_read_at: 'not an iso date', - updated_at: 'not an iso date', - }; - - expect(formatNotificationUpdatedAt(notification)).toBe(''); - }); - }); }); describe('getChevronDetails', () => { diff --git a/src/renderer/utils/helpers.ts b/src/renderer/utils/helpers.ts index c95b8f7ab..a660e9f47 100644 --- a/src/renderer/utils/helpers.ts +++ b/src/renderer/utils/helpers.ts @@ -3,7 +3,6 @@ import { ChevronLeftIcon, ChevronRightIcon, } from '@primer/octicons-react'; -import { formatDistanceToNowStrict, parseISO } from 'date-fns'; import { logError, logWarn } from '../../shared/logger'; import type { Chevron, Hostname, Link } from '../types'; @@ -187,18 +186,6 @@ export function formatForDisplay(text: string[]): string { }); } -export function formatNotificationUpdatedAt( - notification: Notification, -): string { - try { - return formatDistanceToNowStrict(parseISO(notification.updated_at), { - addSuffix: true, - }); - } catch (e) {} - - return ''; -} - export function getChevronDetails( hasNotifications: boolean, isVisible: boolean, From bb855d0073907a0ad9a939f32407bf96486bf03c Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Tue, 21 Jan 2025 12:52:35 -0500 Subject: [PATCH 2/2] feat: migrate to RelativeTime component Signed-off-by: Adam Setch --- .../notifications/NotificationFooter.tsx | 17 +- .../AccountNotifications.test.tsx.snap | 180 +++++-- .../NotificationFooter.test.tsx.snap | 450 ++++++++++++++---- .../NotificationRow.test.tsx.snap | 270 ++++++++--- 4 files changed, 709 insertions(+), 208 deletions(-) diff --git a/src/renderer/components/notifications/NotificationFooter.tsx b/src/renderer/components/notifications/NotificationFooter.tsx index 2b5bd34e1..ca44a26ee 100644 --- a/src/renderer/components/notifications/NotificationFooter.tsx +++ b/src/renderer/components/notifications/NotificationFooter.tsx @@ -1,7 +1,7 @@ import type { FC, MouseEvent } from 'react'; import { FeedPersonIcon, MarkGithubIcon } from '@primer/octicons-react'; -import { Avatar, RelativeTime } from '@primer/react'; +import { Avatar, RelativeTime, Stack, Text } from '@primer/react'; import { IconColor, Opacity, Size } from '../../types'; import type { Notification } from '../../typesGitHub'; @@ -21,7 +21,7 @@ export const NotificationFooter: FC = ({ const reason = formatReason(notification.reason); return ( -
+ {notification.subject.user ? ( = ({ )} - - {reason.title} - - - + + {reason.title} + + + + -
+ ); }; diff --git a/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap b/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap index 8c17fd3d6..150407d1d 100644 --- a/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap +++ b/src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap @@ -835,7 +835,13 @@ exports[`renderer/components/notifications/AccountNotifications.tsx should rende />
- Updated - - - 8 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Authored - - - 8 years ago +
+ + Authored + + + • + + + May 20, 2017 + +
- Updated - - - 8 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Authored - - - 8 years ago +
+ + Authored + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
, "container":
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
, "container":
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
, "container":
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
, "container":
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
, "container":
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +
- Updated - - - 7 years ago +
+ + Updated + + + • + + + May 20, 2017 + +