Skip to content
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

feat: notification filters #1304

Merged
merged 22 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions src/__mocks__/state-mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const mockSettings: SettingsState = {
showPills: true,
keyboardShortcut: true,
groupBy: GroupBy.REPOSITORY,
filterReasons: '',
};

export const mockState: GitifyState = {
Expand Down
9 changes: 9 additions & 0 deletions src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Loading } from './components/Loading';
import { Sidebar } from './components/Sidebar';
import { AppContext, AppProvider } from './context/App';
import { AccountsRoute } from './routes/Accounts';
import { FiltersRoute } from './routes/Filters';
import { LoginRoute } from './routes/Login';
import { LoginWithOAuthApp } from './routes/LoginWithOAuthApp';
import { LoginWithPersonalAccessToken } from './routes/LoginWithPersonalAccessToken';
Expand Down Expand Up @@ -43,6 +44,14 @@ export const App = () => {
</RequireAuth>
}
/>
<Route
path="/filters"
element={
<RequireAuth>
<FiltersRoute />
</RequireAuth>
}
/>
<Route
path="/settings"
element={
Expand Down
83 changes: 77 additions & 6 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,11 @@ describe('components/Sidebar.tsx', () => {
it('should render itself & its children (logged out)', () => {
const tree = render(
<AppContext.Provider
value={{ isLoggedIn: false, notifications: mockAccountNotifications }}
value={{
isLoggedIn: false,
notifications: mockAccountNotifications,
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
Expand All @@ -62,6 +66,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
fetchNotifications,
status: 'success',
}}
Expand All @@ -83,6 +88,8 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,

fetchNotifications,
status: 'loading',
}}
Expand All @@ -99,10 +106,54 @@ describe('components/Sidebar.tsx', () => {
});
});

describe('Filters', () => {
it('go to the filters route', () => {
render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByTitle('Filters'));
expect(mockNavigate).toHaveBeenCalledWith('/filters');
});

it('go to the home if filters path already shown', () => {
render(
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
}}
>
<MemoryRouter initialEntries={['/filters']}>
<Sidebar />
</MemoryRouter>
</AppContext.Provider>,
);
fireEvent.click(screen.getByTitle('Filters'));
expect(mockNavigate).toHaveBeenCalledWith('/', { replace: true });
});
});

describe('Settings', () => {
it('go to the settings route', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
Expand All @@ -114,7 +165,13 @@ describe('components/Sidebar.tsx', () => {

it('go to the home if settings path already shown', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
}}
>
<MemoryRouter initialEntries={['/settings']}>
<Sidebar />
</MemoryRouter>
Expand All @@ -133,6 +190,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
settings: mockSettings,
}}
>
<MemoryRouter>
Expand All @@ -155,6 +213,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
settings: mockSettings,
}}
>
<MemoryRouter>
Expand All @@ -177,6 +236,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
settings: mockSettings,
}}
>
<MemoryRouter>
Expand All @@ -195,7 +255,9 @@ describe('components/Sidebar.tsx', () => {
const quitAppMock = jest.spyOn(comms, 'quitApp');

render(
<AppContext.Provider value={{ isLoggedIn: false, notifications: [] }}>
<AppContext.Provider
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
Expand All @@ -209,7 +271,9 @@ describe('components/Sidebar.tsx', () => {
const openExternalLinkMock = jest.spyOn(comms, 'openExternalLink');

render(
<AppContext.Provider value={{ isLoggedIn: false, notifications: [] }}>
<AppContext.Provider
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
Expand All @@ -225,7 +289,13 @@ describe('components/Sidebar.tsx', () => {
describe('should render the notifications icon', () => {
it('when there are 0 notifications', () => {
render(
<AppContext.Provider value={{ isLoggedIn: true, notifications: [] }}>
<AppContext.Provider
value={{
isLoggedIn: true,
notifications: [],
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
</MemoryRouter>
Expand All @@ -244,6 +314,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
settings: mockSettings,
}}
>
<MemoryRouter>
Expand Down
24 changes: 23 additions & 1 deletion src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
BellIcon,
FilterIcon,
GearIcon,
GitPullRequestIcon,
IssueOpenedIcon,
Expand All @@ -11,6 +12,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
import { AppContext } from '../context/App';
import { Size } from '../types';
import { quitApp } from '../utils/comms';
import { getFilterCount } from '../utils/helpers';
import {
openGitHubIssues,
openGitHubNotifications,
Expand All @@ -25,9 +27,17 @@ export const Sidebar: FC = () => {
const navigate = useNavigate();
const location = useLocation();

const { notifications, fetchNotifications, isLoggedIn, status } =
const { notifications, fetchNotifications, isLoggedIn, status, settings } =
useContext(AppContext);

const toggleFilters = () => {
if (location.pathname.startsWith('/filters')) {
navigate('/', { replace: true });
} else {
navigate('/filters');
}
};

const toggleSettings = () => {
if (location.pathname.startsWith('/settings')) {
navigate('/', { replace: true });
Expand All @@ -45,6 +55,10 @@ export const Sidebar: FC = () => {
return getNotificationCount(notifications);
}, [notifications]);

const filterCount = useMemo(() => {
return getFilterCount(settings);
}, [settings]);

return (
<div className="fixed left-14 -ml-14 flex h-full w-14 flex-col overflow-y-auto bg-gray-sidebar">
<div className="flex flex-1 flex-col items-center py-4">
Expand Down Expand Up @@ -90,6 +104,14 @@ export const Sidebar: FC = () => {
onClick={() => refreshNotifications()}
/>

<SidebarButton
title="Filters"
icon={FilterIcon}
size={Size.MEDIUM}
metric={filterCount}
onClick={() => toggleFilters()}
/>

<SidebarButton
title="Settings"
icon={GearIcon}
Expand Down
2 changes: 2 additions & 0 deletions src/context/App.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ describe('context/App.tsx', () => {
showPills: true,
keyboardShortcut: true,
groupBy: 'REPOSITORY',
filterReasons: '',
} as SettingsState,
});
});
Expand Down Expand Up @@ -434,6 +435,7 @@ describe('context/App.tsx', () => {
showPills: true,
keyboardShortcut: true,
groupBy: 'REPOSITORY',
filterReasons: '',
} as SettingsState,
});
});
Expand Down
1 change: 1 addition & 0 deletions src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ export const defaultSettings: SettingsState = {
showPills: true,
keyboardShortcut: true,
groupBy: GroupBy.REPOSITORY,
filterReasons: '',
};

interface AppContextState {
Expand Down
Loading