Skip to content

Commit

Permalink
Welcome page title and logo configurable
Browse files Browse the repository at this point in the history
Add two new configs branding.smallLogoUrl and branding.title
in the yaml file for making the welcome page logo and title
 configurable. If URL is invalid, the default branding will be shown.

Signed-off-by: Abby Hu <[email protected]>
  • Loading branch information
abbyhu2000 committed Aug 26, 2021
1 parent 43dd663 commit 9b4a085
Show file tree
Hide file tree
Showing 31 changed files with 539 additions and 98 deletions.
9 changes: 8 additions & 1 deletion config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,13 @@
# ]
#vis_type_timeline.graphiteBlockedIPs: []

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

# smaller version customized logo URL
# opensearchDashboards.branding.smallLogoUrl: ""

# custom application title
# opensearchDashboards.branding.title: ""


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
Expand Up @@ -12,7 +12,12 @@ import { CustomLogo } from './opensearch_dashboards_custom_logo';

describe('Custom Logo', () => {
it('Take in a normal URL string', () => {
const branding = { logoUrl: '/', className: '' };
const branding = { logoUrl: '/custom' };
const component = mountWithIntl(<CustomLogo {...branding} />);
expect(component).toMatchSnapshot();
});
it('Take in a invalid URL string', () => {
const branding = { logoUrl: '' };
const component = mountWithIntl(<CustomLogo {...branding} />);
expect(component).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,13 @@ export interface CustomLogoType {
}

export const CustomLogo = ({ ...branding }: CustomLogoType) => {
const defaultUrl =
'https://opensearch.org/assets/brand/SVG/Logo/opensearch_dashboards_logo_darkmode.svg';
return (
<img
data-test-subj="customLogo"
data-test-image-url={branding.logoUrl}
src={branding.logoUrl}
data-test-image-url={branding.logoUrl === '' ? defaultUrl : branding.logoUrl}
src={branding.logoUrl === '' ? defaultUrl : branding.logoUrl}
alt="logo"
loading="lazy"
className="logoImage"
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/ui/header/header.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function mockProps() {
isLocked$: new BehaviorSubject(false),
loadingCount$: new BehaviorSubject(0),
onIsLockedUpdate: () => {},
branding: { logoUrl: '/' },
branding: { logoUrl: '/', smallLogoUrl: '/', title: 'OpenSearch Dashboards' },
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/core/public/core_system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ export class CoreSystem {
docLinks,
http,
i18n,
injectedMetadata: pick(injectedMetadata, ['getInjectedVar']),
injectedMetadata: pick(injectedMetadata, ['getInjectedVar', 'getBranding']),
notifications,
overlays,
savedObjects,
Expand Down
10 changes: 10 additions & 0 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,11 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
logoUrl: string;
smallLogoUrl: string;
title: string;
};
};
/** {@link StartServicesAccessor} */
getStartServices: StartServicesAccessor<TPluginsStart, TStart>;
Expand Down Expand Up @@ -291,6 +296,11 @@ export interface CoreStart {
* */
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
logoUrl: string;
smallLogoUrl: string;
title: string;
};
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,11 @@ describe('setup.getBranding()', () => {
it('returns injectedMetadata.branding', () => {
const injectedMetadata = new InjectedMetadataService({
injectedMetadata: {
branding: { logoUrl: '/' },
branding: { logoUrl: '/', smallLogoUrl: '/', title: 'title' },
},
} as any);

const logoURL = injectedMetadata.setup().getBranding();
expect(logoURL).toEqual({ logoUrl: '/' });
const branding = injectedMetadata.setup().getBranding();
expect(branding).toEqual({ logoUrl: '/', smallLogoUrl: '/', title: 'title' });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export interface InjectedMetadataParams {
};
branding: {
logoUrl: string;
smallLogoUrl: string;
title: string;
};
};
}
Expand Down Expand Up @@ -185,6 +187,8 @@ export interface InjectedMetadataSetup {
};
getBranding: () => {
logoUrl: string;
smallLogoUrl: string;
title: string;
};
}

Expand Down
1 change: 1 addition & 0 deletions src/core/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ function createCoreStartMock({ basePath = '' } = {}) {
savedObjects: savedObjectsServiceMock.createStartContract(),
injectedMetadata: {
getInjectedVar: injectedMetadataServiceMock.createStartContract().getInjectedVar,
getBranding: injectedMetadataServiceMock.createStartContract().getBranding,
},
fatalErrors: fatalErrorsServiceMock.createStartContract(),
};
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/plugins/plugin_context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export function createPluginSetupContext<
uiSettings: deps.uiSettings,
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
getBranding: deps.injectedMetadata.getBranding,
},
getStartServices: () => plugin.startDependencies,
};
Expand Down Expand Up @@ -166,6 +167,7 @@ export function createPluginStartContext<
savedObjects: deps.savedObjects,
injectedMetadata: {
getInjectedVar: deps.injectedMetadata.getInjectedVar,
getBranding: deps.injectedMetadata.getBranding,
},
fatalErrors: deps.fatalErrors,
};
Expand Down
4 changes: 2 additions & 2 deletions src/core/public/plugins/plugins_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ describe('PluginsService', () => {
...mockSetupDeps,
application: expect.any(Object),
getStartServices: expect.any(Function),
injectedMetadata: pick(mockSetupDeps.injectedMetadata, 'getInjectedVar'),
injectedMetadata: pick(mockSetupDeps.injectedMetadata, 'getInjectedVar', 'getBranding'),
};
mockStartDeps = {
application: applicationServiceMock.createInternalStartContract(),
Expand All @@ -132,7 +132,7 @@ describe('PluginsService', () => {
...mockStartDeps,
application: expect.any(Object),
chrome: omit(mockStartDeps.chrome, 'getComponent'),
injectedMetadata: pick(mockStartDeps.injectedMetadata, 'getInjectedVar'),
injectedMetadata: pick(mockStartDeps.injectedMetadata, 'getInjectedVar', 'getBranding'),
};

// Reset these for each test.
Expand Down
7 changes: 5 additions & 2 deletions src/core/server/opensearch_dashboards_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ export const config = {
autocompleteTimeout: schema.duration({ defaultValue: 1000 }),
branding: schema.object({
logoUrl: schema.string({
defaultValue:
'https://opensearch.org/assets/brand/SVG/Logo/opensearch_dashboards_logo_darkmode.svg',
defaultValue: '/',
}),
smallLogoUrl: schema.string({
defaultValue: '/',
}),
title: schema.string({ defaultValue: 'OpenSearch Dashboards' }),
}),
}),
deprecations,
Expand Down

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

Loading

0 comments on commit 9b4a085

Please sign in to comment.