From e7bf214e2053d798c5267ec148b54e175f2dad2e Mon Sep 17 00:00:00 2001 From: Michal Stanke Date: Tue, 8 Oct 2024 12:15:28 +0200 Subject: [PATCH] chore: simplify toolbar button configuration fix #943, removes options for hiding toolbar button badge completely, and to open Pontoon home page regardless of the locale team selected --- src/background/toolbarButton.ts | 19 ++++--------------- src/commons/data/defaultOptions.ts | 15 ++++++++++++--- src/commons/options.spec.ts | 1 + src/commons/options.ts | 9 ++++++--- src/frontend/options/App/index.tsx | 5 ----- .../ToolbarButtonActionSelection/index.tsx | 3 --- 6 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/background/toolbarButton.ts b/src/background/toolbarButton.ts index e1c21704..fd1fbd00 100644 --- a/src/background/toolbarButton.ts +++ b/src/background/toolbarButton.ts @@ -61,9 +61,6 @@ async function registerBadgeChanges() { } }, ); - listenToOptionChange('display_toolbar_button_badge', () => { - updateBadge(); - }); await updateBadge(); } @@ -88,9 +85,6 @@ async function buttonClickHandler() { switch (action) { case 'popup': break; - case 'home-page': - await openNewPontoonTab(await getOneOption('pontoon_base_url')); - break; case 'team-page': await openNewPontoonTab(pontoonTeam(pontoonBaseUrl, { code: teamCode })); break; @@ -105,7 +99,6 @@ function registerButtonPopup(action: OptionValue<'toolbar_button_action'>) { case 'popup': popup = getResourceUrl('frontend/toolbar-button.html'); break; - case 'home-page': case 'team-page': popup = ''; break; @@ -131,14 +124,10 @@ async function updateBadge( notificationsDataLoadingState === 'loaded') && typeof notificationsData === 'object' ) { - if (await getOneOption('display_toolbar_button_badge')) { - const unreadNotificationsCount = Object.values(notificationsData).filter( - (n) => n.unread, - ).length; - await loadedBadge(unreadNotificationsCount); - } else { - await hideBadge(); - } + const unreadNotificationsCount = Object.values(notificationsData).filter( + (n) => n.unread, + ).length; + await loadedBadge(unreadNotificationsCount); } else if (notificationsDataLoadingState === 'loading') { await loadingBadge(); } else { diff --git a/src/commons/data/defaultOptions.ts b/src/commons/data/defaultOptions.ts index 769dfcb7..84f96534 100644 --- a/src/commons/data/defaultOptions.ts +++ b/src/commons/data/defaultOptions.ts @@ -4,8 +4,7 @@ import { browser, BrowserFamily } from '../webExtensionsApi'; export interface OptionsContent { locale_team: string; data_update_interval: number; - display_toolbar_button_badge: boolean; - toolbar_button_action: 'popup' | 'team-page' | 'home-page'; + toolbar_button_action: 'popup' | 'team-page'; toolbar_button_popup_always_hide_read_notifications: boolean; show_notifications: boolean; contextual_identity: string; @@ -16,12 +15,22 @@ const generalDefaultOptions: Omit = { locale_team: browser.i18n.getUILanguage(), pontoon_base_url: DEFAULT_PONTOON_BASE_URL, data_update_interval: 15, - display_toolbar_button_badge: true, toolbar_button_action: 'popup', toolbar_button_popup_always_hide_read_notifications: false, show_notifications: true, }; +export function coalesceLegacyValues( + id: K, + value: OptionsContent[K], +): OptionsContent[K] { + if (id === 'toolbar_button_action' && value === 'home-page') { + return 'team-page' as OptionsContent[K]; + } else { + return value; + } +} + export function defaultOptionsFor( browserFamily: BrowserFamily, ): OptionsContent { diff --git a/src/commons/options.spec.ts b/src/commons/options.spec.ts index 6d1468d6..6ef386d6 100644 --- a/src/commons/options.spec.ts +++ b/src/commons/options.spec.ts @@ -14,6 +14,7 @@ jest.mock('./data/defaultOptions', () => ({ defaultOptionsFor: () => ({ locale_team: 'en', }), + coalesceLegacyValues: (_: unknown, value: unknown) => value, })); beforeEach(() => { diff --git a/src/commons/options.ts b/src/commons/options.ts index 757471f6..e85c83c5 100644 --- a/src/commons/options.ts +++ b/src/commons/options.ts @@ -2,7 +2,7 @@ import type { Storage } from 'webextension-polyfill'; import { browser, browserFamily } from './webExtensionsApi'; import type { OptionsContent } from './data/defaultOptions'; -import { defaultOptionsFor } from './data/defaultOptions'; +import { coalesceLegacyValues, defaultOptionsFor } from './data/defaultOptions'; export type OptionId = keyof OptionsContent; @@ -11,7 +11,7 @@ type OptionValues = Pick; export type OptionValue = OptionValues[ID]; interface OptionChange extends Storage.StorageChange { - oldValue?: OptionValue; + oldValue?: never; newValue: OptionValue; } @@ -37,7 +37,10 @@ export async function getOptions( for (const optionId of optionIds) { const storageKey = storageKeyFor(optionId); if (typeof storageItems[storageKey] !== 'undefined') { - optionsWithDefaultValues[optionId] = storageItems[storageKey]; + optionsWithDefaultValues[optionId] = coalesceLegacyValues( + optionId, + storageItems[storageKey], + ); } else { optionsWithDefaultValues[optionId] = defaultValues[optionId]; } diff --git a/src/frontend/options/App/index.tsx b/src/frontend/options/App/index.tsx index 37b6269c..084136e3 100644 --- a/src/frontend/options/App/index.tsx +++ b/src/frontend/options/App/index.tsx @@ -80,11 +80,6 @@ export const App: React.FC = () => {
Toolbar button -
- - Show the number of unread notifications in the toolbar button - -
diff --git a/src/frontend/options/ToolbarButtonActionSelection/index.tsx b/src/frontend/options/ToolbarButtonActionSelection/index.tsx index e0bbd015..25cc6dc1 100644 --- a/src/frontend/options/ToolbarButtonActionSelection/index.tsx +++ b/src/frontend/options/ToolbarButtonActionSelection/index.tsx @@ -20,9 +20,6 @@ const options: { 'team-page': { label: 'Open your locale team page', }, - 'home-page': { - label: 'Open your Pontoon homepage', - }, }; export const ToolbarButtonActionSelection: React.FC = () => {