From 0af174489219d803487551b90510e097e9bc59ba Mon Sep 17 00:00:00 2001 From: Cataldo Date: Tue, 11 Jul 2023 15:50:00 +0200 Subject: [PATCH] feat: hide settings based on zimbraFeatureOptionsEnabled value refs: SHELL-120 (#283) --- src/boot/app/default-views.ts | 27 ++++++++++++++++++-------- src/shell/shell-primary-bar.test.tsx | 29 +++++++++++++++++++++++++++- src/test/constants.ts | 3 ++- types/account/index.d.ts | 1 + 4 files changed, 50 insertions(+), 10 deletions(-) diff --git a/src/boot/app/default-views.ts b/src/boot/app/default-views.ts index a48bc73c..1cf80e78 100644 --- a/src/boot/app/default-views.ts +++ b/src/boot/app/default-views.ts @@ -7,6 +7,7 @@ import produce from 'immer'; import type { TFunction } from 'i18next'; +import { size } from 'lodash'; import type { AppState, PrimaryBarView, SettingsView } from '../../../types'; import { SEARCH_APP_ID, SETTINGS_APP_ID, SHELL_APP_ID } from '../../constants'; import Feedback from '../../reporting/feedback'; @@ -17,6 +18,7 @@ import { settingsSubSections } from '../../settings/general-settings-sub-section import { SettingsAppView } from '../../settings/settings-app-view'; import { SettingsSidebar } from '../../settings/settings-sidebar'; import { useAppStore } from '../../store/app'; +import { useAccountStore } from '../../store/account'; const settingsRoute = { route: SETTINGS_APP_ID, @@ -103,14 +105,23 @@ const feedbackBoardView = { export const registerDefaultViews = (t: TFunction): void => { useAppStore.setState( produce((s: AppState) => { - s.routes = { - [SEARCH_APP_ID]: searchRoute, - [SETTINGS_APP_ID]: settingsRoute - }; - s.views.primaryBar = [searchPrimaryBar(t), settingsPrimaryBar(t)]; - s.views.secondaryBar = [settingsSecondaryBar]; - s.views.appView = [searchAppView, settingsAppView]; - s.views.settings = [settingsGeneralView(t), settingsAccountsView(t)]; + const { attrs } = useAccountStore.getState().settings; + if (size(attrs) === 0 || attrs.zimbraFeatureOptionsEnabled === 'FALSE') { + s.routes = { + [SEARCH_APP_ID]: searchRoute + }; + s.views.primaryBar = [searchPrimaryBar(t)]; + s.views.appView = [searchAppView]; + } else { + s.routes = { + [SEARCH_APP_ID]: searchRoute, + [SETTINGS_APP_ID]: settingsRoute + }; + s.views.primaryBar = [searchPrimaryBar(t), settingsPrimaryBar(t)]; + s.views.secondaryBar = [settingsSecondaryBar]; + s.views.appView = [searchAppView, settingsAppView]; + s.views.settings = [settingsGeneralView(t), settingsAccountsView(t)]; + } s.views.board = [feedbackBoardView]; }) ); diff --git a/src/shell/shell-primary-bar.test.tsx b/src/shell/shell-primary-bar.test.tsx index 1f5c9fb4..0ec50e58 100644 --- a/src/shell/shell-primary-bar.test.tsx +++ b/src/shell/shell-primary-bar.test.tsx @@ -9,14 +9,17 @@ import { act, screen, within } from '@testing-library/react'; import { Button, Text } from '@zextras/carbonio-design-system'; import { Route, Switch, useParams, useRouteMatch } from 'react-router-dom'; +import produce from 'immer'; import AppViewContainer from './app-view-container'; import ShellPrimaryBar from './shell-primary-bar'; -import { PrimaryBarView } from '../../types'; +import { AccountState, PrimaryBarView } from '../../types'; import { DefaultViewsRegister } from '../boot/bootstrapper'; import { usePushHistoryCallback } from '../history/hooks'; import { ModuleSelector } from '../search/module-selector'; import { useAppStore } from '../store/app'; import { setup } from '../test/utils'; +import { useAccountStore } from '../store/account'; +import { ICONS } from '../test/constants'; const ShellWrapper = (): JSX.Element => ( <> @@ -419,4 +422,28 @@ describe('Shell primary bar', () => { expect(screen.queryByText('default mails view')).not.toBeInTheDocument(); expect(screen.queryByText('files view')).not.toBeInTheDocument(); }); + + test('When zimbraFeatureOptionsEnabled is TRUE the setting icon is visible in primary bar', async () => { + useAccountStore.setState( + produce((state: AccountState) => { + state.settings.attrs.zimbraFeatureOptionsEnabled = 'TRUE'; + }) + ); + const { getByRoleWithIcon } = setup(); + + const searchIcon = getByRoleWithIcon('button', { icon: ICONS.settings }); + expect(searchIcon).toBeVisible(); + expect(searchIcon).toBeEnabled(); + }); + + test('When zimbraFeatureOptionsEnabled is FALSE the setting icon is missing in primary bar', async () => { + useAccountStore.setState( + produce((state: AccountState) => { + state.settings.attrs.zimbraFeatureOptionsEnabled = 'FALSE'; + }) + ); + const { queryByRoleWithIcon } = setup(); + + expect(queryByRoleWithIcon('button', { icon: ICONS.settings })).not.toBeInTheDocument(); + }); }); diff --git a/src/test/constants.ts b/src/test/constants.ts index c3ad5c48..846cf63b 100644 --- a/src/test/constants.ts +++ b/src/test/constants.ts @@ -136,7 +136,8 @@ export const ICONS = { enlargeBoard: 'ExpandOutline', reduceBoard: 'CollapseOutline', resetBoardSize: 'DiagonalArrowLeftDown', - unCollapseBoard: 'BoardOpen' + unCollapseBoard: 'BoardOpen', + settings: 'SettingsModOutline' }; export const TESTID_SELECTORS = { diff --git a/types/account/index.d.ts b/types/account/index.d.ts index daa31e73..ade00dbc 100644 --- a/types/account/index.d.ts +++ b/types/account/index.d.ts @@ -95,6 +95,7 @@ export interface AccountSettingsPrefs { } export type AccountSettingsAttrs = { + zimbraFeatureOptionsEnabled?: BooleanString; zimbraIdentityMaxNumEntries?: number; [key: string]: string | number | Array; };