diff --git a/public/apps/account/account-app.tsx b/public/apps/account/account-app.tsx index 879eb5a9..0f973a1b 100644 --- a/public/apps/account/account-app.tsx +++ b/public/apps/account/account-app.tsx @@ -107,9 +107,10 @@ export async function setupTopNavButton(coreStart: CoreStart, config: ClientConf setShouldShowTenantPopup(shouldShowTenantPopup); - coreStart.chrome.navControls.registerRight({ - // Pin to rightmost, since newsfeed plugin is using 1000, here needs a number > 1000 - order: 2000, + const isPlacedInLeftNav = coreStart.uiSettings.get('home:useNewHomePage'); + + coreStart.chrome.navControls[isPlacedInLeftNav ? 'registerLeftBottom' : 'registerRight']({ + order: isPlacedInLeftNav ? 10000 : 2000, mount: (element: HTMLElement) => { ReactDOM.render( { try { setIsMultiTenancyEnabled( - (await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled + Boolean((await getDashboardsInfo(props.coreStart.http)).multitenancy_enabled) ); } catch (e) { // TODO: switch to better error display. @@ -167,12 +168,31 @@ export function AccountNavButton(props: { /> ); - return ( - + + const isPlacedInLeftNav = props.coreStart.uiSettings.get('home:useNewHomePage'); + + // ToDo: Add aria-label and tooltip when isPlacedInLeftNav is true + const innerElement = isPlacedInLeftNav ? ( + + + + ) : ( + + ); + + const popover = ( + <> } + anchorPosition={isPlacedInLeftNav ? 'rightDown' : undefined} + button={innerElement} isOpen={isPopoverOpen} closePopover={() => { setPopoverOpen(false); @@ -185,6 +205,14 @@ export function AccountNavButton(props: { {contextMenuPanel} {modal} + + ); + + return isPlacedInLeftNav ? ( + popover + ) : ( + + {popover} ); } diff --git a/public/apps/account/test/__snapshots__/account-nav-button.test.tsx.snap b/public/apps/account/test/__snapshots__/account-nav-button.test.tsx.snap index 39b9e332..41ec95fb 100644 --- a/public/apps/account/test/__snapshots__/account-nav-button.test.tsx.snap +++ b/public/apps/account/test/__snapshots__/account-nav-button.test.tsx.snap @@ -3,12 +3,14 @@ exports[`Account navigation button renders 1`] = ` } closePopover={[Function]} @@ -111,7 +113,34 @@ exports[`Account navigation button renders 1`] = ` margin="xs" /> } - http={1} + http={ + Object { + "addLoadingCountSource": [MockFunction], + "anonymousPaths": Object { + "isAnonymous": [MockFunction], + "register": [MockFunction], + }, + "basePath": BasePath { + "basePath": "", + "clientBasePath": "", + "get": [Function], + "getBasePath": [Function], + "prepend": [Function], + "remove": [Function], + "serverBasePath": "", + }, + "delete": [MockFunction], + "fetch": [MockFunction], + "get": [MockFunction], + "getLoadingCount$": [MockFunction], + "head": [MockFunction], + "intercept": [MockFunction], + "options": [MockFunction], + "patch": [MockFunction], + "post": [MockFunction], + "put": [MockFunction], + } + } /> diff --git a/public/apps/account/test/account-app.test.tsx b/public/apps/account/test/account-app.test.tsx index 3c7e1a74..ef0b4469 100644 --- a/public/apps/account/test/account-app.test.tsx +++ b/public/apps/account/test/account-app.test.tsx @@ -19,6 +19,8 @@ import { fetchAccountInfoSafe } from '../utils'; import { fetchCurrentAuthType } from '../../../utils/logout-utils'; import { fetchCurrentTenant } from '../../configuration/utils/tenant-utils'; import { getDashboardsInfoSafe } from '../../../utils/dashboards-info-utils'; +import { CoreStart } from 'opensearch-dashboards/public'; +import { coreMock } from '../../../../../../src/core/public/mocks'; jest.mock('../../../utils/storage-utils', () => ({ getShouldShowTenantPopup: jest.fn(), @@ -44,13 +46,7 @@ jest.mock('../../configuration/utils/tenant-utils', () => ({ })); describe('Account app', () => { - const mockCoreStart = { - chrome: { - navControls: { - registerRight: jest.fn(), - }, - }, - }; + const mockCoreStart: CoreStart = coreMock.createStart(); const mockConfig = { multitenancy: { diff --git a/public/apps/account/test/account-nav-button.test.tsx b/public/apps/account/test/account-nav-button.test.tsx index cdc6a00a..3e3821c8 100644 --- a/public/apps/account/test/account-nav-button.test.tsx +++ b/public/apps/account/test/account-nav-button.test.tsx @@ -19,6 +19,8 @@ import { AccountNavButton, reloadAfterTenantSwitch } from '../account-nav-button import { getShouldShowTenantPopup } from '../../../utils/storage-utils'; import { getDashboardsInfo } from '../../../utils/dashboards-info-utils'; import { render, fireEvent } from '@testing-library/react'; +import { coreMock } from '../../../../../../src/core/public/mocks'; +import { CoreStart } from 'opensearch-dashboards/public'; jest.mock('../../../utils/storage-utils', () => ({ getShouldShowTenantPopup: jest.fn(), @@ -38,9 +40,7 @@ const mockDashboardsInfo = { }; describe('Account navigation button', () => { - const mockCoreStart = { - http: 1, - }; + const mockCoreStart: CoreStart = coreMock.createStart(); const config = { multitenancy: { @@ -66,6 +66,7 @@ describe('Account navigation button', () => { (getDashboardsInfo as jest.Mock).mockImplementation(() => { return mockDashboardsInfo; }); + component = shallow( { }); describe('Account navigation button, multitenancy disabled', () => { - const mockCoreStart = { - http: 1, - }; + const mockCoreStart: CoreStart = coreMock.createStart(); const config = { multitenancy: { @@ -178,9 +177,11 @@ describe('Account navigation button, multitenancy disabled', () => { }); describe('Shows tenant info when multitenancy enabled, and hides it if disabled', () => { + const mockCoreStart: CoreStart = coreMock.createStart(); + test('Renders "switch-tenants" and "tenant-name" when multi-tenancy is enabled', () => { const props = { - coreStart: {}, + coreStart: mockCoreStart, isInternalUser: true, username: 'example_user', tenant: 'example_tenant', @@ -213,7 +214,7 @@ describe('Shows tenant info when multitenancy enabled, and hides it if disabled' test('Does not render "switch-tenants" and "tenant-name" when multi-tenancy is disabled', () => { const props = { - coreStart: {}, + coreStart: mockCoreStart, isInternalUser: true, username: 'example_user', tenant: 'example_tenant',