From cec45ce4794fad172d64c43e8d192b84e52e4c78 Mon Sep 17 00:00:00 2001 From: Darshit Chanpura Date: Wed, 3 May 2023 18:13:42 -0400 Subject: [PATCH] Fixes mutlti-tenancy popup toggle due to hard-coded default state Signed-off-by: Darshit Chanpura --- public/apps/account/account-nav-button.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/public/apps/account/account-nav-button.tsx b/public/apps/account/account-nav-button.tsx index 6da1aec11..c972f72ef 100644 --- a/public/apps/account/account-nav-button.tsx +++ b/public/apps/account/account-nav-button.tsx @@ -49,7 +49,11 @@ export function AccountNavButton(props: { const [modal, setModal] = React.useState(null); const horizontalRule = ; const username = props.username; - const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = React.useState(true); + const propsMultiTenancyToggle = props.config.multitenancy.enabled; + const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = React.useState( + propsMultiTenancyToggle || false + ); + const shouldDisplaySwitchTenantsPanel = isMultiTenancyEnabled && propsMultiTenancyToggle; const showTenantSwitchPanel = useCallback( () => @@ -72,9 +76,11 @@ export function AccountNavButton(props: { React.useEffect(() => { const fetchData = async () => { try { - setIsMultiTenancyEnabled( - (await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled + // defaults to true if for some reason the multitenancy_enabled flag is undefined. This should ideally never happen. + const { multitenancy_enabled: isEnabled = true } = await getDashboardsInfo( + props.coreStart.http ); + setIsMultiTenancyEnabled(isEnabled); } catch (e) { // TODO: switch to better error display. console.error(e); @@ -128,7 +134,7 @@ export function AccountNavButton(props: { > View roles and identities - {isMultiTenancyEnabled && ( + {shouldDisplaySwitchTenantsPanel && ( <> {horizontalRule}