Skip to content

Commit

Permalink
Conditionally change where avatar shows up
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki committed Aug 7, 2024
1 parent 76c176a commit 3e55648
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 7 deletions.
7 changes: 4 additions & 3 deletions public/apps/account/account-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<AccountNavButton
Expand Down
9 changes: 9 additions & 0 deletions public/apps/account/account-nav-button.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

// stylelint-disable-next-line @osd/stylelint/no_modifying_global_selectors
.euiButtonEmpty.accountNavButton {
border: 0;
}
36 changes: 32 additions & 4 deletions public/apps/account/account-nav-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { LogoutButton } from './log-out-button';
import { resolveTenantName } from '../configuration/utils/tenant-utils';
import { getShouldShowTenantPopup, setShouldShowTenantPopup } from '../../utils/storage-utils';
import { getDashboardsInfo } from '../../utils/dashboards-info-utils';
import './account-nav-button.scss';

export function AccountNavButton(props: {
coreStart: CoreStart;
Expand Down Expand Up @@ -73,7 +74,7 @@ export function AccountNavButton(props: {
const fetchData = async () => {
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.
Expand Down Expand Up @@ -167,12 +168,31 @@ export function AccountNavButton(props: {
/>
</div>
);
return (
<EuiHeaderSectionItemButton id="user-icon-btn">

const isPlacedInLeftNav = props.coreStart.uiSettings.get('home:useNewHomePage');

// ToDo: Add aria-label and tooltip when isPlacedInLeftNav is true
const innerElement = isPlacedInLeftNav ? (
<EuiButtonEmpty
size="xs"
flush="both"
className="accountNavButton"
aria-expanded={isPopoverOpen}
aria-haspopup="true"
>
<EuiAvatar name={username} size="s" />
</EuiButtonEmpty>
) : (
<EuiAvatar name={username} size="m" />
);

const popover = (
<>
<EuiPopover
data-test-subj="account-popover"
id="actionsMenu"
button={<EuiAvatar name={username} />}
anchorPosition={isPlacedInLeftNav ? 'rightDown' : undefined}
button={innerElement}
isOpen={isPopoverOpen}
closePopover={() => {
setPopoverOpen(false);
Expand All @@ -185,6 +205,14 @@ export function AccountNavButton(props: {
<EuiContextMenuPanel>{contextMenuPanel}</EuiContextMenuPanel>
</EuiPopover>
{modal}
</>
);

return isPlacedInLeftNav ? (
popover
) : (
<EuiHeaderSectionItemButton id="user-icon-btn" size="l">
{popover}
</EuiHeaderSectionItemButton>
);
}
Expand Down

0 comments on commit 3e55648

Please sign in to comment.