Skip to content

Commit 6493d7f

Browse files
authored
feat: notification number relo for groupByDate mode (#1762)
* feat: notification number relo for groupByDate mode Signed-off-by: Adam Setch <[email protected]> * feat: notification number relo for groupByDate mode Signed-off-by: Adam Setch <[email protected]> --------- Signed-off-by: Adam Setch <[email protected]>
1 parent c3a4b3c commit 6493d7f

File tree

6 files changed

+386
-23
lines changed

6 files changed

+386
-23
lines changed

src/renderer/components/notifications/NotificationHeader.test.tsx

Lines changed: 53 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,60 @@ describe('renderer/components/notifications/NotificationHeader.tsx', () => {
2626
expect(tree).toMatchSnapshot();
2727
});
2828

29-
it('should render itself & its children - group by date', async () => {
30-
const props = {
31-
notification: mockSingleNotification,
32-
};
29+
describe('should render itself & its children - group by date', () => {
30+
it('with notification number', async () => {
31+
const props = {
32+
notification: mockSingleNotification,
33+
};
3334

34-
const tree = render(
35-
<AppContext.Provider
36-
value={{ settings: { ...mockSettings, groupBy: GroupBy.DATE } }}
37-
>
38-
<NotificationHeader {...props} />
39-
</AppContext.Provider>,
40-
);
41-
expect(tree).toMatchSnapshot();
35+
const tree = render(
36+
<AppContext.Provider
37+
value={{ settings: { ...mockSettings, groupBy: GroupBy.DATE } }}
38+
>
39+
<NotificationHeader {...props} />
40+
</AppContext.Provider>,
41+
);
42+
expect(tree).toMatchSnapshot();
43+
});
44+
45+
it('with showNumber setting disabled', async () => {
46+
const props = {
47+
notification: mockSingleNotification,
48+
};
49+
50+
const tree = render(
51+
<AppContext.Provider
52+
value={{
53+
settings: {
54+
...mockSettings,
55+
showNumber: false,
56+
groupBy: GroupBy.DATE,
57+
},
58+
}}
59+
>
60+
<NotificationHeader {...props} />
61+
</AppContext.Provider>,
62+
);
63+
expect(tree).toMatchSnapshot();
64+
});
65+
66+
it('without notification number', async () => {
67+
const props = {
68+
notification: {
69+
...mockSingleNotification,
70+
subject: { ...mockSingleNotification.subject, number: null },
71+
},
72+
};
73+
74+
const tree = render(
75+
<AppContext.Provider
76+
value={{ settings: { ...mockSettings, groupBy: GroupBy.DATE } }}
77+
>
78+
<NotificationHeader {...props} />
79+
</AppContext.Provider>,
80+
);
81+
expect(tree).toMatchSnapshot();
82+
});
4283
});
4384

4485
it('should open notification user profile - group by date', () => {

src/renderer/components/notifications/NotificationHeader.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { type FC, type MouseEvent, useContext } from 'react';
33
import { Avatar, Stack, Tooltip } from '@primer/react';
44

55
import { AppContext } from '../../context/App';
6-
import { Size } from '../../types';
6+
import { GroupBy, Opacity, Size } from '../../types';
77
import type { Notification } from '../../typesGitHub';
8+
import { cn } from '../../utils/cn';
89
import { openRepository } from '../../utils/links';
910

1011
interface INotificationHeader {
@@ -19,7 +20,11 @@ export const NotificationHeader: FC<INotificationHeader> = ({
1920
const repoAvatarUrl = notification.repository.owner.avatar_url;
2021
const repoSlug = notification.repository.full_name;
2122

22-
const groupByDate = settings.groupBy === 'DATE';
23+
const notificationNumber = notification.subject?.number
24+
? `#${notification.subject.number}`
25+
: '';
26+
27+
const groupByDate = settings.groupBy === GroupBy.DATE;
2328

2429
return (
2530
groupByDate && (
@@ -35,6 +40,15 @@ export const NotificationHeader: FC<INotificationHeader> = ({
3540
<Stack direction="horizontal" align="center" gap="condensed">
3641
<Avatar src={repoAvatarUrl} size={Size.SMALL} />
3742
<span className="text-xs font-medium">{repoSlug}</span>
43+
<span
44+
className={cn(
45+
'text-xxs',
46+
Opacity.READ,
47+
!settings.showNumber && 'hidden',
48+
)}
49+
>
50+
{notificationNumber}
51+
</span>
3852
</Stack>
3953
</div>
4054
</Tooltip>

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { BellSlashIcon, CheckIcon, ReadIcon } from '@primer/octicons-react';
1010
import { IconButton, Tooltip } from '@primer/react';
1111

1212
import { AppContext } from '../../context/App';
13-
import { Opacity, Size } from '../../types';
13+
import { GroupBy, Opacity, Size } from '../../types';
1414
import type { Notification } from '../../typesGitHub';
1515
import { cn } from '../../utils/cn';
1616
import { isMarkAsDoneFeatureSupported } from '../../utils/features';
@@ -84,6 +84,8 @@ export const NotificationRow: FC<INotificationRow> = ({
8484
const notificationTitle =
8585
`${notification.subject.title} ${notificationNumber}`.trim();
8686

87+
const groupByDate = settings.groupBy === GroupBy.DATE;
88+
8789
return (
8890
<div
8991
id={notification.id}
@@ -116,7 +118,7 @@ export const NotificationRow: FC<INotificationRow> = ({
116118
className={cn(
117119
'text-xxs',
118120
Opacity.READ,
119-
!settings.showNumber && 'hidden',
121+
(groupByDate || !settings.showNumber) && 'hidden',
120122
)}
121123
>
122124
{notificationNumber}

src/renderer/components/notifications/__snapshots__/AccountNotifications.test.tsx.snap

Lines changed: 16 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)