-
Notifications
You must be signed in to change notification settings - Fork 266
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: filter by notification type (#1860)
* feat: filter by notification type Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat: filter by notification type Signed-off-by: Adam Setch <adam.setch@outlook.com> * feat: filter by notification type Signed-off-by: Adam Setch <adam.setch@outlook.com> --------- Signed-off-by: Adam Setch <adam.setch@outlook.com>
- Loading branch information
Showing
14 changed files
with
1,861 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
96 changes: 96 additions & 0 deletions
96
src/renderer/components/filters/SubjectTypeFilter.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { act, fireEvent, render, screen } from '@testing-library/react'; | ||
import { MemoryRouter } from 'react-router-dom'; | ||
import { mockAccountNotifications } from '../../__mocks__/notifications-mocks'; | ||
import { mockSettings } from '../../__mocks__/state-mocks'; | ||
import { AppContext } from '../../context/App'; | ||
import type { SettingsState } from '../../types'; | ||
import { SubjectTypeFilter } from './SubjectTypeFilter'; | ||
|
||
describe('renderer/components/filters/SubjectTypeFilter.tsx', () => { | ||
const updateFilter = jest.fn(); | ||
|
||
it('should render itself & its children', () => { | ||
const tree = render( | ||
<AppContext.Provider | ||
value={{ | ||
settings: { | ||
...mockSettings, | ||
} as SettingsState, | ||
notifications: mockAccountNotifications, | ||
}} | ||
> | ||
<MemoryRouter> | ||
<SubjectTypeFilter /> | ||
</MemoryRouter> | ||
</AppContext.Provider>, | ||
); | ||
|
||
expect(tree).toMatchSnapshot(); | ||
}); | ||
|
||
it('should be able to toggle subject type - none already set', async () => { | ||
await act(async () => { | ||
render( | ||
<AppContext.Provider | ||
value={{ | ||
settings: { | ||
...mockSettings, | ||
filterSubjectTypes: [], | ||
}, | ||
notifications: [], | ||
updateFilter, | ||
}} | ||
> | ||
<MemoryRouter> | ||
<SubjectTypeFilter /> | ||
</MemoryRouter> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByLabelText('Issue')); | ||
|
||
expect(updateFilter).toHaveBeenCalledWith( | ||
'filterSubjectTypes', | ||
'Issue', | ||
true, | ||
); | ||
|
||
expect( | ||
screen.getByLabelText('Issue').parentNode.parentNode, | ||
).toMatchSnapshot(); | ||
}); | ||
|
||
it('should be able to toggle subject type - some filters already set', async () => { | ||
await act(async () => { | ||
render( | ||
<AppContext.Provider | ||
value={{ | ||
settings: { | ||
...mockSettings, | ||
filterSubjectTypes: ['Issue'], | ||
}, | ||
notifications: [], | ||
updateFilter, | ||
}} | ||
> | ||
<MemoryRouter> | ||
<SubjectTypeFilter /> | ||
</MemoryRouter> | ||
</AppContext.Provider>, | ||
); | ||
}); | ||
|
||
fireEvent.click(screen.getByLabelText('Pull Request')); | ||
|
||
expect(updateFilter).toHaveBeenCalledWith( | ||
'filterSubjectTypes', | ||
'PullRequest', | ||
true, | ||
); | ||
|
||
expect( | ||
screen.getByLabelText('Pull Request').parentNode.parentNode, | ||
).toMatchSnapshot(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { type FC, useContext } from 'react'; | ||
|
||
import { BellIcon } from '@primer/octicons-react'; | ||
import { Stack, Text } from '@primer/react'; | ||
|
||
import { AppContext } from '../../context/App'; | ||
import type { SubjectType } from '../../typesGitHub'; | ||
import { | ||
FILTERS_SUBJECT_TYPES, | ||
getSubjectTypeDetails, | ||
getSubjectTypeFilterCount, | ||
isSubjectTypeFilterSet, | ||
} from '../../utils/notifications/filters/subjectType'; | ||
import { Checkbox } from '../fields/Checkbox'; | ||
import { Tooltip } from '../fields/Tooltip'; | ||
import { Title } from '../primitives/Title'; | ||
|
||
export const SubjectTypeFilter: FC = () => { | ||
const { updateFilter, settings, notifications } = useContext(AppContext); | ||
|
||
return ( | ||
<fieldset id="filter-subject-type" className="mb-3"> | ||
<Stack direction="horizontal" gap="condensed" align="baseline"> | ||
<Title icon={BellIcon}>Type</Title> | ||
<Tooltip | ||
name="tooltip-filter-subject-type" | ||
tooltip={ | ||
<Stack direction="vertical" gap="condensed"> | ||
<Text>Filter notifications by type.</Text> | ||
</Stack> | ||
} | ||
/> | ||
</Stack> | ||
|
||
<Stack direction="vertical" gap="condensed"> | ||
{Object.keys(FILTERS_SUBJECT_TYPES).map((subjectType: SubjectType) => { | ||
const subjectTypeDetails = getSubjectTypeDetails(subjectType); | ||
const subjectTypeTitle = subjectTypeDetails.title; | ||
const subjectTypeDescription = subjectTypeDetails.description; | ||
const isSubjectTypeChecked = isSubjectTypeFilterSet( | ||
settings, | ||
subjectType, | ||
); | ||
const subjectTypeCount = getSubjectTypeFilterCount( | ||
notifications, | ||
subjectType, | ||
); | ||
|
||
return ( | ||
<Checkbox | ||
key={subjectType} | ||
name={subjectTypeTitle} | ||
label={subjectTypeTitle} | ||
checked={isSubjectTypeChecked} | ||
onChange={(evt) => | ||
updateFilter( | ||
'filterSubjectTypes', | ||
subjectType, | ||
evt.target.checked, | ||
) | ||
} | ||
tooltip={ | ||
subjectTypeDescription ? ( | ||
<Text>{subjectTypeDescription}</Text> | ||
) : null | ||
} | ||
disabled={!settings.detailedNotifications} | ||
counter={subjectTypeCount} | ||
/> | ||
); | ||
})} | ||
</Stack> | ||
</fieldset> | ||
); | ||
}; |
28 changes: 20 additions & 8 deletions
28
src/renderer/components/filters/__snapshots__/StateFilter.test.tsx.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.