Skip to content

Commit

Permalink
Make top left logo on the main screen configurable
Browse files Browse the repository at this point in the history
Add a new config opensearchDashboards.branding.logoUrl in yaml file
for making top left corner logo on the main screen configurable. If
URL is invalid, the default OpenSearch logo will be shown.

Signed-off-by: Abby Hu <[email protected]>
  • Loading branch information
abbyhu2000 authored and kavilla committed Oct 15, 2021
1 parent 38ace12 commit bdb10c7
Show file tree
Hide file tree
Showing 24 changed files with 445 additions and 34 deletions.
4 changes: 4 additions & 0 deletions config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,7 @@
# 'ff00::/8',
# ]
#vis_type_timeline.graphiteBlockedIPs: []

# user input URL for customized logo
# opensearchDashboards.branding.logoUrl: ""

1 change: 1 addition & 0 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ export class ChromeService {
navControlsRight$={navControls.getRight$()}
onIsLockedUpdate={setIsNavDrawerLocked}
isLocked$={getIsNavDrawerLocked$}
branding={injectedMetadata.getBranding()}
/>
),

Expand Down
43 changes: 19 additions & 24 deletions src/core/public/chrome/ui/header/__snapshots__/header.test.tsx.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

import React from 'react';
import { mountWithIntl } from 'test_utils/enzyme_helpers';
import { CustomLogo } from './opensearch_dashboards_custom_logo';

describe('Custom Logo', () => {
it('Take in a normal URL string', () => {
const branding = { logoUrl: '/', className: '' };
const component = mountWithIntl(<CustomLogo {...branding} />);
expect(component).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/*
* Modifications Copyright OpenSearch Contributors. See
* GitHub history for details.
*/

import React from 'react';
import '../header_logo.scss';

export interface CustomLogoType {
logoUrl: string;
}

export const CustomLogo = ({ ...branding }: CustomLogoType) => {
return (
<img
data-test-subj="customLogo"
data-test-image-url={branding.logoUrl}
src={branding.logoUrl}
alt="logo"
loading="lazy"
className="logoImage"
/>
);
};
1 change: 1 addition & 0 deletions src/core/public/chrome/ui/header/header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function mockProps() {
isLocked$: new BehaviorSubject(false),
loadingCount$: new BehaviorSubject(0),
onIsLockedUpdate: () => {},
branding: { logoUrl: '/' },
};
}

Expand Down
3 changes: 3 additions & 0 deletions src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export interface HeaderProps {
isLocked$: Observable<boolean>;
loadingCount$: ReturnType<HttpStart['getLoadingCount$']>;
onIsLockedUpdate: OnIsLockedUpdate;
branding: { logoUrl: string };
}

export function Header({
Expand All @@ -96,6 +97,7 @@ export function Header({
basePath,
onIsLockedUpdate,
homeHref,
branding,
...observables
}: HeaderProps) {
const isVisible = useObservable(observables.isVisible$, false);
Expand Down Expand Up @@ -125,6 +127,7 @@ export function Header({
forceNavigation$={observables.forceAppSwitcherNavigation$}
navLinks$={observables.navLinks$}
navigateToApp={application.navigateToApp}
logoUrl={branding.logoUrl}
/>,
<LoadingIndicator loadingCount$={observables.loadingCount$} />,
],
Expand Down
9 changes: 9 additions & 0 deletions src/core/public/chrome/ui/header/header_logo.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.logoContainer {
height: 30px;
padding: 3px 3px 3px 10px;
}

.logoImage{
height: 100%;
max-width: 100%;
}
18 changes: 12 additions & 6 deletions src/core/public/chrome/ui/header/header_logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@
* GitHub history for details.
*/

import { EuiHeaderLogo } from '@elastic/eui';
import { i18n } from '@osd/i18n';
import React from 'react';
import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import Url from 'url';
import { ChromeNavLink } from '../..';
import { OpenSearchDashboardsLogoDarkMode } from './branding/opensearch_dashboards_logo_darkmode';
import { CustomLogo, CustomLogoType } from './branding/opensearch_dashboards_custom_logo';
import './header_logo.scss';

function findClosestAnchor(element: HTMLElement): HTMLAnchorElement | void {
let current = element;
Expand Down Expand Up @@ -104,21 +104,27 @@ interface Props {
navLinks$: Observable<ChromeNavLink[]>;
forceNavigation$: Observable<boolean>;
navigateToApp: (appId: string) => void;
logoUrl: string;
}

export function HeaderLogo({ href, navigateToApp, ...observables }: Props) {
export function HeaderLogo({ href, navigateToApp, logoUrl, ...observables }: Props) {
const forceNavigation = useObservable(observables.forceNavigation$, false);
const navLinks = useObservable(observables.navLinks$, []);
const branding: CustomLogoType = {
logoUrl,
};

return (
<EuiHeaderLogo
<a
data-test-subj="logo"
iconType={OpenSearchDashboardsLogoDarkMode}
onClick={(e) => onClick(e, forceNavigation, navLinks, navigateToApp)}
href={href}
aria-label={i18n.translate('core.ui.chrome.headerGlobalNav.goHomePageIconAriaLabel', {
defaultMessage: 'Go to home page',
})}
/>
className="logoContainer"
>
<CustomLogo {...branding} />
</a>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const createSetupContractMock = () => {
getInjectedVar: jest.fn(),
getInjectedVars: jest.fn(),
getOpenSearchDashboardsBuildNumber: jest.fn(),
getBranding: jest.fn(),
};
setupContract.getCspConfig.mockReturnValue({ warnLegacyBrowsers: true });
setupContract.getOpenSearchDashboardsVersion.mockReturnValue('opensearchDashboardsVersion');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,3 +229,16 @@ describe('setup.getInjectedVars()', () => {
);
});
});

describe('setup.getBranding()', () => {
it('returns injectedMetadata.branding', () => {
const injectedMetadata = new InjectedMetadataService({
injectedMetadata: {
branding: { logoUrl: '/' },
},
} as any);

const logoURL = injectedMetadata.setup().getBranding();
expect(logoURL).toEqual({ logoUrl: '/' });
});
});
Loading

0 comments on commit bdb10c7

Please sign in to comment.