Skip to content

feat: add tooltip for show participating setting #1008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/components/fields/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ export const Checkbox: FC<ICheckbox> = (props: ICheckbox) => {
}
>
{props.label}
{props.tooltip && <Tooltip tooltip={props.tooltip} />}
{props.tooltip && (
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
)}
</label>
</div>
</div>
Expand Down
3 changes: 2 additions & 1 deletion src/components/fields/Tooltip.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { type ITooltip, Tooltip } from './Tooltip';

describe('components/fields/Tooltip.tsx', () => {
const props: ITooltip = {
name: 'tooltip',
tooltip: 'This is some tooltip text',
};

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

const tooltipElement = screen.getByTitle('tooltip');
const tooltipElement = screen.getByLabelText('tooltip');

fireEvent.mouseEnter(tooltipElement);
expect(tooltipElement).toMatchSnapshot();
Expand Down
4 changes: 3 additions & 1 deletion src/components/fields/Tooltip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { QuestionIcon } from '@primer/octicons-react';
import { type FC, type ReactNode, useState } from 'react';

export interface ITooltip {
name: string;
tooltip: ReactNode | string;
}

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

return (
<span
title="tooltip"
id={props.name}
aria-label={props.name}
className="relative"
onMouseEnter={() => setShowTooltip(true)}
onMouseLeave={() => setShowTooltip(false)}
Expand Down
9 changes: 6 additions & 3 deletions src/components/fields/__snapshots__/Tooltip.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions src/routes/Settings.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,41 @@ describe('routes/Settings.tsx', () => {
expect(updateSetting).toHaveBeenCalledWith('participating', false);
});

it('should open official docs for showOnlyParticipating tooltip', async () => {
await act(async () => {
render(
<AppContext.Provider
value={{
settings: mockSettings,
accounts: mockAccounts,
updateSetting,
}}
>
<MemoryRouter>
<SettingsRoute />
</MemoryRouter>
</AppContext.Provider>,
);
});

const tooltipElement = screen.getByLabelText(
'tooltip-showOnlyParticipating',
);

fireEvent.mouseEnter(tooltipElement);

fireEvent.click(
screen.getByTitle(
'Open GitHub documentation for participating and watching notifications',
),
);

expect(shell.openExternal).toHaveBeenCalledTimes(1);
expect(shell.openExternal).toHaveBeenCalledWith(
'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications',
);
});

it('should not be able to toggle the showBots checkbox when detailedNotifications is disabled', async () => {
await act(async () => {
render(
Expand Down
26 changes: 26 additions & 0 deletions src/routes/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { ipcRenderer } from 'electron';

import {
type FC,
type MouseEvent,
useCallback,
useContext,
useEffect,
Expand Down Expand Up @@ -44,6 +45,15 @@ export const SettingsRoute: FC = () => {
);
}, []);

const openGitHubParticipatingDocs = (event: MouseEvent<HTMLElement>) => {
// Don't trigger onClick of parent element.
event.stopPropagation();

openExternalLink(
'https://docs.github.com/en/account-and-profile/managing-subscriptions-and-notifications-on-github/setting-up-notifications/configuring-notifications#about-participating-and-watching-notifications',
);
};

useEffect(() => {
ipcRenderer.invoke('get-platform').then((result: string) => {
setIsLinux(result === 'linux');
Expand Down Expand Up @@ -177,6 +187,22 @@ export const SettingsRoute: FC = () => {
onChange={(evt) =>
updateSetting('participating', evt.target.checked)
}
tooltip={
<div>
<div className="pb-3">
See{' '}
<button
type="button"
className="text-blue-500"
title="Open GitHub documentation for participating and watching notifications"
onClick={openGitHubParticipatingDocs}
>
official docs
</button>{' '}
for more details.
</div>
</div>
}
/>
<Checkbox
name="showBots"
Expand Down
35 changes: 30 additions & 5 deletions src/routes/__snapshots__/Settings.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.