From ba80e2d7a2bcb10385722c56c147cb39d4e66e4f Mon Sep 17 00:00:00 2001 From: andreastanderen Date: Thu, 24 Oct 2024 09:41:43 +0200 Subject: [PATCH] Use StudioContentMenu in SettingsModal --- .../SettingsModal/SettingsModal.module.css | 1 + .../SettingsModal/SettingsModal.tsx | 67 ++++++------------- .../hooks/useSettingsModalMenuTabConfigs.tsx | 46 +++++++++++++ .../types/SettingsModalHandle.ts | 4 +- .../types/SettingsModalTabId.ts | 1 + .../types/StudioMenuTabType.ts | 15 +++++ .../src/ScopedStorage/ScopedStorage.ts | 1 - 7 files changed, 85 insertions(+), 50 deletions(-) create mode 100644 frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs.tsx create mode 100644 frontend/app-development/types/SettingsModalTabId.ts create mode 100644 frontend/libs/studio-components/src/components/StudioContentMenu/types/StudioMenuTabType.ts diff --git a/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css index 50c2a6150c2..67c66e7afe7 100644 --- a/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css +++ b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.module.css @@ -13,6 +13,7 @@ .leftNavWrapper { overflow-y: auto; + width: 250px; } .contentWrapper { diff --git a/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.tsx b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.tsx index c0bb28a0bc1..87acb0b6e37 100644 --- a/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.tsx +++ b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/SettingsModal.tsx @@ -1,33 +1,26 @@ import type { ReactElement } from 'react'; import React, { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react'; import classes from './SettingsModal.module.css'; -import { - CogIcon, - InformationSquareIcon, - TimerStartIcon, - ShieldLockIcon, - SidebarBothIcon, -} from '@studio/icons'; -import { StudioModal } from '@studio/components'; -import type { LeftNavigationTab } from 'app-shared/types/LeftNavigationTab'; -import { LeftNavigationBar } from 'app-shared/components/LeftNavigationBar'; -import type { SettingsModalTab } from 'app-development/types/SettingsModalTab'; -import { createNavigationTab } from './utils'; +import { CogIcon } from '@studio/icons'; +import { StudioModal, StudioContentMenu } from '@studio/components'; +import type { SettingsModalTabId } from 'app-development/types/SettingsModalTabId'; import { useTranslation } from 'react-i18next'; import { PolicyTab } from './components/Tabs/PolicyTab'; import { AboutTab } from './components/Tabs/AboutTab'; import { AccessControlTab } from './components/Tabs/AccessControlTab'; import { SetupTab } from './components/Tabs/SetupTab'; import { type SettingsModalHandle } from 'app-development/types/SettingsModalHandle'; +import { useSettingsModalMenuTabConfigs } from './hooks/useSettingsModalMenuTabConfigs'; export const SettingsModal = forwardRef(({}, ref): ReactElement => { const { t } = useTranslation(); - const [currentTab, setCurrentTab] = useState('about'); + const [currentTab, setCurrentTab] = useState('about'); const dialogRef = useRef(); + const { getMenuTabConfigs } = useSettingsModalMenuTabConfigs(); const openSettings = useCallback( - (tab: SettingsModalTab = currentTab) => { + (tab: SettingsModalTabId = currentTab) => { setCurrentTab(tab); dialogRef.current?.showModal(); }, @@ -38,38 +31,6 @@ export const SettingsModal = forwardRef(({}, ref): Reac openSettings, ]); - const aboutTabId: SettingsModalTab = 'about'; - const setupTabId: SettingsModalTab = 'setup'; - const policyTabId: SettingsModalTab = 'policy'; - const accessControlTabId: SettingsModalTab = 'access_control'; - - const leftNavigationTabs: LeftNavigationTab[] = [ - createNavigationTab( - , - aboutTabId, - () => setCurrentTab(aboutTabId), - currentTab, - ), - createNavigationTab( - , - setupTabId, - () => setCurrentTab(setupTabId), - currentTab, - ), - createNavigationTab( - , - policyTabId, - () => setCurrentTab(policyTabId), - currentTab, - ), - createNavigationTab( - , - accessControlTabId, - () => setCurrentTab(accessControlTabId), - currentTab, - ), - ]; - const displayTabs = () => { switch (currentTab) { case 'about': { @@ -98,7 +59,19 @@ export const SettingsModal = forwardRef(({}, ref): Reac contentClassName={classes.modalContent} >
- + setCurrentTab(tabId)} + > + {getMenuTabConfigs().map((contentTab) => ( + + ))} +
{displayTabs()}
diff --git a/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs.tsx b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs.tsx new file mode 100644 index 00000000000..b0e7e3b487b --- /dev/null +++ b/frontend/app-development/layout/PageHeader/SubHeader/SettingsModalButton/SettingsModal/hooks/useSettingsModalMenuTabConfigs.tsx @@ -0,0 +1,46 @@ +import React from 'react'; +import type { SettingsModalTabId } from '../../../../../../types/SettingsModalTabId'; +import { + InformationSquareIcon, + SidebarBothIcon, + ShieldLockIcon, + TimerStartIcon, +} from '@studio/icons'; +import { useTranslation } from 'react-i18next'; +import type { StudioMenuTabType } from '@studio/components'; + +const aboutTabId: SettingsModalTabId = 'about'; +const setupTabId: SettingsModalTabId = 'setup'; +const policyTabId: SettingsModalTabId = 'policy'; +const accessControlTabId: SettingsModalTabId = 'access_control'; + +export const useSettingsModalMenuTabConfigs = () => { + const { t } = useTranslation(); + + const getMenuTabConfigs = (): StudioMenuTabType[] => { + return [ + { + tabId: aboutTabId, + tabName: t(`settings_modal.left_nav_tab_${aboutTabId}`), + icon: , + }, + { + tabId: setupTabId, + tabName: t(`settings_modal.left_nav_tab_${setupTabId}`), + icon: , + }, + { + tabId: policyTabId, + tabName: t(`settings_modal.left_nav_tab_${policyTabId}`), + icon: , + }, + { + tabId: accessControlTabId, + tabName: t(`settings_modal.left_nav_tab_${accessControlTabId}`), + icon: , + }, + ]; + }; + + return { getMenuTabConfigs }; +}; diff --git a/frontend/app-development/types/SettingsModalHandle.ts b/frontend/app-development/types/SettingsModalHandle.ts index 5f2b30cc351..580159b04bb 100644 --- a/frontend/app-development/types/SettingsModalHandle.ts +++ b/frontend/app-development/types/SettingsModalHandle.ts @@ -1,5 +1,5 @@ -import type { SettingsModalTab } from './SettingsModalTab'; +import type { SettingsModalTabId } from './SettingsModalTabId'; export type SettingsModalHandle = { - openSettings: (tab?: SettingsModalTab) => void; + openSettings: (tab?: SettingsModalTabId) => void; }; diff --git a/frontend/app-development/types/SettingsModalTabId.ts b/frontend/app-development/types/SettingsModalTabId.ts new file mode 100644 index 00000000000..c596b1e0d5b --- /dev/null +++ b/frontend/app-development/types/SettingsModalTabId.ts @@ -0,0 +1 @@ +export type SettingsModalTabId = 'about' | 'setup' | 'policy' | 'access_control'; diff --git a/frontend/libs/studio-components/src/components/StudioContentMenu/types/StudioMenuTabType.ts b/frontend/libs/studio-components/src/components/StudioContentMenu/types/StudioMenuTabType.ts new file mode 100644 index 00000000000..84b65d3ad24 --- /dev/null +++ b/frontend/libs/studio-components/src/components/StudioContentMenu/types/StudioMenuTabType.ts @@ -0,0 +1,15 @@ +import type { ReactNode } from 'react'; + +export type StudioButtonTabType = { + icon: ReactNode; + tabName: string; + tabId: TabId; +}; + +export type StudioLinkTabType = StudioButtonTabType & { + to: string; +}; + +export type StudioMenuTabType = + | StudioButtonTabType + | StudioLinkTabType; diff --git a/frontend/libs/studio-pure-functions/src/ScopedStorage/ScopedStorage.ts b/frontend/libs/studio-pure-functions/src/ScopedStorage/ScopedStorage.ts index 0fc48637a6f..8e08846222b 100644 --- a/frontend/libs/studio-pure-functions/src/ScopedStorage/ScopedStorage.ts +++ b/frontend/libs/studio-pure-functions/src/ScopedStorage/ScopedStorage.ts @@ -7,7 +7,6 @@ export interface ScopedStorageResult extends ScopedStorage { getItem: (key: string) => T; removeItem: (key: string) => void; } - export class ScopedStorageImpl implements ScopedStorage { private readonly storageKey: StorageKey; private readonly scopedStorage: ScopedStorage;