Skip to content

Commit

Permalink
Remove tenant tab when disabled via yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Derek Ho <[email protected]>
  • Loading branch information
derek-ho committed May 15, 2024
1 parent 37c2695 commit 6086dea
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 165 deletions.
77 changes: 38 additions & 39 deletions public/apps/configuration/app-router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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,
Expand Down Expand Up @@ -155,21 +151,37 @@ export const LocalCluster = { label: 'Local cluster', id: '' };
export const DataSourceContext = createContext<DataSourceContextType | null>(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<DataSourceOption>(dataSourceFromUrl);

function getTenancyRoutes() {
if (multitenancyEnabled) {
return (
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
);
}
return null;
}

return (
<DataSourceContext.Provider value={{ dataSource, setDataSource }}>
<Router basename={props.params.appBasePath}>
<EuiPage>
{allNavPanelUrls.map((route) => (
{allNavPanelUrls(multitenancyEnabled).map((route) => (
// Create different routes to update the 'selected' nav item .
<Route key={route} path={route} exact>
<EuiPageSideBar>
<NavPanel items={ROUTE_LIST} />
<NavPanel items={getRouteList(multitenancyEnabled)} />
</EuiPageSideBar>
</Route>
))}
Expand Down Expand Up @@ -267,20 +279,7 @@ export function AppRouter(props: AppDependencies) {
return <PermissionList {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenants.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Manage'} {...props} />;
}}
/>
<Route
path={ROUTE_MAP.tenantsConfigureTab.href}
render={() => {
setGlobalBreadcrumbs(ResourceType.tenants);
return <TenantList tabID={'Configure'} {...props} />;
}}
/>
{getTenancyRoutes()}
<Route
path={ROUTE_MAP.getStarted.href}
render={() => {
Expand Down

This file was deleted.

5 changes: 0 additions & 5 deletions public/apps/configuration/panels/tenant-list/tenant-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -129,10 +128,6 @@ export function TenantList(props: TenantListProps) {
));
};

if (!props.config.multitenancy.enabled) {
return <TenantInstructionView />;
}

return (
<>
<SecurityPluginTopNavMenu
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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(
<ManageTab
coreStart={mockCoreStart as any}
depsStart={{} as any}
params={{} as any}
config={config1 as any}
/>
);
expect(component.find(TenantInstructionView).length).toBe(0);
});

it('fetch data error', (done) => {
jest.spyOn(React, 'useEffect').mockImplementationOnce((f) => f());
// Hide the error message
Expand Down
6 changes: 6 additions & 0 deletions public/apps/configuration/test/top-nav-menu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ describe('SecurityPluginTopNavMenu', () => {
dataSourceEnabled: true,
},
};
const securityPluginConfigMock = {
multitenancy: {
enabled: false,
},
};

const wrapper = render(
<SecurityPluginTopNavMenu
coreStart={coreStartMock}
depsStart={securityPluginStartDepsMock}
config={securityPluginConfigMock}
dataSourcePickerReadOnly={false}
dataSourceManagement={dataSourceManagementMock}
selectedDataSource={{}}
Expand Down

0 comments on commit 6086dea

Please sign in to comment.