From 650fcc5a5f90f5ab2a9fe5fc8343d2e6ed833228 Mon Sep 17 00:00:00 2001 From: Adam Setch Date: Sat, 14 Sep 2024 11:10:50 -0400 Subject: [PATCH] feat: always show account header Signed-off-by: Adam Setch --- src/__mocks__/state-mocks.ts | 1 - src/components/AccountNotifications.test.tsx | 10 +- src/components/AccountNotifications.tsx | 109 +++++++++--------- .../settings/AppearanceSettings.test.tsx | 33 +----- .../settings/AppearanceSettings.tsx | 14 +-- src/context/App.tsx | 1 - src/routes/Accounts.tsx | 27 ++--- src/routes/Notifications.test.tsx | 17 +-- src/routes/Notifications.tsx | 9 +- src/types.ts | 1 - src/utils/constants.ts | 2 - src/utils/links.ts | 5 - 12 files changed, 68 insertions(+), 161 deletions(-) diff --git a/src/__mocks__/state-mocks.ts b/src/__mocks__/state-mocks.ts index 18def091..7e5a9048 100644 --- a/src/__mocks__/state-mocks.ts +++ b/src/__mocks__/state-mocks.ts @@ -33,7 +33,6 @@ export const mockAuth: AuthState = { const mockAppearanceSettings = { theme: Theme.SYSTEM, zoomPercentage: 100, - showAccountHeader: false, }; const mockNotificationSettings = { diff --git a/src/components/AccountNotifications.test.tsx b/src/components/AccountNotifications.test.tsx index 582c41cd..921d5a1c 100644 --- a/src/components/AccountNotifications.test.tsx +++ b/src/components/AccountNotifications.test.tsx @@ -20,11 +20,10 @@ describe('components/AccountNotifications.tsx', () => { mockDirectoryPath(); }); - it('should render itself - group notifications by repositories', () => { + it('should render itself - group notifications by products', () => { const props = { account: mockAtlassianCloudAccount, notifications: mockAtlasifyNotification, - showAccountHeader: true, error: null, }; @@ -42,7 +41,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: mockAtlasifyNotification, - showAccountHeader: true, error: null, }; @@ -60,7 +58,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: [], - showAccountHeader: true, error: null, }; @@ -81,7 +78,6 @@ describe('components/AccountNotifications.tsx', () => { descriptions: ['Error description'], emojis: ['🔥'], }, - showAccountHeader: true, }; const tree = render( @@ -100,7 +96,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: [], - showAccountHeader: true, error: null, }; @@ -128,7 +123,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: [], - showAccountHeader: true, error: null, }; @@ -153,7 +147,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: [], - showAccountHeader: true, error: null, }; @@ -174,7 +167,6 @@ describe('components/AccountNotifications.tsx', () => { const props = { account: mockAtlassianCloudAccount, notifications: mockAtlasifyNotification, - showAccountHeader: true, error: null, }; diff --git a/src/components/AccountNotifications.tsx b/src/components/AccountNotifications.tsx index 0debedd4..18d879c8 100644 --- a/src/components/AccountNotifications.tsx +++ b/src/components/AccountNotifications.tsx @@ -26,7 +26,6 @@ interface IAccountNotifications { account: Account; notifications: AtlasifyNotification[]; error: AtlasifyError | null; - showAccountHeader: boolean; } export const AccountNotifications: FC = ( @@ -34,7 +33,7 @@ export const AccountNotifications: FC = ( ) => { const [showOnlyUnread, setShowOnlyUnread] = useState(false); - const { account, showAccountHeader, notifications } = props; + const { account, notifications } = props; const { settings } = useContext(AppContext); @@ -80,61 +79,59 @@ export const AccountNotifications: FC = ( return ( <> - {showAccountHeader && ( -
-
- -
- - - setShowOnlyUnread((prev) => !prev)} - /> - - - - - +
+
+
- )} + + + setShowOnlyUnread((prev) => !prev)} + /> + + + + + +
{showAccountNotifications && ( <> diff --git a/src/components/settings/AppearanceSettings.test.tsx b/src/components/settings/AppearanceSettings.test.tsx index 4d717109..fc89a5f0 100644 --- a/src/components/settings/AppearanceSettings.test.tsx +++ b/src/components/settings/AppearanceSettings.test.tsx @@ -1,11 +1,7 @@ import { act, fireEvent, render, screen } from '@testing-library/react'; import { webFrame } from 'electron'; import { MemoryRouter } from 'react-router-dom'; -import { - mockAtlassianCloudAccount, - mockAuth, - mockSettings, -} from '../../__mocks__/state-mocks'; +import { mockAuth, mockSettings } from '../../__mocks__/state-mocks'; import { AppContext } from '../../context/App'; import { AppearanceSettings } from './AppearanceSettings'; @@ -198,31 +194,4 @@ describe('routes/components/settings/AppearanceSettings.tsx', () => { expect(updateSetting).toHaveBeenCalledTimes(1); expect(updateSetting).toHaveBeenCalledWith('showNumber', false); }); - - it('should toggle account header checkbox', async () => { - await act(async () => { - render( - - - - - , - ); - }); - - await screen.findByLabelText('Show account header'); - - fireEvent.click(screen.getByLabelText('Show account header')); - - expect(updateSetting).toHaveBeenCalledTimes(1); - expect(updateSetting).toHaveBeenCalledWith('showAccountHeader', true); - }); }); diff --git a/src/components/settings/AppearanceSettings.tsx b/src/components/settings/AppearanceSettings.tsx index 410528c2..f5eeccab 100644 --- a/src/components/settings/AppearanceSettings.tsx +++ b/src/components/settings/AppearanceSettings.tsx @@ -3,11 +3,9 @@ import { ipcRenderer, webFrame } from 'electron'; import { type FC, useContext, useEffect, useState } from 'react'; import { AppContext } from '../../context/App'; import { Theme } from '../../types'; -import { hasMultipleAccounts } from '../../utils/auth/utils'; import { setTheme } from '../../utils/theme'; import { zoomLevelToPercentage, zoomPercentageToLevel } from '../../utils/zoom'; import { Button } from '../buttons/Button'; -import { Checkbox } from '../fields/Checkbox'; import { RadioGroup } from '../fields/RadioGroup'; import { Legend } from './Legend'; @@ -15,7 +13,7 @@ let timeout: NodeJS.Timeout; const DELAY = 200; export const AppearanceSettings: FC = () => { - const { auth, settings, updateSetting } = useContext(AppContext); + const { settings, updateSetting } = useContext(AppContext); const [zoomPercentage, setZoomPercentage] = useState( zoomLevelToPercentage(webFrame.getZoomLevel()), ); @@ -99,16 +97,6 @@ export const AppearanceSettings: FC = () => { X
- - - updateSetting('showAccountHeader', evt.target.checked) - } - /> ); }; diff --git a/src/context/App.tsx b/src/context/App.tsx index f4f78748..b8f9e9da 100644 --- a/src/context/App.tsx +++ b/src/context/App.tsx @@ -49,7 +49,6 @@ export const defaultAuth: AuthState = { const defaultAppearanceSettings = { theme: Theme.SYSTEM, zoomPercentage: 100, - showAccountHeader: false, }; const defaultNotificationSettings = { diff --git a/src/routes/Accounts.tsx b/src/routes/Accounts.tsx index ed2e1ebf..79509b8e 100644 --- a/src/routes/Accounts.tsx +++ b/src/routes/Accounts.tsx @@ -20,7 +20,7 @@ import type { Account } from '../types'; import { getAccountUUID, refreshAccount } from '../utils/auth/utils'; import { cn } from '../utils/cn'; import { updateTrayIcon, updateTrayTitle } from '../utils/comms'; -import { openAccountProfile, openManageProfileSecurity } from '../utils/links'; +import { openAccountProfile } from '../utils/links'; import { saveState } from '../utils/storage'; export const AccountsRoute: FC = () => { @@ -71,28 +71,21 @@ export const AccountsRoute: FC = () => {
{account.user.name}
-
- +
+
{account.user.login}
-
- +
+
{account.method}
diff --git a/src/routes/Notifications.test.tsx b/src/routes/Notifications.test.tsx index f61e78f2..071a9610 100644 --- a/src/routes/Notifications.test.tsx +++ b/src/routes/Notifications.test.tsx @@ -1,6 +1,5 @@ import { render } from '@testing-library/react'; import { mockAccountNotifications } from '../__mocks__/notifications-mocks'; -import { mockSettings } from '../__mocks__/state-mocks'; import { AppContext } from '../context/App'; import { Errors } from '../utils/errors'; import { NotificationsRoute } from './Notifications'; @@ -28,7 +27,7 @@ describe('routes/Notifications.tsx', () => { expect(tree).toMatchSnapshot(); }); - it('should render itself & its children (all read notifications)', () => { + it('should render itself & its children', () => { const tree = render( @@ -37,20 +36,6 @@ describe('routes/Notifications.tsx', () => { expect(tree).toMatchSnapshot(); }); - it('should render itself & its children (show account header)', () => { - const tree = render( - - - , - ); - expect(tree).toMatchSnapshot(); - }); - describe('should render itself & its children (error conditions - oops)', () => { it('bad credentials', () => { const tree = render( diff --git a/src/routes/Notifications.tsx b/src/routes/Notifications.tsx index ab129c70..995fc640 100644 --- a/src/routes/Notifications.tsx +++ b/src/routes/Notifications.tsx @@ -8,13 +8,7 @@ import { Errors } from '../utils/errors'; import { getNotificationCount } from '../utils/notifications'; export const NotificationsRoute: FC = () => { - const { notifications, status, globalError, settings } = - useContext(AppContext); - - const hasMultipleAccounts = useMemo( - () => notifications.length > 1, - [notifications], - ); + const { notifications, status, globalError } = useContext(AppContext); const hasNoAccountErrors = useMemo( () => notifications.every((account) => account.error === null), @@ -42,7 +36,6 @@ export const NotificationsRoute: FC = () => { account={accountNotifications.account} notifications={accountNotifications.notifications} error={accountNotifications.error} - showAccountHeader={hasMultipleAccounts || settings.showAccountHeader} /> ))} diff --git a/src/types.ts b/src/types.ts index aa81e581..16f36d61 100644 --- a/src/types.ts +++ b/src/types.ts @@ -50,7 +50,6 @@ export type SettingsState = AppearanceSettingsState & interface AppearanceSettingsState { theme: Theme; zoomPercentage: number; - showAccountHeader: boolean; } interface NotificationSettingsState { diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 9b771f51..a847118b 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -22,8 +22,6 @@ export const Constants = { WEB: { MY_NOTIFICATIONS: 'https://team.atlassian.com/notifications' as Link, PEOPLE: 'https://team.atlassian.com/people' as Link, - PROFILE_SECURITY: - 'https://id.atlassian.com/manage-profile/security' as Link, SECURITY_TOKENS: 'https://id.atlassian.com/manage-profile/security/api-tokens' as Link, }, diff --git a/src/utils/links.ts b/src/utils/links.ts index c181c64a..adeb7ad7 100644 --- a/src/utils/links.ts +++ b/src/utils/links.ts @@ -35,11 +35,6 @@ export function openAccountProfile(account: Account) { openExternalLink(url.toString() as Link); } -export function openManageProfileSecurity() { - const url = new URL(Constants.ATLASSIAN_URLS.WEB.PROFILE_SECURITY); - openExternalLink(url.toString() as Link); -} - export function openUserProfile(user: SubjectUser) { openExternalLink(user.html_url); }