Skip to content

Commit 2b85c43

Browse files
committed
feat: format notification titles with backticks as code
Signed-off-by: Adam Setch <adam.setch@outlook.com>
1 parent f9188f8 commit 2b85c43

6 files changed

Lines changed: 921 additions & 3 deletions

File tree

src/renderer/components/notifications/NotificationRow.tsx

Lines changed: 5 additions & 3 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;
@@ -118,9 +119,10 @@ export const NotificationRow: FC<NotificationRowProps> = ({
118119
justify="space-between"
119120
title={notification.display.title}
120121
>
121-
<Text className={!settings.wrapNotificationTitle && 'truncate'}>
122-
{notification.subject.title}
123-
</Text>
122+
<NotificationTitle
123+
className={!settings.wrapNotificationTitle && 'truncate'}
124+
title={notification.subject.title}
125+
/>
124126
<Text
125127
className={cn(
126128
'text-xxs ml-auto mr-2',
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { renderWithAppContext } from '../../__helpers__/test-utils';
2+
3+
import { NotificationTitle } from './NotificationTitle';
4+
5+
describe('renderer/components/notifications/NotificationTitle.tsx', () => {
6+
it('should render plain text without code blocks', () => {
7+
const tree = renderWithAppContext(
8+
<NotificationTitle title="Simple notification title" />,
9+
);
10+
11+
expect(tree).toMatchSnapshot();
12+
});
13+
14+
it('should render text with single inline code block', () => {
15+
const tree = renderWithAppContext(
16+
<NotificationTitle title="refactor: migrate deprecated atlaskit `xcss`" />,
17+
);
18+
19+
expect(tree).toMatchSnapshot();
20+
});
21+
22+
it('should render text with multiple inline code blocks', () => {
23+
const tree = renderWithAppContext(
24+
<NotificationTitle title="Replace `foo` with `bar` in config" />,
25+
);
26+
27+
expect(tree).toMatchSnapshot();
28+
});
29+
30+
it('should render text with code block at the start', () => {
31+
const tree = renderWithAppContext(
32+
<NotificationTitle title="`useState` hook implementation" />,
33+
);
34+
35+
expect(tree).toMatchSnapshot();
36+
});
37+
38+
it('should render text with code block at the end', () => {
39+
const tree = renderWithAppContext(
40+
<NotificationTitle title="Fix issue with `render`" />,
41+
);
42+
43+
expect(tree).toMatchSnapshot();
44+
});
45+
46+
it('should apply custom className', () => {
47+
const tree = renderWithAppContext(
48+
<NotificationTitle
49+
className="truncate"
50+
title="refactor: migrate deprecated atlaskit `xcss`"
51+
/>,
52+
);
53+
54+
expect(tree).toMatchSnapshot();
55+
});
56+
});
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import type { FC } from 'react';
2+
3+
import { Text } from '@primer/react';
4+
5+
import { parseInlineCode } from '../../utils/helpers';
6+
7+
interface NotificationTitleProps {
8+
title: string;
9+
className?: string;
10+
}
11+
12+
export const NotificationTitle: FC<NotificationTitleProps> = ({
13+
title,
14+
className,
15+
}: NotificationTitleProps) => {
16+
const parts = parseInlineCode(title);
17+
18+
return (
19+
<Text className={className}>
20+
{parts.map((part, index) =>
21+
part.type === 'code' ? (
22+
<code
23+
className="px-1 py-0.5 rounded bg-gitify-notification-hover font-mono text-xs"
24+
// biome-ignore lint/suspicious/noArrayIndexKey: parts are derived from static title
25+
key={index}
26+
>
27+
{part.content}
28+
</code>
29+
) : (
30+
// biome-ignore lint/suspicious/noArrayIndexKey: parts are derived from static title
31+
<span key={index}>{part.content}</span>
32+
),
33+
)}
34+
</Text>
35+
);
36+
};

0 commit comments

Comments
 (0)