From 3aaf0124603f285c800b3d494c4aa8cc0a5e2e3c Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Fri, 17 May 2024 15:57:27 -0400 Subject: [PATCH] Fetches mds feature flag dynamically and updates missed components Signed-off-by: Darshit Chanpura --- .../panels/auth-view/auth-view.tsx | 38 +++++++++---------- .../panels/tenant-list/configure_tab1.tsx | 15 ++++++++ .../panels/tenant-list/manage_tab.tsx | 10 +++++ .../panels/tenant-list/tenant-list.tsx | 5 +-- public/plugin.ts | 2 +- public/utils/test/datasource-utils.test.ts | 2 +- 6 files changed, 46 insertions(+), 26 deletions(-) diff --git a/public/apps/configuration/panels/auth-view/auth-view.tsx b/public/apps/configuration/panels/auth-view/auth-view.tsx index d32efcedf..bb01793a5 100644 --- a/public/apps/configuration/panels/auth-view/auth-view.tsx +++ b/public/apps/configuration/panels/auth-view/auth-view.tsx @@ -63,6 +63,9 @@ export function AuthView(props: AppDependencies) { setDataSource={setDataSource} selectedDataSource={dataSource} /> + +

Authentication and authorization

+
{errorFlag ? ( ) : ( @@ -80,32 +83,25 @@ export function AuthView(props: AppDependencies) { setDataSource={setDataSource} selectedDataSource={dataSource} /> + + +

Authentication and authorization

+
+ {!errorFlag && props.config.ui.backend_configurable && ( + + )} +
{errorFlag ? ( - <> - - -

Authentication and authorization

-
-
- - + ) : ( <> - - -

Authentication and authorization

-
- {props.config.ui.backend_configurable && ( - - )} -
- /* @ts-ignore */ + {/* @ts-ignore */} - /* @ts-ignore */ + {/* @ts-ignore */} )} diff --git a/public/apps/configuration/panels/tenant-list/configure_tab1.tsx b/public/apps/configuration/panels/tenant-list/configure_tab1.tsx index 2430ce1ac..1c098c758 100644 --- a/public/apps/configuration/panels/tenant-list/configure_tab1.tsx +++ b/public/apps/configuration/panels/tenant-list/configure_tab1.tsx @@ -50,6 +50,8 @@ import { } from '../../utils/toast-utils'; import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils'; import { LOCAL_CLUSTER_ID } from '../../../../../common'; +import { AccessErrorComponent } from '../../../access-error-component'; +import { LocalCluster } from '../../app-router'; export function ConfigureTab1(props: AppDependencies) { const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = useState(false); @@ -76,6 +78,7 @@ export function ConfigureTab1(props: AppDependencies) { const [toasts, addToast, removeToast] = useToastState(); const [selectedComboBoxOptions, setSelectedComboBoxOptions] = useState(); + const [errorFlag, setErrorFlag] = React.useState(false); const discardChangesFunction = async () => { await setUpdatedConfiguration(originalConfiguration); @@ -195,9 +198,11 @@ export function ConfigureTab1(props: AppDependencies) { const rawTenantData = await fetchTenants(props.coreStart.http, LOCAL_CLUSTER_ID); const processedTenantData = transformTenantData(rawTenantData); setTenantData(processedTenantData); + setErrorFlag(false); } catch (e) { // TODO: switch to better error display. console.error(e); + setErrorFlag(true); } }; fetchData(); @@ -306,6 +311,16 @@ export function ConfigureTab1(props: AppDependencies) { The private tenant is disabled. Select another default tenant. ); + + if (errorFlag) { + return ( + + ); + } + return ( <> diff --git a/public/apps/configuration/panels/tenant-list/manage_tab.tsx b/public/apps/configuration/panels/tenant-list/manage_tab.tsx index 79bcbe908..a35627801 100644 --- a/public/apps/configuration/panels/tenant-list/manage_tab.tsx +++ b/public/apps/configuration/panels/tenant-list/manage_tab.tsx @@ -72,6 +72,7 @@ import { LocalCluster, getBreadcrumbs } from '../../app-router'; import { buildUrl } from '../../utils/url-builder'; import { CrossPageToast } from '../../cross-page-toast'; import { getDashboardsInfo } from '../../../../utils/dashboards-info-utils'; +import { AccessErrorComponent } from '../../../access-error-component'; export function ManageTab(props: AppDependencies) { const setGlobalBreadcrumbs = flow(getBreadcrumbs, props.coreStart.chrome.setBreadcrumbs); @@ -108,6 +109,7 @@ export function ManageTab(props: AppDependencies) { setIsMultiTenancyEnabled(tenancyConfig.multitenancy_enabled); setIsPrivateTenantEnabled(tenancyConfig.private_tenant_enabled); setDashboardsDefaultTenant(tenancyConfig.default_tenant); + setErrorFlag(false); } catch (e) { console.log(e); setErrorFlag(true); @@ -484,6 +486,14 @@ export function ManageTab(props: AppDependencies) { ); }; + if (errorFlag) { + return ( + + ); + } /* eslint-disable */ return ( <> diff --git a/public/apps/configuration/panels/tenant-list/tenant-list.tsx b/public/apps/configuration/panels/tenant-list/tenant-list.tsx index 0b97c6ae1..99c7d02a2 100644 --- a/public/apps/configuration/panels/tenant-list/tenant-list.tsx +++ b/public/apps/configuration/panels/tenant-list/tenant-list.tsx @@ -45,9 +45,8 @@ export function TenantList(props: TenantListProps) { React.useEffect(() => { const fetchData = async () => { try { - await setIsMultiTenancyEnabled( - (await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled - ); + const dashboardsInfo = await getDashboardsInfo(props.coreStart.http); + setIsMultiTenancyEnabled(dashboardsInfo?.multitenancy_enabled || false); } catch (e) { console.log(e); } diff --git a/public/plugin.ts b/public/plugin.ts index bc799768f..75a983ab9 100644 --- a/public/plugin.ts +++ b/public/plugin.ts @@ -87,7 +87,7 @@ export class SecurityPlugin deps: SecurityPluginSetupDependencies ): Promise { const apiPermission = await hasApiPermission(core); - const mdsEnabled = true; + const mdsEnabled = !!deps.dataSource?.dataSourceEnabled; const config = this.initializerContext.config.get(); diff --git a/public/utils/test/datasource-utils.test.ts b/public/utils/test/datasource-utils.test.ts index 5f945155f..33aef7905 100644 --- a/public/utils/test/datasource-utils.test.ts +++ b/public/utils/test/datasource-utils.test.ts @@ -69,7 +69,7 @@ describe('Tests datasource utils', () => { 'http://localhost:5601/app/security-dashboards-plugin?dataSource=%7B%22id%22%3A%22%22%2C%22label%22%3A%22Local+cluster%22%7D#/auth' ); }); - + it('Tests getting the datasource from the url with undefined dataSource', () => { const mockSearchUndefinedDataSource = '?dataSource=undefined'; Object.defineProperty(window, 'location', {