Skip to content

Commit d2a048f

Browse files
authored
feat: filter counters (#1788)
Signed-off-by: Adam Setch <[email protected]>
1 parent 8b70265 commit d2a048f

File tree

13 files changed

+560
-113
lines changed

13 files changed

+560
-113
lines changed

src/renderer/components/AllRead.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { type FC, useContext, useMemo } from 'react';
22

33
import { AppContext } from '../context/App';
44
import { Constants } from '../utils/constants';
5-
import { hasFiltersSet } from '../utils/filters';
5+
import { hasAnyFiltersSet } from '../utils/filters';
66
import { EmojiSplash } from './layout/EmojiSplash';
77

88
interface IAllRead {
@@ -12,7 +12,7 @@ interface IAllRead {
1212
export const AllRead: FC<IAllRead> = ({ fullHeight = true }: IAllRead) => {
1313
const { settings } = useContext(AppContext);
1414

15-
const hasFilters = hasFiltersSet(settings);
15+
const hasFilters = hasAnyFiltersSet(settings);
1616

1717
const emoji = useMemo(
1818
() =>

src/renderer/components/Sidebar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { APPLICATION } from '../../shared/constants';
1616
import { AppContext } from '../context/App';
1717
import { quitApp } from '../utils/comms';
1818
import { Constants } from '../utils/constants';
19-
import { hasFiltersSet } from '../utils/filters';
19+
import { hasAnyFiltersSet } from '../utils/filters';
2020
import {
2121
openGitHubIssues,
2222
openGitHubNotifications,
@@ -114,7 +114,7 @@ export const Sidebar: FC = () => {
114114
description="Filter notifications"
115115
unsafeDisableTooltip={false}
116116
size="small"
117-
variant={hasFiltersSet(settings) ? 'primary' : 'invisible'}
117+
variant={hasAnyFiltersSet(settings) ? 'primary' : 'invisible'}
118118
tooltipDirection="e"
119119
onClick={() => toggleFilters()}
120120
data-testid="sidebar-filter-notifications"

src/renderer/components/fields/Checkbox.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,19 @@ describe('renderer/components/fields/Checkbox.tsx', () => {
3030
);
3131
expect(tree).toMatchSnapshot();
3232
});
33+
34+
it('should render - positive counter unselected', () => {
35+
const tree = render(<Checkbox {...props} counter={5} checked={false} />);
36+
expect(tree).toMatchSnapshot();
37+
});
38+
39+
it('should render - positive counter selected', () => {
40+
const tree = render(<Checkbox {...props} counter={5} checked={true} />);
41+
expect(tree).toMatchSnapshot();
42+
});
43+
44+
it('should render - zero counter', () => {
45+
const tree = render(<Checkbox {...props} counter={0} />);
46+
expect(tree).toMatchSnapshot();
47+
});
3348
});

src/renderer/components/fields/Checkbox.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import type { FC, ReactNode } from 'react';
22

3-
import { Stack } from '@primer/react';
3+
import { CounterLabel, Stack } from '@primer/react';
44

55
import { cn } from '../../utils/cn';
66
import { Tooltip } from './Tooltip';
77

88
export interface ICheckbox {
99
name: string;
1010
label: string;
11+
counter?: number;
1112
tooltip?: ReactNode | string;
1213
checked: boolean;
1314
disabled?: boolean;
@@ -19,6 +20,8 @@ export const Checkbox: FC<ICheckbox> = ({
1920
visible = true,
2021
...props
2122
}: ICheckbox) => {
23+
const counter = props.counter > 0 ? props.counter : undefined;
24+
2225
return (
2326
visible && (
2427
<Stack
@@ -46,9 +49,16 @@ export const Checkbox: FC<ICheckbox> = ({
4649
>
4750
{props.label}
4851
</label>
52+
4953
{props.tooltip && (
5054
<Tooltip name={`tooltip-${props.name}`} tooltip={props.tooltip} />
5155
)}
56+
57+
{counter && (
58+
<CounterLabel scheme={props.checked ? 'primary' : 'secondary'}>
59+
{counter}
60+
</CounterLabel>
61+
)}
5262
</Stack>
5363
)
5464
);

src/renderer/components/fields/Tooltip.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const Tooltip: FC<ITooltip> = (props: ITooltip) => {
1919
onMouseLeave={() => setShowTooltip(false)}
2020
data-testid={`tooltip-${props.name}`}
2121
>
22-
<QuestionIcon className="ml-1 text-gitify-tooltip-icon" />
22+
<QuestionIcon className="text-gitify-tooltip-icon" />
2323
{showTooltip && (
2424
<Box className="absolute left-[-80px] z-10 w-60 rounded-sm border border-gray-300 p-2 shadow-sm bg-gitify-tooltip-popout">
2525
<Box className="text-left text-xs text-gitify-font">

0 commit comments

Comments
 (0)