Skip to content

Commit

Permalink
Use logical equivalent for undefined, jsdoc params
Browse files Browse the repository at this point in the history
Signed-off-by: Abby Hu <[email protected]>
  • Loading branch information
abbyhu2000 committed Aug 29, 2021
1 parent c56d3ff commit 913e6d8
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 48 deletions.
4 changes: 2 additions & 2 deletions config/opensearch_dashboards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,10 @@
#vis_type_timeline.graphiteBlockedIPs: []

# full version customized logo URL
# opensearchDashboards.branding.logoUrl: ""
opensearchDashboards.branding.logoUrl: "https://i.ibb.co/WHHLG2W/bear"

# smaller version customized logo URL
# opensearchDashboards.branding.smallLogoUrl: ""
opensearchDashboards.branding.smallLogoUrl: "https://i.ibb.co/WHHLG2W/bear.png"

# custom application title
# opensearchDashboards.branding.title: ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ describe('Custom Logo', () => {
expect(component).toMatchSnapshot();
});
it('Take in a invalid URL string', () => {
const branding = { logoUrl: undefined };
const branding = {};
const component = mountWithIntl(<CustomLogo {...branding} />);
expect(component).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ import React from 'react';
import '../header_logo.scss';
import { OpenSearchDashboardsLogoDarkMode } from './opensearch_dashboards_logo_darkmode';

/**
* @param {string} logoUrl - custom URL for the top left logo of the main screen
*/
export interface CustomLogoType {
logoUrl: string | undefined;
logoUrl?: string;
}

export const CustomLogo = ({ ...branding }: CustomLogoType) => {
return branding.logoUrl === undefined ? (
return !branding.logoUrl ? (
OpenSearchDashboardsLogoDarkMode()
) : (
<img
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/ui/header/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export interface HeaderProps {
isLocked$: Observable<boolean>;
loadingCount$: ReturnType<HttpStart['getLoadingCount$']>;
onIsLockedUpdate: OnIsLockedUpdate;
branding: { logoUrl: string | undefined };
branding: { logoUrl?: string };
}

export function Header({
Expand Down
2 changes: 1 addition & 1 deletion src/core/public/chrome/ui/header/header_logo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ interface Props {
navLinks$: Observable<ChromeNavLink[]>;
forceNavigation$: Observable<boolean>;
navigateToApp: (appId: string) => void;
logoUrl: string | undefined;
logoUrl?: string;
}

export function HeaderLogo({ href, navigateToApp, logoUrl, ...observables }: Props) {
Expand Down
8 changes: 4 additions & 4 deletions src/core/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,8 @@ export interface CoreSetup<TPluginsStart extends object = object, TStart = unkno
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
logoUrl: string | undefined;
smallLogoUrl: string | undefined;
logoUrl?: string;
smallLogoUrl?: string;
title: string;
};
};
Expand Down Expand Up @@ -297,8 +297,8 @@ export interface CoreStart {
injectedMetadata: {
getInjectedVar: (name: string, defaultValue?: any) => unknown;
getBranding: () => {
logoUrl: string | undefined;
smallLogoUrl: string | undefined;
logoUrl?: string;
smallLogoUrl?: string;
title: string;
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export interface InjectedMetadataParams {
};
};
branding: {
logoUrl: string | undefined;
smallLogoUrl: string | undefined;
logoUrl?: string;
smallLogoUrl?: string;
title: string;
};
};
Expand Down Expand Up @@ -186,8 +186,8 @@ export interface InjectedMetadataSetup {
[key: string]: unknown;
};
getBranding: () => {
logoUrl: string | undefined;
smallLogoUrl: string | undefined;
logoUrl?: string;
smallLogoUrl?: string;
title: string;
};
}
Expand Down
10 changes: 4 additions & 6 deletions src/core/server/rendering/rendering_service.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,10 @@ export class RenderingService {
uiSettings: settings,
},
branding: {
logoUrl:
isLogoUrlValid === true ? opensearchDashboardsConfig.branding.logoUrl : undefined,
smallLogoUrl:
isSmallLogoUrlValid === true
? opensearchDashboardsConfig.branding.smallLogoUrl
: undefined,
logoUrl: isLogoUrlValid ? opensearchDashboardsConfig.branding.logoUrl : undefined,
smallLogoUrl: isSmallLogoUrlValid
? opensearchDashboardsConfig.branding.smallLogoUrl
: undefined,
title: opensearchDashboardsConfig.branding.title,
},
},
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/rendering/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ export interface RenderingMetadata {
};
};
branding: {
logoUrl: string | undefined;
smallLogoUrl: string | undefined;
logoUrl?: string;
smallLogoUrl?: string;
title: string;
};
};
Expand Down

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

2 changes: 1 addition & 1 deletion src/plugins/home/public/application/components/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class Home extends Component {

render() {
const { isLoading, isWelcomeEnabled, isNewOpenSearchDashboardsInstance } = this.state;

if (isWelcomeEnabled) {
if (isLoading) {
return this.renderLoading();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ test('fires opt-in seen when mounted', () => {

test('should render a Welcome screen with the default OpenSearch Dashboards branding', () => {
const defaultBranding = {
smallLogoUrl: undefined,
title: 'OpenSearch Dashboards',
};
const component = shallow(
Expand Down
40 changes: 24 additions & 16 deletions src/plugins/home/public/application/components/welcome.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ interface Props {
onSkip: () => void;
telemetry?: TelemetryPluginStart;
branding: {
smallLogoUrl: string | undefined;
smallLogoUrl?: string;
title: string;
};
}
Expand Down Expand Up @@ -144,6 +144,28 @@ export class Welcome extends React.Component<Props> {
}
};

private renderBrandingEnabledOrDisabledLogo = () => {
if (!this.props.branding.smallLogoUrl) {
return (
<span className="homWelcome__logo">
<EuiIcon type={OpenSearchMarkCentered} size="original" />
</span>
);
} else {
return (
<div className="homWelcome__customLogoContainer">
<img
className="homWelcome__customLogo"
data-test-subj="welcomeCustomLogo"
data-test-image-url={this.props.branding.smallLogoUrl}
alt="logo"
src={this.props.branding.smallLogoUrl}
/>
</div>
);
}
};

render() {
const { urlBasePath, telemetry, branding } = this.props;
return (
Expand All @@ -152,21 +174,7 @@ export class Welcome extends React.Component<Props> {
<header className="homWelcome__header">
<div className="homWelcome__content eui-textCenter">
<EuiSpacer size="xl" />
{branding.smallLogoUrl === undefined ? (
<span className="homWelcome__logo">
<EuiIcon type={OpenSearchMarkCentered} size="original" />
</span>
) : (
<div className="homWelcome__customLogoContainer">
<img
className="homWelcome__customLogo"
data-test-subj="welcomeCustomLogo"
data-test-image-url={branding.smallLogoUrl}
alt="logo"
src={branding.smallLogoUrl}
/>
</div>
)}
{this.renderBrandingEnabledOrDisabledLogo()}
<EuiTitle
size="l"
className="homWelcome__title"
Expand Down

0 comments on commit 913e6d8

Please sign in to comment.