Skip to content

Commit

Permalink
Update header logo selection logic and assets
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <miki@amazon.com>
  • Loading branch information
AMoo-Miki committed Jun 23, 2023
1 parent fe1f1d1 commit 2fb8ea8
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 12 deletions.
8 changes: 7 additions & 1 deletion src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import {
EuiHeader,
EuiHeaderProps,
EuiHeaderSection,
EuiHeaderSectionItem,
EuiHeaderSectionItemButton,
Expand Down Expand Up @@ -116,14 +117,16 @@ export function Header({
const className = classnames('hide-for-sharing', 'headerGlobalNav');
const { useExpandedHeader = true, darkMode } = branding;

const headerTheme: EuiHeaderProps['theme'] = 'dark';

return (
<>
<header className={className} data-test-subj="headerGlobalNav">
<div id="globalHeaderBars">
{useExpandedHeader && (
<EuiHeader
className="expandedHeader"
theme="dark"
theme={headerTheme}
position="fixed"
sections={[
{
Expand All @@ -134,6 +137,9 @@ export function Header({
navLinks$={observables.navLinks$}
navigateToApp={application.navigateToApp}
branding={branding}
basePath={basePath}
/* This theme should match the theme of EuiHeader */
theme={headerTheme}
/>,
],
borders: 'none',
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/chrome/ui/header/header_logo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import React from 'react';
import { BehaviorSubject } from 'rxjs';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { HeaderLogo, DEFAULT_DARK_LOGO, DEFAULT_LOGO } from './header_logo';
import { BasePath } from '../../../http/base_path';

const mockProps = () => ({
href: '/',
basePath: new BasePath('/base'),
navLinks$: new BehaviorSubject([]),
forceNavigation$: new BehaviorSubject(false),
navigateToApp: jest.fn(),
Expand Down
37 changes: 26 additions & 11 deletions src/core/public/chrome/ui/header/header_logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@
*/

import './header_logo.scss';
import { EuiHeaderProps } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import { ChromeNavLink } from '../..';
import { ChromeBranding } from '../../chrome_service';
import { HttpStart } from '../../../http';

function findClosestAnchor(element: HTMLElement): HTMLAnchorElement | void {
let current = element;
Expand Down Expand Up @@ -96,32 +98,45 @@ function onClick(
}
}

export const DEFAULT_DARK_LOGO = 'opensearch_logo_dark_mode.svg';
export const DEFAULT_LOGO = 'opensearch_logo_default_mode.svg';
export const DEFAULT_LOGO = 'plugins/home/assets/logos/opensearch_dashboards.svg';
export const DEFAULT_DARK_LOGO = 'plugins/home/assets/logos/opensearch_dashboards_darkmode.svg';

interface Props {
href: string;
navLinks$: Observable<ChromeNavLink[]>;
forceNavigation$: Observable<boolean>;
navigateToApp: (appId: string) => void;
branding: ChromeBranding;
basePath: HttpStart['basePath'];
// What background is the logo appearing on; this is unrelated to theme:darkMode
theme?: EuiHeaderProps['theme'];
}

export function HeaderLogo({ href, navigateToApp, branding, ...observables }: Props) {
export function HeaderLogo({
href,
navigateToApp,
branding,
basePath,
theme = 'default',
...observables
}: Props) {
const forceNavigation = useObservable(observables.forceNavigation$, false);
const navLinks = useObservable(observables.navLinks$, []);
const {
darkMode,
assetFolderUrl = '',
logo = {},
logo: { defaultUrl: customLogoUrl, darkModeUrl: customDarkLogoUrl } = {},
applicationTitle = 'opensearch dashboards',
} = branding;
const { defaultUrl: logoUrl, darkModeUrl: darkLogoUrl } = logo;

const customLogo = darkMode ? darkLogoUrl ?? logoUrl : logoUrl;
const defaultLogo = darkMode ? DEFAULT_DARK_LOGO : DEFAULT_LOGO;
// Attempt to find a suitable custom branded logo before falling back on OSD's
let logoSrc = theme === 'dark' && customDarkLogoUrl ? customDarkLogoUrl : customLogoUrl;
let testSubj = 'customLogo';

// If no custom branded logo was set, use OSD's
if (!logoSrc) {
logoSrc = `${basePath.serverBasePath}/${theme === 'dark' ? DEFAULT_DARK_LOGO : DEFAULT_LOGO}`;
testSubj = 'defaultLogo';
}

const logoSrc = customLogo ? customLogo : `${assetFolderUrl}/${defaultLogo}`;
const testSubj = customLogo ? 'customLogo' : 'defaultLogo';
const alt = `${applicationTitle} logo`;

return (
Expand Down
13 changes: 13 additions & 0 deletions src/plugins/home/public/assets/logos/opensearch_dashboards.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 2fb8ea8

Please sign in to comment.