Skip to content

Commit

Permalink
Make home page primary dashboard card logo and title configurable
Browse files Browse the repository at this point in the history
Home page dashboard card logo and title can be customized by config
mark.defaultUrl and mark.darkModeUrl. Unit test and functional test
are also written.

Signed-off-by: Abby Hu <[email protected]>
  • Loading branch information
abbyhu2000 committed Sep 24, 2021
1 parent 51f4c2d commit 990502e
Show file tree
Hide file tree
Showing 28 changed files with 721 additions and 145 deletions.
2 changes: 1 addition & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,4 @@
# defaultUrl: ""
# darkModeUrl: ""
# faviconUrl: ""
# applicationTitle: ""
# applicationTitle: ""
4 changes: 4 additions & 0 deletions src/core/public/chrome/chrome_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import { ChromeNavLinks, NavLinksService, ChromeNavLink } from './nav_links';
import { ChromeRecentlyAccessed, RecentlyAccessedService } from './recently_accessed';
import { Header } from './ui';
import { ChromeHelpExtensionMenuLink } from './ui/header/header_help_menu';
import { Branding } from '../';
export { ChromeNavControls, ChromeRecentlyAccessed, ChromeDocTitle };

const IS_LOCKED_KEY = 'core.chrome.isLocked';
Expand All @@ -71,6 +72,9 @@ export interface ChromeBrand {
/** @public */
export type ChromeBreadcrumb = EuiBreadcrumb;

/** @public */
export type HeaderLogoBranding = Branding;

/** @public */
export interface ChromeHelpExtension {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,40 +33,23 @@
import React from 'react';
import '../header_logo.scss';
import { OpenSearchDashboardsLogoDarkMode } from './opensearch_dashboards_logo_darkmode';

/**
* @param {object} logo - full logo on main screen: defaultUrl will be used in default mode; darkModeUrl will be used in dark mode
* @param {object} mark - thumbnail logo: defaultUrl will be used in default mode; darkModeUrl will be used in dark mode
* @param {string} applicationTitle - custom title for the application
*/
export interface CustomLogoType {
darkMode: boolean;
logo: {
defaultUrl?: string;
darkModeUrl?: string;
};
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
applicationTitle?: string;
}
import { HeaderLogoBranding } from '../../../chrome_service';

/**
* Use branding configurations to render the header logo on the nab bar.
*
* @param {CustomLogoType} - branding object consist of logo, mark and title
* @param {HeaderLogoBranding} - branding object consist of logo, mark and title
* @returns A image component which is going to be rendered on the main page header bar.
* If logo default is valid, the full logo by logo default config will be rendered;
* if not, the logo icon by mark default config will be rendered; if both are not found,
* the default opensearch logo will be rendered.
*/
export const CustomLogo = ({ ...branding }: CustomLogoType) => {
export const CustomLogo = ({ ...branding }: HeaderLogoBranding) => {
const darkMode = branding.darkMode;
const logoDefault = branding.logo.defaultUrl;
const logoDarkMode = branding.logo.darkModeUrl;
const markDefault = branding.mark.defaultUrl;
const markDarkMode = branding.mark.darkModeUrl;
const logoDefault = branding.logo?.defaultUrl;
const logoDarkMode = branding.logo?.darkModeUrl;
const markDefault = branding.mark?.defaultUrl;
const markDarkMode = branding.mark?.darkModeUrl;
const applicationTitle = branding.applicationTitle;

/**
Expand Down
14 changes: 2 additions & 12 deletions src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { HeaderHelpMenu } from './header_help_menu';
import { HeaderLogo } from './header_logo';
import { HeaderNavControls } from './header_nav_controls';
import { HeaderActionMenu } from './header_action_menu';
import { HeaderLogoBranding } from '../../chrome_service';

export interface HeaderProps {
opensearchDashboardsVersion: string;
Expand All @@ -87,18 +88,7 @@ export interface HeaderProps {
isLocked$: Observable<boolean>;
loadingCount$: ReturnType<HttpStart['getLoadingCount$']>;
onIsLockedUpdate: OnIsLockedUpdate;
branding: {
darkMode: boolean;
logo: {
defaultUrl?: string;
darkModeUrl?: string;
};
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
applicationTitle?: string;
};
branding: HeaderLogoBranding;
}

export function Header({
Expand Down
5 changes: 3 additions & 2 deletions src/core/public/chrome/ui/header/header_logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ import useObservable from 'react-use/lib/useObservable';
import { Observable } from 'rxjs';
import Url from 'url';
import { ChromeNavLink } from '../..';
import { CustomLogo, CustomLogoType } from './branding/opensearch_dashboards_custom_logo';
import { CustomLogo } from './branding/opensearch_dashboards_custom_logo';
import { HeaderLogoBranding } from '../../chrome_service';
import './header_logo.scss';

function findClosestAnchor(element: HTMLElement): HTMLAnchorElement | void {
Expand Down Expand Up @@ -104,7 +105,7 @@ interface Props {
navLinks$: Observable<ChromeNavLink[]>;
forceNavigation$: Observable<boolean>;
navigateToApp: (appId: string) => void;
branding: CustomLogoType;
branding: HeaderLogoBranding;
}

export function HeaderLogo({ href, navigateToApp, branding, ...observables }: Props) {
Expand Down
19 changes: 4 additions & 15 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import {
HandlerContextType,
HandlerParameters,
} from './context';
import { Branding } from '../types';

export { PackageInfo, EnvironmentMode } from '../server/types';
/** @interal */
Expand Down Expand Up @@ -236,13 +237,7 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
title?: string;
};
getBranding: () => Branding;
};
/** {@link StartServicesAccessor} */
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
Expand Down Expand Up @@ -298,14 +293,7 @@ export interface CoreStart {
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
darkMode: boolean;
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
applicationTitle?: string;
};
getBranding: () => Branding;
};
}

Expand Down Expand Up @@ -352,6 +340,7 @@ export {
IUiSettingsClient,
UiSettingsState,
NavType,
Branding,
};

export { __osdBootstrap__ } from './osd_bootstrap';
37 changes: 3 additions & 34 deletions src/core/public/injected_metadata/injected_metadata_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import {
UserProvidedValues,
} from '../../server/types';
import { AppCategory } from '../';
import { Branding } from '../';

export interface InjectedPluginMetadata {
id: PluginName;
Expand Down Expand Up @@ -76,23 +77,7 @@ export interface InjectedMetadataParams {
user?: Record<string, UserProvidedValues>;
};
};
branding: {
darkMode: boolean;
logo: {
defaultUrl?: string;
darkModeUrl?: string;
};
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
loadingLogo: {
defaultUrl?: string;
darkModeUrl?: string;
};
faviconUrl?: string;
applicationTitle?: string;
};
branding: Branding;
};
}

Expand Down Expand Up @@ -197,23 +182,7 @@ export interface InjectedMetadataSetup {
getInjectedVars: () => {
[key: string]: unknown;
};
getBranding: () => {
darkMode: boolean;
logo: {
defaultUrl?: string;
darkModeUrl?: string;
};
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
loadingLogo: {
defaultUrl?: string;
darkModeUrl?: string;
};
faviconUrl?: string;
applicationTitle?: string;
};
getBranding: () => Branding;
}

/** @internal */
Expand Down
19 changes: 2 additions & 17 deletions src/core/server/rendering/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import { i18n } from '@osd/i18n';

import { Branding } from 'src/core/types';
import { EnvironmentMode, PackageInfo } from '../config';
import { ICspConfig } from '../csp';
import { InternalHttpServiceSetup, OpenSearchDashboardsRequest, LegacyRequest } from '../http';
Expand Down Expand Up @@ -74,23 +75,7 @@ export interface RenderingMetadata {
user: Record<string, UserProvidedValues<any>>;
};
};
branding: {
darkMode: boolean;
logo: {
defaultUrl?: string;
darkModeUrl?: string;
};
mark: {
defaultUrl?: string;
darkModeUrl?: string;
};
loadingLogo: {
defaultUrl?: string;
darkModeUrl?: string;
};
faviconUrl?: string;
applicationTitle?: string;
};
branding: Branding;
};
}

Expand Down
10 changes: 5 additions & 5 deletions src/core/server/rendering/views/template.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ export const Template: FunctionComponent<Props> = ({
</svg>
);

const loadingLogoDefault = injectedMetadata.branding.loadingLogo.defaultUrl;
const loadingLogoDarkMode = injectedMetadata.branding.loadingLogo.darkModeUrl;
const markDefault = injectedMetadata.branding.mark.defaultUrl;
const markDarkMode = injectedMetadata.branding.mark.darkModeUrl;
const loadingLogoDefault = injectedMetadata.branding.loadingLogo?.defaultUrl;
const loadingLogoDarkMode = injectedMetadata.branding.loadingLogo?.darkModeUrl;
const markDefault = injectedMetadata.branding.mark?.defaultUrl;
const markDarkMode = injectedMetadata.branding.mark?.darkModeUrl;
const favicon = injectedMetadata.branding.faviconUrl;
const applicationTitle = injectedMetadata.branding.applicationTitle;

Expand Down Expand Up @@ -149,7 +149,7 @@ export const Template: FunctionComponent<Props> = ({
* @returns a loading bar component or no loading bar component
*/
const renderBrandingEnabledOrDisabledLoadingBar = () => {
if (customLoadingLogo() && !injectedMetadata.branding.loadingLogo.defaultUrl) {
if (customLoadingLogo() && !injectedMetadata.branding.loadingLogo?.defaultUrl) {
return <div className="osdProgress" />;
}
};
Expand Down
1 change: 1 addition & 0 deletions src/core/server/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ export * from './saved_objects/types';
export * from './ui_settings/types';
export * from './legacy/types';
export type { EnvironmentMode, PackageInfo } from '@osd/config';
export { Branding } from '../../core/types';
54 changes: 54 additions & 0 deletions src/core/types/custom_branding.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.
*/

/**
* A type definition for custom branding configurations
* @public
*/

export interface Branding {
darkMode?: boolean;
mark?: {
defaultUrl?: string;
darkModeUrl?: string;
};
logo?: {
defaultUrl?: string;
darkModeUrl?: string;
};
loadingLogo?: {
defaultUrl?: string;
darkModeUrl?: string;
};
faviconUrl?: string;
applicationTitle?: string;
}
1 change: 1 addition & 0 deletions src/core/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,4 @@ export * from './app_category';
export * from './ui_settings';
export * from './saved_objects';
export * from './serializable';
export * from './custom_branding';

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
Expand Up @@ -135,3 +135,13 @@
background-size: $euiSizeL * 2;
}
}

.homSolutionPanel__customIconContainer {
height: 50px;
padding: 5px 5px 5px 5px;
}

.homSolutionPanel__customIcon {
height: 100%;
max-width: 100%;
}
1 change: 1 addition & 0 deletions src/plugins/home/public/application/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ export class Home extends Component {
addBasePath={addBasePath}
solutions={solutions}
directories={directories}
branding={getServices().injectedMetadata.getBranding()}
/>
) : null}

Expand Down

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

Loading

0 comments on commit 990502e

Please sign in to comment.