Skip to content
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/__mocks__/mockedData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ export const mockedGitHubNotifications: Notification[] = [
'https://avatars.githubusercontent.com/u/133795385?s=200&v=4',
type: 'User',
},
reviews: [
{
state: 'APPROVED',
users: ['octocat'],
},
{
state: 'CHANGES_REQUESTED',
users: ['gitify-app'],
},
{
state: 'PENDING',
users: ['gitify-user'],
},
],
},
repository: {
id: 57216596,
Expand Down Expand Up @@ -198,6 +212,7 @@ export const mockedGitHubNotifications: Notification[] = [
latest_comment_url:
'https://api.github.com/repos/gitify-app/notifications-test/issues/comments/302885965',
type: 'Issue',
reviews: null,
},
repository: {
id: 57216596,
Expand Down Expand Up @@ -255,6 +270,7 @@ export const mockedEnterpriseNotifications: Notification[] = [
latest_comment_url:
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/releases/3',
type: 'Release',
reviews: null,
},
repository: {
id: 1,
Expand Down Expand Up @@ -308,6 +324,7 @@ export const mockedEnterpriseNotifications: Notification[] = [
latest_comment_url:
'https://github.gitify.io/api/v3/repos/myorg/notifications-test/issues/comments/21',
type: 'PullRequest',
reviews: null,
},
repository: {
id: 1,
Expand Down
2 changes: 2 additions & 0 deletions src/__mocks__/partial-mocks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import type { Notification, Subject, User } from '../typesGitHub';
import Constants from '../utils/constants';

export function partialMockNotification(
subject: Partial<Subject>,
): Notification {
const mockNotification: Partial<Notification> = {
hostname: Constants.GITHUB_API_BASE_URL,
subject: subject as Subject,
};

Expand Down
1 change: 1 addition & 0 deletions src/components/NotificationRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ describe('components/NotificationRow.tsx', () => {
avatar_url: 'https://avatars.githubusercontent.com/u/123456789?v=4',
type: 'User' as UserType,
},
reviews: null,
},
},
hostname: 'github.com',
Expand Down
26 changes: 25 additions & 1 deletion src/components/NotificationRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { formatForDisplay, openInBrowser } from '../utils/helpers';
import {
getNotificationTypeIcon,
getNotificationTypeIconColor,
getPullRequestReviewIcon,
} from '../utils/icons';
import { formatReason } from '../utils/reason';

Expand Down Expand Up @@ -69,13 +70,14 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
const reason = formatReason(notification.reason);
const NotificationIcon = getNotificationTypeIcon(notification.subject);
const iconColor = getNotificationTypeIconColor(notification.subject);

const updatedAt = formatDistanceToNow(parseISO(notification.updated_at), {
addSuffix: true,
});

const updatedLabel = notification.subject.user
? `${notification.subject.user.login} updated ${updatedAt}`
: `Updated ${updatedAt}`;

const notificationTitle = formatForDisplay([
notification.subject.state,
notification.subject.type,
Expand Down Expand Up @@ -131,6 +133,28 @@ export const NotificationRow: FC<IProps> = ({ notification, hostname }) => {
{reason.title}
</span>
<span className="ml-1">{updatedAt}</span>
{notification.subject.reviews
? notification.subject.reviews.map((review) => {
const icon = getPullRequestReviewIcon(review);
if (!icon) {
return null;
}

return (
<span
key={review.state}
title={icon.description}
className="ml-1"
>
<icon.type
size={16}
className={icon.color}
aria-label={icon.description}
/>
</span>
);
})
: null}
</span>
</span>
</div>
Expand Down
108 changes: 108 additions & 0 deletions src/components/__snapshots__/NotificationRow.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions src/routes/__snapshots__/Notifications.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { OcticonProps } from '@primer/octicons-react';
import type { FC } from 'react';
import type { Notification } from './typesGitHub';

export interface AuthState {
Expand Down Expand Up @@ -101,4 +103,11 @@ export enum IconColor {
GREEN = 'text-green-500',
PURPLE = 'text-purple-500',
RED = 'text-red-500',
YELLOW = 'text-yellow-500 dark:text-yellow-300',
}

export type PullRequestApprovalIcon = {
type: FC<OcticonProps>;
color: IconColor;
description: string;
};
Loading