Skip to content

Commit b9695de

Browse files
committed
Merge branch 'main' into feat/avatar-with-fallback
Signed-off-by: Adam Setch <[email protected]>
2 parents a0958df + 6493d7f commit b9695de

File tree

6 files changed

+756
-263
lines changed

6 files changed

+756
-263
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', () => {
Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { type FC, type MouseEvent, useContext } from 'react';
22

3-
import { Box, Tooltip } from '@primer/react';
3+
import { Box, 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
import { AvatarWithFallback } from '../avatars/AvatarWithFallback';
1011

@@ -19,29 +20,44 @@ export const NotificationHeader: FC<INotificationHeader> = ({
1920

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 && (
26-
<Tooltip text={`View repository: ${repoSlug}`} direction="se">
31+
<Stack direction="horizontal" align="center" gap="condensed">
32+
<Tooltip text={`View repository: ${repoSlug}`} direction="se">
33+
<Box
34+
className="text-xs font-medium"
35+
onClick={(event: MouseEvent<HTMLElement>) => {
36+
// Don't trigger onClick of parent element.
37+
event.stopPropagation();
38+
openRepository(notification.repository);
39+
}}
40+
data-testid="view-repository"
41+
>
42+
<AvatarWithFallback
43+
src={notification.repository.owner.avatar_url}
44+
alt={repoSlug}
45+
name={repoSlug}
46+
size={Size.SMALL}
47+
userType={notification.repository.owner.type}
48+
/>
49+
</Box>
50+
</Tooltip>
2751
<Box
28-
className="text-xs font-medium"
29-
onClick={(event: MouseEvent<HTMLElement>) => {
30-
// Don't trigger onClick of parent element.
31-
event.stopPropagation();
32-
openRepository(notification.repository);
33-
}}
34-
data-testid="view-repository"
52+
className={cn(
53+
'text-xxs',
54+
Opacity.READ,
55+
!settings.showNumber && 'hidden',
56+
)}
3557
>
36-
<AvatarWithFallback
37-
src={notification.repository.owner.avatar_url}
38-
alt={repoSlug}
39-
name={repoSlug}
40-
size={Size.SMALL}
41-
userType={notification.repository.owner.type}
42-
/>
58+
{notificationNumber}
4359
</Box>
44-
</Tooltip>
60+
</Stack>
4561
)
4662
);
4763
};

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}

0 commit comments

Comments
 (0)