Skip to content

Commit f242e01

Browse files
authored
feat: use first account for quick link hostname (#1411)
* feat: use first account for quick link hostname * feat: use first account for quick link hostname * feat: use first account for quick link hostname
1 parent 4ab9c67 commit f242e01

File tree

5 files changed

+68
-20
lines changed

5 files changed

+68
-20
lines changed

src/components/Sidebar.test.tsx

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { fireEvent, render, screen } from '@testing-library/react';
22
import { MemoryRouter } from 'react-router-dom';
33
import { mockAccountNotifications } from '../__mocks__/notifications-mocks';
4-
import { mockSettings } from '../__mocks__/state-mocks';
4+
import { mockAuth, mockSettings } from '../__mocks__/state-mocks';
55
import { AppContext } from '../context/App';
66
import { IconColor } from '../types';
77
import * as comms from '../utils/comms';
@@ -27,8 +27,9 @@ describe('components/Sidebar.tsx', () => {
2727
const tree = render(
2828
<AppContext.Provider
2929
value={{
30-
settings: mockSettings,
3130
notifications: mockAccountNotifications,
31+
auth: mockAuth,
32+
settings: mockSettings,
3233
}}
3334
>
3435
<MemoryRouter>
@@ -46,6 +47,7 @@ describe('components/Sidebar.tsx', () => {
4647
value={{
4748
isLoggedIn: false,
4849
notifications: mockAccountNotifications,
50+
auth: mockAuth,
4951
settings: mockSettings,
5052
}}
5153
>
@@ -61,7 +63,12 @@ describe('components/Sidebar.tsx', () => {
6163
it('should open the gitify repository', () => {
6264
render(
6365
<AppContext.Provider
64-
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
66+
value={{
67+
isLoggedIn: false,
68+
notifications: [],
69+
auth: mockAuth,
70+
settings: mockSettings,
71+
}}
6572
>
6673
<MemoryRouter>
6774
<Sidebar />
@@ -85,6 +92,7 @@ describe('components/Sidebar.tsx', () => {
8592
value={{
8693
isLoggedIn: true,
8794
notifications: [],
95+
auth: mockAuth,
8896
settings: mockSettings,
8997
}}
9098
>
@@ -114,6 +122,7 @@ describe('components/Sidebar.tsx', () => {
114122
value={{
115123
isLoggedIn: true,
116124
notifications: mockAccountNotifications,
125+
auth: mockAuth,
117126
settings: mockSettings,
118127
}}
119128
>
@@ -146,6 +155,7 @@ describe('components/Sidebar.tsx', () => {
146155
value={{
147156
isLoggedIn: true,
148157
notifications: mockAccountNotifications,
158+
auth: mockAuth,
149159
settings: mockSettings,
150160
}}
151161
>
@@ -169,6 +179,7 @@ describe('components/Sidebar.tsx', () => {
169179
value={{
170180
isLoggedIn: true,
171181
notifications: mockAccountNotifications,
182+
auth: mockAuth,
172183
settings: mockSettings,
173184
}}
174185
>
@@ -193,6 +204,7 @@ describe('components/Sidebar.tsx', () => {
193204
value={{
194205
isLoggedIn: true,
195206
notifications: [],
207+
auth: mockAuth,
196208
settings: mockSettings,
197209
fetchNotifications,
198210
status: 'success',
@@ -215,6 +227,7 @@ describe('components/Sidebar.tsx', () => {
215227
value={{
216228
isLoggedIn: true,
217229
notifications: [],
230+
auth: mockAuth,
218231
settings: mockSettings,
219232
fetchNotifications,
220233
status: 'loading',
@@ -239,6 +252,7 @@ describe('components/Sidebar.tsx', () => {
239252
value={{
240253
isLoggedIn: true,
241254
notifications: [],
255+
auth: mockAuth,
242256
settings: mockSettings,
243257
}}
244258
>
@@ -257,6 +271,7 @@ describe('components/Sidebar.tsx', () => {
257271
value={{
258272
isLoggedIn: true,
259273
notifications: [],
274+
auth: mockAuth,
260275
settings: mockSettings,
261276
}}
262277
>
@@ -277,6 +292,7 @@ describe('components/Sidebar.tsx', () => {
277292
value={{
278293
isLoggedIn: true,
279294
notifications: [],
295+
auth: mockAuth,
280296
settings: mockSettings,
281297
}}
282298
>
@@ -297,6 +313,7 @@ describe('components/Sidebar.tsx', () => {
297313
value={{
298314
isLoggedIn: true,
299315
notifications: [],
316+
auth: mockAuth,
300317
settings: mockSettings,
301318
fetchNotifications,
302319
}}
@@ -322,6 +339,7 @@ describe('components/Sidebar.tsx', () => {
322339
value={{
323340
isLoggedIn: true,
324341
notifications: mockAccountNotifications,
342+
auth: mockAuth,
325343
settings: mockSettings,
326344
}}
327345
>
@@ -345,6 +363,7 @@ describe('components/Sidebar.tsx', () => {
345363
value={{
346364
isLoggedIn: true,
347365
notifications: mockAccountNotifications,
366+
auth: mockAuth,
348367
settings: mockSettings,
349368
}}
350369
>
@@ -368,6 +387,7 @@ describe('components/Sidebar.tsx', () => {
368387
value={{
369388
isLoggedIn: true,
370389
notifications: mockAccountNotifications,
390+
auth: mockAuth,
371391
settings: mockSettings,
372392
}}
373393
>
@@ -388,7 +408,12 @@ describe('components/Sidebar.tsx', () => {
388408

389409
render(
390410
<AppContext.Provider
391-
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
411+
value={{
412+
isLoggedIn: false,
413+
notifications: [],
414+
auth: mockAuth,
415+
settings: mockSettings,
416+
}}
392417
>
393418
<MemoryRouter>
394419
<Sidebar />
@@ -406,7 +431,12 @@ describe('components/Sidebar.tsx', () => {
406431

407432
render(
408433
<AppContext.Provider
409-
value={{ isLoggedIn: false, notifications: [], settings: mockSettings }}
434+
value={{
435+
isLoggedIn: false,
436+
notifications: [],
437+
auth: mockAuth,
438+
settings: mockSettings,
439+
}}
410440
>
411441
<MemoryRouter>
412442
<Sidebar />
@@ -427,6 +457,7 @@ describe('components/Sidebar.tsx', () => {
427457
value={{
428458
isLoggedIn: true,
429459
notifications: [],
460+
auth: mockAuth,
430461
settings: mockSettings,
431462
}}
432463
>
@@ -448,6 +479,7 @@ describe('components/Sidebar.tsx', () => {
448479
value={{
449480
isLoggedIn: true,
450481
notifications: mockAccountNotifications,
482+
auth: mockAuth,
451483
settings: mockSettings,
452484
}}
453485
>

src/components/Sidebar.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { useLocation, useNavigate } from 'react-router-dom';
1212
import { AppContext } from '../context/App';
1313
import { Size } from '../types';
1414
import { quitApp } from '../utils/comms';
15+
import Constants from '../utils/constants';
1516
import { getFilterCount } from '../utils/helpers';
1617
import {
1718
openGitHubIssues,
@@ -27,8 +28,18 @@ export const Sidebar: FC = () => {
2728
const navigate = useNavigate();
2829
const location = useLocation();
2930

30-
const { notifications, fetchNotifications, isLoggedIn, status, settings } =
31-
useContext(AppContext);
31+
const {
32+
notifications,
33+
fetchNotifications,
34+
isLoggedIn,
35+
status,
36+
settings,
37+
auth,
38+
} = useContext(AppContext);
39+
40+
// We naively assume that the first account is the primary account for the purposes of our sidebar quick links
41+
const primaryAccountHostname =
42+
auth.accounts[0]?.hostname ?? Constants.DEFAULT_AUTH_OPTIONS.hostname;
3243

3344
const toggleFilters = () => {
3445
if (location.pathname.startsWith('/filters')) {
@@ -77,19 +88,19 @@ export const Sidebar: FC = () => {
7788
title={`${notificationsCount} Unread Notifications`}
7889
metric={notificationsCount}
7990
icon={BellIcon}
80-
onClick={() => openGitHubNotifications()}
91+
onClick={() => openGitHubNotifications(primaryAccountHostname)}
8192
/>
8293

8394
<SidebarButton
8495
title="My Issues"
8596
icon={IssueOpenedIcon}
86-
onClick={() => openGitHubIssues()}
97+
onClick={() => openGitHubIssues(primaryAccountHostname)}
8798
/>
8899

89100
<SidebarButton
90101
title="My Pull Requests"
91102
icon={GitPullRequestIcon}
92-
onClick={() => openGitHubPulls()}
103+
onClick={() => openGitHubPulls(primaryAccountHostname)}
93104
/>
94105
</div>
95106

src/utils/auth/migration.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ export async function migrateAuthenticatedAccounts() {
1313
const existing = loadState();
1414

1515
if (!hasAccountsToMigrate(existing.auth)) {
16-
log.info('Account Migration: No accounts need migrating');
1716
return;
1817
}
1918

src/utils/links.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,21 +46,21 @@ describe('utils/links.ts', () => {
4646
});
4747

4848
it('openGitHubNotifications', () => {
49-
openGitHubNotifications();
49+
openGitHubNotifications(mockGitHubCloudAccount.hostname);
5050
expect(openExternalLinkMock).toHaveBeenCalledWith(
5151
'https://github.com/notifications',
5252
);
5353
});
5454

5555
it('openGitHubIssues', () => {
56-
openGitHubIssues();
56+
openGitHubIssues(mockGitHubCloudAccount.hostname);
5757
expect(openExternalLinkMock).toHaveBeenCalledWith(
5858
'https://github.com/issues',
5959
);
6060
});
6161

6262
it('openGitHubPulls', () => {
63-
openGitHubPulls();
63+
openGitHubPulls(mockGitHubCloudAccount.hostname);
6464
expect(openExternalLinkMock).toHaveBeenCalledWith(
6565
'https://github.com/pulls',
6666
);

src/utils/links.ts

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,22 @@ export function openGitifyReleaseNotes(version: string) {
1515
);
1616
}
1717

18-
export function openGitHubNotifications() {
19-
openExternalLink('https://github.com/notifications' as Link);
18+
export function openGitHubNotifications(hostname: Hostname) {
19+
const url = new URL(`https://${hostname}`);
20+
url.pathname = 'notifications';
21+
openExternalLink(url.toString() as Link);
2022
}
2123

22-
export function openGitHubIssues() {
23-
openExternalLink('https://github.com/issues' as Link);
24+
export function openGitHubIssues(hostname: Hostname) {
25+
const url = new URL(`https://${hostname}`);
26+
url.pathname = 'issues';
27+
openExternalLink(url.toString() as Link);
2428
}
2529

26-
export function openGitHubPulls() {
27-
openExternalLink('https://github.com/pulls' as Link);
30+
export function openGitHubPulls(hostname: Hostname) {
31+
const url = new URL(`https://${hostname}`);
32+
url.pathname = 'pulls';
33+
openExternalLink(url.toString() as Link);
2834
}
2935

3036
export function openAccountProfile(account: Account) {

0 commit comments

Comments
 (0)