Skip to content

Commit 2f3e11f

Browse files
authored
feat: show notification last update user (#898)
1 parent f0f74fa commit 2f3e11f

File tree

9 files changed

+337
-91
lines changed

9 files changed

+337
-91
lines changed

src/__mocks__/mockedData.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,68 +299,101 @@ export const mockedGraphQLResponse: GraphQLSearch<DiscussionSearchResultNode> =
299299
{
300300
databaseId: 2215656,
301301
createdAt: '2022-02-20T18:33:39Z',
302+
author: {
303+
login: 'comment-user',
304+
},
302305
replies: {
303306
nodes: [],
304307
},
305308
},
306309
{
307310
databaseId: 2217789,
308311
createdAt: '2022-02-21T03:30:42Z',
312+
author: {
313+
login: 'comment-user',
314+
},
309315
replies: {
310316
nodes: [],
311317
},
312318
},
313319
{
314320
databaseId: 2223243,
315321
createdAt: '2022-02-21T18:26:27Z',
322+
author: {
323+
login: 'comment-user',
324+
},
316325
replies: {
317326
nodes: [
318327
{
319328
databaseId: 2232922,
320329
createdAt: '2022-02-23T00:57:58Z',
330+
author: {
331+
login: 'reply-user',
332+
},
321333
},
322334
],
323335
},
324336
},
325337
{
326338
databaseId: 2232921,
327339
createdAt: '2022-02-23T00:57:49Z',
340+
author: {
341+
login: 'comment-user',
342+
},
328343
replies: {
329344
nodes: [],
330345
},
331346
},
332347
{
333348
databaseId: 2258799,
334349
createdAt: '2022-02-27T01:22:20Z',
350+
author: {
351+
login: 'comment-user',
352+
},
335353
replies: {
336354
nodes: [
337355
{
338356
databaseId: 2300902,
339357
createdAt: '2022-03-05T17:43:52Z',
358+
author: {
359+
login: 'reply-user',
360+
},
340361
},
341362
],
342363
},
343364
},
344365
{
345366
databaseId: 2297637,
346367
createdAt: '2022-03-04T20:39:44Z',
368+
author: {
369+
login: 'comment-user',
370+
},
347371
replies: {
348372
nodes: [
349373
{
350374
databaseId: 2300893,
351375
createdAt: '2022-03-05T17:41:04Z',
376+
author: {
377+
login: 'reply-user',
378+
},
352379
},
353380
],
354381
},
355382
},
356383
{
357384
databaseId: 2299763,
358385
createdAt: '2022-03-05T11:05:42Z',
386+
author: {
387+
login: 'comment-user',
388+
},
359389
replies: {
360390
nodes: [
361391
{
362392
databaseId: 2300895,
363393
createdAt: '2022-03-05T17:41:44Z',
394+
author: {
395+
login: 'reply-user',
396+
},
364397
},
365398
],
366399
},
@@ -379,68 +412,101 @@ export const mockedGraphQLResponse: GraphQLSearch<DiscussionSearchResultNode> =
379412
{
380413
databaseId: 2215656,
381414
createdAt: '2022-02-20T18:33:39Z',
415+
author: {
416+
login: 'comment-user',
417+
},
382418
replies: {
383419
nodes: [],
384420
},
385421
},
386422
{
387423
databaseId: 2217789,
388424
createdAt: '2022-02-21T03:30:42Z',
425+
author: {
426+
login: 'comment-user',
427+
},
389428
replies: {
390429
nodes: [],
391430
},
392431
},
393432
{
394433
databaseId: 2223243,
395434
createdAt: '2022-02-21T18:26:27Z',
435+
author: {
436+
login: 'comment-user',
437+
},
396438
replies: {
397439
nodes: [
398440
{
399441
databaseId: 2232922,
400442
createdAt: '2022-02-23T00:57:58Z',
443+
author: {
444+
login: 'reply-user',
445+
},
401446
},
402447
],
403448
},
404449
},
405450
{
406451
databaseId: 2232921,
407452
createdAt: '2022-02-23T00:57:49Z',
453+
author: {
454+
login: 'comment-user',
455+
},
408456
replies: {
409457
nodes: [],
410458
},
411459
},
412460
{
413461
databaseId: 2258799,
414462
createdAt: '2022-02-27T01:22:20Z',
463+
author: {
464+
login: 'comment-user',
465+
},
415466
replies: {
416467
nodes: [
417468
{
418469
databaseId: 2300902,
419470
createdAt: '2022-03-05T17:43:52Z',
471+
author: {
472+
login: 'reply-user',
473+
},
420474
},
421475
],
422476
},
423477
},
424478
{
425479
databaseId: 2297637,
426480
createdAt: '2022-03-04T20:39:44Z',
481+
author: {
482+
login: 'comment-user',
483+
},
427484
replies: {
428485
nodes: [
429486
{
430487
databaseId: 2300893,
431488
createdAt: '2022-03-05T17:41:04Z',
489+
author: {
490+
login: 'reply-user',
491+
},
432492
},
433493
],
434494
},
435495
},
436496
{
437497
databaseId: 2299763,
438498
createdAt: '2022-03-05T11:05:42Z',
499+
author: {
500+
login: 'comment-user',
501+
},
439502
replies: {
440503
nodes: [
441504
{
442505
databaseId: 2300895,
443506
createdAt: '2022-03-05T17:41:44Z',
507+
author: {
508+
login: 'reply-user',
509+
},
444510
},
445511
],
446512
},

src/components/NotificationRow.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ export const NotificationRow: React.FC<IProps> = ({
6161
const updatedAt = formatDistanceToNow(parseISO(notification.updated_at), {
6262
addSuffix: true,
6363
});
64+
const updatedBy = notification.subject.user
65+
? ` by ${notification.subject.user}`
66+
: '';
67+
const updatedLabel = `Updated ${updatedAt}${updatedBy}`;
6468
const notificationTitle = formatForDisplay([
6569
notification.subject.state,
6670
notification.subject.type,
@@ -87,9 +91,9 @@ export const NotificationRow: React.FC<IProps> = ({
8791
{notification.subject.title}
8892
</div>
8993

90-
<div className="text-xs text-capitalize">
91-
<span title={reason.description}>{reason.type}</span> - Updated{' '}
92-
{updatedAt}
94+
<div className="text-xs text-capitalize whitespace-nowrap overflow-ellipsis overflow-hidden">
95+
<span title={reason.description}>{reason.type}</span> -{' '}
96+
<span title={updatedLabel}>{updatedLabel}</span>
9397
</div>
9498
</div>
9599

src/components/__snapshots__/NotificationRow.test.tsx.snap

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,20 @@ exports[`components/Notification.js should render itself & its children 1`] = `
4747
I am a robot and this is a test!
4848
</div>
4949
<div
50-
className="text-xs text-capitalize"
50+
className="text-xs text-capitalize whitespace-nowrap overflow-ellipsis overflow-hidden"
5151
>
5252
<span
5353
title="You're watching the repository."
5454
>
5555
Subscribed
5656
</span>
57-
- Updated
57+
-
5858
59-
in over 3 years
59+
<span
60+
title="Updated in over 3 years"
61+
>
62+
Updated in over 3 years
63+
</span>
6064
</div>
6165
</div>
6266
<div

src/hooks/useNotifications.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ describe('hooks/useNotifications.ts', () => {
219219
title: 'This is an Issue.',
220220
type: 'Issue',
221221
url: 'https://api.github.com/3',
222+
latest_comment_url: 'https://api.github.com/3/comments',
222223
},
223224
},
224225
{
@@ -227,6 +228,7 @@ describe('hooks/useNotifications.ts', () => {
227228
title: 'This is a Pull Request.',
228229
type: 'PullRequest',
229230
url: 'https://api.github.com/4',
231+
latest_comment_url: 'https://api.github.com/4/comments',
230232
},
231233
},
232234
{
@@ -258,21 +260,43 @@ describe('hooks/useNotifications.ts', () => {
258260
search: {
259261
nodes: [
260262
{
261-
title: 'This is an answered discussion',
263+
title: 'This is a Discussion.',
262264
viewerSubscription: 'SUBSCRIBED',
263265
stateReason: null,
264266
isAnswered: true,
267+
url: 'https://github.com/manosim/notifications-test/discussions/612',
268+
comments: {
269+
nodes: [
270+
{
271+
databaseId: 2297637,
272+
createdAt: '2022-03-04T20:39:44Z',
273+
author: {
274+
login: 'comment-user',
275+
},
276+
replies: {
277+
nodes: [],
278+
},
279+
},
280+
],
281+
},
265282
},
266283
],
267284
},
268285
},
269286
});
287+
270288
nock('https://api.github.com')
271289
.get('/3')
272290
.reply(200, { state: 'closed', merged: true });
291+
nock('https://api.github.com')
292+
.get('/3/comments')
293+
.reply(200, { user: { login: 'some-user' } });
273294
nock('https://api.github.com')
274295
.get('/4')
275296
.reply(200, { state: 'closed', merged: false });
297+
nock('https://api.github.com')
298+
.get('/4/comments')
299+
.reply(200, { user: { login: 'some-user' } });
276300
nock('https://api.github.com')
277301
.get('/5')
278302
.reply(200, { state: 'open', draft: false });

src/hooks/useNotifications.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import {
1717
} from '../utils/notifications';
1818
import Constants from '../utils/constants';
1919
import { removeNotifications } from '../utils/remove-notifications';
20-
import { getNotificationState } from '../utils/state';
20+
import { getGitifySubjectDetails } from '../utils/subject';
2121

2222
interface NotificationsState {
2323
notifications: AccountNotifications[];
@@ -141,16 +141,14 @@ export const useNotifications = (colors: boolean): NotificationsState => {
141141
)
142142
: accounts.token;
143143

144-
const notificationState = await getNotificationState(
145-
notification,
146-
token,
147-
);
144+
const additionalSubjectDetails =
145+
await getGitifySubjectDetails(notification, token);
148146

149147
return {
150148
...notification,
151149
subject: {
152150
...notification.subject,
153-
state: notificationState,
151+
...additionalSubjectDetails,
154152
},
155153
};
156154
},

src/typesGithub.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,14 +157,21 @@ export interface Owner {
157157
site_admin: boolean;
158158
}
159159

160-
export interface Subject {
160+
export type Subject = GitHubSubject & GitifySubject;
161+
162+
interface GitHubSubject {
161163
title: string;
162164
url: string | null;
163-
state?: StateType; // This is not in the GitHub API, but we add it to the type to make it easier to work with
164165
latest_comment_url: string | null;
165166
type: SubjectType;
166167
}
167168

169+
// This is not in the GitHub API, but we add it to the type to make it easier to work with
170+
export interface GitifySubject {
171+
state?: StateType;
172+
user?: string;
173+
}
174+
168175
export interface PullRequest {
169176
url: string;
170177
id: number;
@@ -262,6 +269,7 @@ export interface DiscussionSearchResultNode {
262269
export interface DiscussionCommentNode {
263270
databaseId: string | number;
264271
createdAt: string;
272+
author: { login: string };
265273
replies: {
266274
nodes: DiscussionSubcommentNode[];
267275
};
@@ -270,6 +278,7 @@ export interface DiscussionCommentNode {
270278
export interface DiscussionSubcommentNode {
271279
databaseId: string | number;
272280
createdAt: string;
281+
author: { login: string };
273282
}
274283

275284
export interface CheckSuiteAttributes {

0 commit comments

Comments
 (0)