Skip to content
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
42 changes: 37 additions & 5 deletions src/components/Sidebar.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { 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 { mockAuth, mockSettings } from '../__mocks__/state-mocks';
import { AppContext } from '../context/App';
import { IconColor } from '../types';
import * as comms from '../utils/comms';
Expand All @@ -27,8 +27,9 @@ describe('components/Sidebar.tsx', () => {
const tree = render(
<AppContext.Provider
value={{
settings: mockSettings,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
Expand All @@ -46,6 +47,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: false,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -61,7 +63,12 @@ describe('components/Sidebar.tsx', () => {
it('should open the gitify repository', () => {
render(
<AppContext.Provider
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
value={{
isLoggedIn: false,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
Expand All @@ -85,6 +92,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
Expand Down Expand Up @@ -114,6 +122,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand Down Expand Up @@ -146,6 +155,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -169,6 +179,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -193,6 +204,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
fetchNotifications,
status: 'success',
Expand All @@ -215,6 +227,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
fetchNotifications,
status: 'loading',
Expand All @@ -239,6 +252,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -257,6 +271,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -277,6 +292,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -297,6 +313,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
fetchNotifications,
}}
Expand All @@ -322,6 +339,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -345,6 +363,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -368,6 +387,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -388,7 +408,12 @@ describe('components/Sidebar.tsx', () => {

render(
<AppContext.Provider
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
value={{
isLoggedIn: false,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
Expand All @@ -406,7 +431,12 @@ describe('components/Sidebar.tsx', () => {

render(
<AppContext.Provider
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
value={{
isLoggedIn: false,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
<MemoryRouter>
<Sidebar />
Expand All @@ -427,6 +457,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: [],
auth: mockAuth,
settings: mockSettings,
}}
>
Expand All @@ -448,6 +479,7 @@ describe('components/Sidebar.tsx', () => {
value={{
isLoggedIn: true,
notifications: mockAccountNotifications,
auth: mockAuth,
settings: mockSettings,
}}
>
Expand Down
21 changes: 16 additions & 5 deletions src/components/Sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,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 Constants from '../utils/constants';
import { getFilterCount } from '../utils/helpers';
import {
openGitHubIssues,
Expand All @@ -27,8 +28,18 @@ export const Sidebar: FC = () => {
const navigate = useNavigate();
const location = useLocation();

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

// We naively assume that the first account is the primary account for the purposes of our sidebar quick links
const primaryAccountHostname =
auth.accounts[0]?.hostname ?? Constants.DEFAULT_AUTH_OPTIONS.hostname;

const toggleFilters = () => {
if (location.pathname.startsWith('/filters')) {
Expand Down Expand Up @@ -77,19 +88,19 @@ export const Sidebar: FC = () => {
title={`${notificationsCount} Unread Notifications`}
metric={notificationsCount}
icon={BellIcon}
onClick={() => openGitHubNotifications()}
onClick={() => openGitHubNotifications(primaryAccountHostname)}
/>

<SidebarButton
title="My Issues"
icon={IssueOpenedIcon}
onClick={() => openGitHubIssues()}
onClick={() => openGitHubIssues(primaryAccountHostname)}
/>

<SidebarButton
title="My Pull Requests"
icon={GitPullRequestIcon}
onClick={() => openGitHubPulls()}
onClick={() => openGitHubPulls(primaryAccountHostname)}
/>
</div>

Expand Down
2 changes: 1 addition & 1 deletion src/context/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
const newSettings = { ...settings, ...defaultFilters };
setSettings(newSettings);
saveState({ auth, settings: newSettings });
}, [auth]);
}, [auth, settings]);

const resetSettings = useCallback(() => {
setSettings(defaultSettings);
Expand Down
1 change: 0 additions & 1 deletion src/utils/auth/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export async function migrateAuthenticatedAccounts() {
const existing = loadState();

if (!hasAccountsToMigrate(existing.auth)) {
log.info('Account Migration: No accounts need migrating');
Copy link
Member Author

@setchy setchy Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was logging a lot when running our test suites. removing

return;
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/links.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,21 @@ describe('utils/links.ts', () => {
});

it('openGitHubNotifications', () => {
openGitHubNotifications();
openGitHubNotifications(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/notifications',
);
});

it('openGitHubIssues', () => {
openGitHubIssues();
openGitHubIssues(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/issues',
);
});

it('openGitHubPulls', () => {
openGitHubPulls();
openGitHubPulls(mockGitHubCloudAccount.hostname);
expect(openExternalLinkMock).toHaveBeenCalledWith(
'https://github.com/pulls',
);
Expand Down
18 changes: 12 additions & 6 deletions src/utils/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,22 @@ export function openGitifyReleaseNotes(version: string) {
);
}

export function openGitHubNotifications() {
openExternalLink('https://github.com/notifications' as Link);
export function openGitHubNotifications(hostname: Hostname) {
const url = new URL(`https://${hostname}`);
url.pathname = 'notifications';
openExternalLink(url.toString() as Link);
}

export function openGitHubIssues() {
openExternalLink('https://github.com/issues' as Link);
export function openGitHubIssues(hostname: Hostname) {
const url = new URL(`https://${hostname}`);
url.pathname = 'issues';
openExternalLink(url.toString() as Link);
}

export function openGitHubPulls() {
openExternalLink('https://github.com/pulls' as Link);
export function openGitHubPulls(hostname: Hostname) {
const url = new URL(`https://${hostname}`);
url.pathname = 'pulls';
openExternalLink(url.toString() as Link);
}

export function openAccountProfile(account: Account) {
Expand Down