Skip to content

Commit d5db6e7

Browse files
authored
feat: add tooltip for show participating setting (#1008)
* feat(settings): add tooltip for show participating * feat(settings): add tooltip for show participating * feat(settings): add tooltip for show participating * feat(settings): add tooltip for show participating * feat(settings): add tooltip for show participating
1 parent 86da335 commit d5db6e7

File tree

7 files changed

+105
-11
lines changed

7 files changed

+105
-11
lines changed

src/components/fields/Checkbox.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ export const Checkbox: FC<ICheckbox> = (props: ICheckbox) => {
3535
}
3636
>
3737
{props.label}
38-
{props.tooltip && <Tooltip tooltip={props.tooltip} />}
38+
{props.tooltip && (
39+
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
40+
)}
3941
</label>
4042
</div>
4143
</div>

src/components/fields/Tooltip.test.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { type ITooltip, Tooltip } from './Tooltip';
66

77
describe('components/fields/Tooltip.tsx', () => {
88
const props: ITooltip = {
9+
name: 'tooltip',
910
tooltip: 'This is some tooltip text',
1011
};
1112

@@ -17,7 +18,7 @@ describe('components/fields/Tooltip.tsx', () => {
1718
it('should display on mouse enter / leave', () => {
1819
render(<Tooltip {...props} />);
1920

20-
const tooltipElement = screen.getByTitle('tooltip');
21+
const tooltipElement = screen.getByLabelText('tooltip');
2122

2223
fireEvent.mouseEnter(tooltipElement);
2324
expect(tooltipElement).toMatchSnapshot();

src/components/fields/Tooltip.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { QuestionIcon } from '@primer/octicons-react';
22
import { type FC, type ReactNode, useState } from 'react';
33

44
export interface ITooltip {
5+
name: string;
56
tooltip: ReactNode | string;
67
}
78

@@ -10,7 +11,8 @@ export const Tooltip: FC<ITooltip> = (props: ITooltip) => {
1011

1112
return (
1213
<span
13-
title="tooltip"
14+
id={props.name}
15+
aria-label={props.name}
1416
className="relative"
1517
onMouseEnter={() => setShowTooltip(true)}
1618
onMouseLeave={() => setShowTooltip(false)}

src/components/fields/__snapshots__/Tooltip.test.tsx.snap

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

src/routes/Settings.test.tsx

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,41 @@ describe('routes/Settings.tsx', () => {
119119
expect(updateSetting).toHaveBeenCalledWith('participating', false);
120120
});
121121

122+
it('should open official docs for showOnlyParticipating tooltip', async () => {
123+
await act(async () => {
124+
render(
125+
<AppContext.Provider
126+
value={{
127+
settings: mockSettings,
128+
accounts: mockAccounts,
129+
updateSetting,
130+
}}
131+
>
132+
<MemoryRouter>
133+
<SettingsRoute />
134+
</MemoryRouter>
135+
</AppContext.Provider>,
136+
);
137+
});
138+
139+
const tooltipElement = screen.getByLabelText(
140+
'tooltip-showOnlyParticipating',
141+
);
142+
143+
fireEvent.mouseEnter(tooltipElement);
144+
145+
fireEvent.click(
146+
screen.getByTitle(
147+
'Open GitHub documentation for participating and watching notifications',
148+
),
149+
);
150+
151+
expect(shell.openExternal).toHaveBeenCalledTimes(1);
152+
expect(shell.openExternal).toHaveBeenCalledWith(
153+
'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications',
154+
);
155+
});
156+
122157
it('should not be able to toggle the showBots checkbox when detailedNotifications is disabled', async () => {
123158
await act(async () => {
124159
render(

src/routes/Settings.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ipcRenderer } from 'electron';
88

99
import {
1010
type FC,
11+
type MouseEvent,
1112
useCallback,
1213
useContext,
1314
useEffect,
@@ -44,6 +45,15 @@ export const SettingsRoute: FC = () => {
4445
);
4546
}, []);
4647

48+
const openGitHubParticipatingDocs = (event: MouseEvent<HTMLElement>) => {
49+
// Don't trigger onClick of parent element.
50+
event.stopPropagation();
51+
52+
openExternalLink(
53+
'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications',
54+
);
55+
};
56+
4757
useEffect(() => {
4858
ipcRenderer.invoke('get-platform').then((result: string) => {
4959
setIsLinux(result === 'linux');
@@ -177,6 +187,22 @@ export const SettingsRoute: FC = () => {
177187
onChange={(evt) =>
178188
updateSetting('participating', evt.target.checked)
179189
}
190+
tooltip={
191+
<div>
192+
<div className="pb-3">
193+
See{' '}
194+
<button
195+
type="button"
196+
className="text-blue-500"
197+
title="Open GitHub documentation for participating and watching notifications"
198+
onClick={openGitHubParticipatingDocs}
199+
>
200+
official docs
201+
</button>{' '}
202+
for more details.
203+
</div>
204+
</div>
205+
}
180206
/>
181207
<Checkbox
182208
name="showBots"

src/routes/__snapshots__/Settings.test.tsx.snap

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

0 commit comments

Comments
 (0)