From 6086dea9fdca83ed762eba05a74cbd017e91df7e Mon Sep 17 00:00:00 2001 From: Derek Ho Date: Wed, 15 May 2024 14:04:52 -0400 Subject: [PATCH] Remove tenant tab when disabled via yaml Signed-off-by: Derek Ho --- public/apps/configuration/app-router.tsx | 77 +++++++++---------- .../tenant-list/tenant-instruction-view.tsx | 37 --------- .../panels/tenant-list/tenant-list.tsx | 5 -- .../tenant-instruction-view.test.tsx.snap | 31 -------- .../test/tenant-instruction-view.test.tsx | 25 ------ .../tenant-list/test/tenant-list.test.tsx | 28 ------- .../configuration/test/top-nav-menu.test.tsx | 6 ++ 7 files changed, 44 insertions(+), 165 deletions(-) delete mode 100644 public/apps/configuration/panels/tenant-list/tenant-instruction-view.tsx delete mode 100644 public/apps/configuration/panels/tenant-list/test/__snapshots__/tenant-instruction-view.test.tsx.snap delete mode 100644 public/apps/configuration/panels/tenant-list/test/tenant-instruction-view.test.tsx diff --git a/public/apps/configuration/app-router.tsx b/public/apps/configuration/app-router.tsx index 8fba2f24f..9067f783f 100644 --- a/public/apps/configuration/app-router.tsx +++ b/public/apps/configuration/app-router.tsx @@ -70,14 +70,6 @@ const ROUTE_MAP: { [key: string]: RouteItem } = { name: 'Tenants', href: buildUrl(ResourceType.tenants), }, - [ResourceType.tenantsManageTab]: { - name: 'TenantsManageTab', - href: buildUrl(ResourceType.tenantsManageTab), - }, - [ResourceType.tenantsConfigureTab]: { - name: '', - href: buildUrl(ResourceType.tenantsConfigureTab), - }, [ResourceType.auth]: { name: 'Authentication', href: buildUrl(ResourceType.auth), @@ -88,22 +80,26 @@ const ROUTE_MAP: { [key: string]: RouteItem } = { }, }; -const ROUTE_LIST = [ - ROUTE_MAP.getStarted, - ROUTE_MAP[ResourceType.auth], - ROUTE_MAP[ResourceType.roles], - ROUTE_MAP[ResourceType.users], - ROUTE_MAP[ResourceType.serviceAccounts], - ROUTE_MAP[ResourceType.permissions], - ROUTE_MAP[ResourceType.tenants], - ROUTE_MAP[ResourceType.auditLogging], - ROUTE_MAP[ResourceType.tenantsConfigureTab], -]; +const getRouteList = (multitenancyEnabled: boolean) => { + return [ + ROUTE_MAP.getStarted, + ROUTE_MAP[ResourceType.auth], + ROUTE_MAP[ResourceType.roles], + ROUTE_MAP[ResourceType.users], + ROUTE_MAP[ResourceType.serviceAccounts], + ROUTE_MAP[ResourceType.permissions], + ...(multitenancyEnabled ? [ROUTE_MAP[ResourceType.tenants]] : []), + ROUTE_MAP[ResourceType.auditLogging], + ]; +}; -const allNavPanelUrls = ROUTE_LIST.map((route) => route.href).concat([ - buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT, - buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT, -]); +const allNavPanelUrls = (multitenancyEnabled: boolean) => + getRouteList(multitenancyEnabled) + .map((route) => route.href) + .concat([ + buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_GENERAL_SETTINGS_EDIT, + buildUrl(ResourceType.auditLogging) + SUB_URL_FOR_COMPLIANCE_SETTINGS_EDIT, + ]); export function getBreadcrumbs( resourceType?: ResourceType, @@ -155,21 +151,37 @@ export const LocalCluster = { label: 'Local cluster', id: '' }; export const DataSourceContext = createContext(null); export function AppRouter(props: AppDependencies) { + const multitenancyEnabled = props.config.multitenancy.enabled; const dataSourceEnabled = !!props.depsStart.dataSource?.dataSourceEnabled; const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs); const dataSourceFromUrl = dataSourceEnabled ? getDataSourceFromUrl() : LocalCluster; const [dataSource, setDataSource] = useState(dataSourceFromUrl); + function getTenancyRoutes() { + if (multitenancyEnabled) { + return ( + { + setGlobalBreadcrumbs(ResourceType.tenants); + return ; + }} + /> + ); + } + return null; + } + return ( - {allNavPanelUrls.map((route) => ( + {allNavPanelUrls(multitenancyEnabled).map((route) => ( // Create different routes to update the 'selected' nav item . - + ))} @@ -267,20 +279,7 @@ export function AppRouter(props: AppDependencies) { return ; }} /> - { - setGlobalBreadcrumbs(ResourceType.tenants); - return ; - }} - /> - { - setGlobalBreadcrumbs(ResourceType.tenants); - return ; - }} - /> + {getTenancyRoutes()} { diff --git a/public/apps/configuration/panels/tenant-list/tenant-instruction-view.tsx b/public/apps/configuration/panels/tenant-list/tenant-instruction-view.tsx deleted file mode 100644 index d5e5ffe83..000000000 --- a/public/apps/configuration/panels/tenant-list/tenant-instruction-view.tsx +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -import React from 'react'; -import { EuiSpacer, EuiText, EuiTitle } from '@elastic/eui'; - -export function TenantInstructionView() { - return ( - <> - -

Tenants

-
- - - - -

You have not enabled multi tenancy

-
- - - Contact your administrator to enable multi tenancy. - - - ); -} diff --git a/public/apps/configuration/panels/tenant-list/tenant-list.tsx b/public/apps/configuration/panels/tenant-list/tenant-list.tsx index 0b97c6ae1..47f5035f4 100644 --- a/public/apps/configuration/panels/tenant-list/tenant-list.tsx +++ b/public/apps/configuration/panels/tenant-list/tenant-list.tsx @@ -30,7 +30,6 @@ import { AppDependencies } from '../../../types'; import { ExternalLink } from '../../utils/display-utils'; import { DocLinks } from '../../constants'; import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils'; -import { TenantInstructionView } from './tenant-instruction-view'; import { LocalCluster } from '../../app-router'; import { SecurityPluginTopNavMenu } from '../../top-nav-menu'; @@ -129,10 +128,6 @@ export function TenantList(props: TenantListProps) { )); }; - if (!props.config.multitenancy.enabled) { - return ; - } - return ( <> - -

- Tenants -

-
- - -

- You have not enabled multi tenancy -

-
- - Contact your administrator to enable multi tenancy. - - -`; diff --git a/public/apps/configuration/panels/tenant-list/test/tenant-instruction-view.test.tsx b/public/apps/configuration/panels/tenant-list/test/tenant-instruction-view.test.tsx deleted file mode 100644 index 929ab0629..000000000 --- a/public/apps/configuration/panels/tenant-list/test/tenant-instruction-view.test.tsx +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * - * Licensed under the Apache License, Version 2.0 (the "License"). - * You may not use this file except in compliance with the License. - * A copy of the License is located at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * or in the "license" file accompanying this file. This file is distributed - * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either - * express or implied. See the License for the specific language governing - * permissions and limitations under the License. - */ - -import { shallow } from 'enzyme'; -import React from 'react'; -import { TenantInstructionView } from '../tenant-instruction-view'; - -describe('Tenant instruction view', () => { - it('renders', () => { - const component = shallow(); - expect(component).toMatchSnapshot(); - }); -}); diff --git a/public/apps/configuration/panels/tenant-list/test/tenant-list.test.tsx b/public/apps/configuration/panels/tenant-list/test/tenant-list.test.tsx index a00a417d8..e6f5bfbf3 100644 --- a/public/apps/configuration/panels/tenant-list/test/tenant-list.test.tsx +++ b/public/apps/configuration/panels/tenant-list/test/tenant-list.test.tsx @@ -20,7 +20,6 @@ import { EuiInMemoryTable } from '@elastic/eui'; import { useDeleteConfirmState } from '../../../utils/delete-confirm-modal-utils'; import { Tenant } from '../../../types'; import { TenantEditModal } from '../edit-modal'; -import { TenantInstructionView } from '../tenant-instruction-view'; import { getDashboardsInfo } from '../../../../../utils/dashboards-info-utils'; jest.mock('../../../utils/tenant-utils'); @@ -107,33 +106,6 @@ describe('Tenant list', () => { expect(component.find(EuiInMemoryTable).prop('items').length).toBe(0); }); - it('renders when multitenancy is disabled in the opensearch_dashboards.yml', () => { - (getDashboardsInfo as jest.Mock).mockImplementation(() => { - return { - multitenancy_enabled: false, - private_tenant_enabled: true, - default_tenant: '', - }; - }); - const config1 = { - multitenancy: { - enabled: false, - tenants: { - enable_private: true, - }, - }, - }; - const component = shallow( - - ); - expect(component.find(TenantInstructionView).length).toBe(0); - }); - it('fetch data error', (done) => { jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f()); // Hide the error message diff --git a/public/apps/configuration/test/top-nav-menu.test.tsx b/public/apps/configuration/test/top-nav-menu.test.tsx index 2e2872f65..4ea26ebbd 100644 --- a/public/apps/configuration/test/top-nav-menu.test.tsx +++ b/public/apps/configuration/test/top-nav-menu.test.tsx @@ -39,11 +39,17 @@ describe('SecurityPluginTopNavMenu', () => { dataSourceEnabled: true, }, }; + const securityPluginConfigMock = { + multitenancy: { + enabled: false, + }, + }; const wrapper = render(