Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,11 @@ export function AccountNavButton(props: {
const [modal, setModal] = React.useState<React.ReactNode>(null);
const horizontalRule = <EuiHorizontalRule margin="xs" />;
const username = props.username;
const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = React.useState<boolean>(true);
const propsMultiTenancyToggle = props.config.multitenancy.enabled;
const [isMultiTenancyEnabled, setIsMultiTenancyEnabled] = React.useState<boolean>(
propsMultiTenancyToggle || false
);
const shouldDisplaySwitchTenantsPanel = isMultiTenancyEnabled && propsMultiTenancyToggle;

const showTenantSwitchPanel = useCallback(
() =>
Expand All @@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should have default behavior instead of print error into browser console which will notice nothing to customer and not actonable

Expand Down Expand Up @@ -128,7 +134,7 @@ export function AccountNavButton(props: {
>
View roles and identities
</EuiButtonEmpty>
{isMultiTenancyEnabled && (
{shouldDisplaySwitchTenantsPanel && (
<>
{horizontalRule}
<EuiButtonEmpty data-test-subj="switch-tenants" size="xs" onClick={showTenantSwitchPanel}>
Expand Down