Skip to content

Commit 5d543d3

Browse files
authored
feat: format notification titles with backticks as code (#2548)
* feat: format notification titles with backticks as code Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat(notifications): format backticks in title Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat(notifications): format backticks in title Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat(notifications): format backticks in title Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat(notifications): format backticks in title Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat(notifications): format backticks in title Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent fa05582 commit 5d543d3

File tree

8 files changed

+1157
-47
lines changed

8 files changed

+1157
-47
lines changed

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { isGroupByDate } from '../../utils/notifications/group';
1717
import { shouldRemoveNotificationsFromState } from '../../utils/notifications/remove';
1818
import { NotificationFooter } from './NotificationFooter';
1919
import { NotificationHeader } from './NotificationHeader';
20+
import { NotificationTitle } from './NotificationTitle';
2021

2122
interface NotificationRowProps {
2223
notification: GitifyNotification;
@@ -97,10 +98,7 @@ export const NotificationRow: FC<NotificationRowProps> = ({
9798
</Tooltip>
9899

99100
<Stack
100-
className={cn(
101-
'cursor-pointer text-sm w-full',
102-
!settings.wrapNotificationTitle && 'truncate',
103-
)}
101+
className="cursor-pointer text-sm w-full"
104102
direction="vertical"
105103
gap="none"
106104
onClick={() => handleNotification()}
@@ -109,19 +107,14 @@ export const NotificationRow: FC<NotificationRowProps> = ({
109107

110108
<Stack
111109
align="start"
112-
className={cn(
113-
'mb-0.5',
114-
!settings.wrapNotificationTitle && 'truncate',
115-
)}
110+
className="mb-0.5"
116111
data-testid="notification-row"
117112
direction="horizontal"
118113
gap="condensed"
119114
justify="space-between"
120115
title={notification.display.title}
121116
>
122-
<Text className={!settings.wrapNotificationTitle && 'truncate'}>
123-
{notification.subject.title}
124-
</Text>
117+
<NotificationTitle title={notification.subject.title} />
125118
<Text
126119
className={cn(
127120
'text-xxs ml-auto mr-2',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { renderWithAppContext } from '../../__helpers__/test-utils';
2+
import { mockSettings } from '../../__mocks__/state-mocks';
3+
4+
import { NotificationTitle } from './NotificationTitle';
5+
6+
describe('renderer/components/notifications/NotificationTitle.tsx', () => {
7+
it('should render plain text without code blocks', () => {
8+
const tree = renderWithAppContext(
9+
<NotificationTitle title="Simple notification title" />,
10+
);
11+
12+
expect(tree).toMatchSnapshot();
13+
});
14+
15+
it('should render text with single inline code block', () => {
16+
const tree = renderWithAppContext(
17+
<NotificationTitle title="refactor: migrate deprecated atlaskit `xcss`" />,
18+
);
19+
20+
expect(tree).toMatchSnapshot();
21+
});
22+
23+
it('should render text with multiple inline code blocks', () => {
24+
const tree = renderWithAppContext(
25+
<NotificationTitle title="Replace `foo` with `bar` in config" />,
26+
);
27+
28+
expect(tree).toMatchSnapshot();
29+
});
30+
31+
it('should render text with code block at the start', () => {
32+
const tree = renderWithAppContext(
33+
<NotificationTitle title="`useState` hook implementation" />,
34+
);
35+
36+
expect(tree).toMatchSnapshot();
37+
});
38+
39+
it('should render text with code block at the end', () => {
40+
const tree = renderWithAppContext(
41+
<NotificationTitle title="Fix issue with `render`" />,
42+
);
43+
44+
expect(tree).toMatchSnapshot();
45+
});
46+
47+
it('should apply truncate className when wrapNotificationTitle is false', () => {
48+
const tree = renderWithAppContext(
49+
<NotificationTitle title="refactor: migrate deprecated atlaskit `xcss`" />,
50+
{
51+
settings: {
52+
...mockSettings,
53+
wrapNotificationTitle: false,
54+
},
55+
},
56+
);
57+
58+
expect(tree).toMatchSnapshot();
59+
});
60+
61+
it('should not apply truncate className when wrapNotificationTitle is true', () => {
62+
const tree = renderWithAppContext(
63+
<NotificationTitle title="refactor: migrate deprecated atlaskit `xcss`" />,
64+
{
65+
settings: {
66+
...mockSettings,
67+
wrapNotificationTitle: true,
68+
},
69+
},
70+
);
71+
72+
expect(tree).toMatchSnapshot();
73+
});
74+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import type { FC } from 'react';
2+
3+
import { Text } from '@primer/react';
4+
5+
import { useAppContext } from '../../hooks/useAppContext';
6+
7+
import { cn } from '../../utils/cn';
8+
import { parseInlineCode } from '../../utils/helpers';
9+
10+
interface NotificationTitleProps {
11+
title: string;
12+
}
13+
14+
export const NotificationTitle: FC<NotificationTitleProps> = ({
15+
title,
16+
}: NotificationTitleProps) => {
17+
const { settings } = useAppContext();
18+
const parts = parseInlineCode(title);
19+
20+
return (
21+
<Text className={!settings.wrapNotificationTitle && 'truncate'}>
22+
{parts.map((part) => (
23+
<Text
24+
className={cn(
25+
part.type === 'code' &&
26+
'px-1 py-0.5 rounded bg-gitify-notification-hover font-mono text-xs',
27+
)}
28+
key={part.id}
29+
>
30+
{part.content}
31+
</Text>
32+
))}
33+
</Text>
34+
);
35+
};

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

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

0 commit comments

Comments
 (0)