Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] Support OpenSearch logo theming for light / dark modes #1571

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions public/apps/customerror/custom-error.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,22 @@ import React from 'react';
import ReactDOM from 'react-dom';
import { Router, Route } from 'react-router-dom';
import { ERROR_MISSING_ROLE_PATH } from '../../../common';
import defaultBrandImage from '../../assets/opensearch_logo_h.svg';
import { ClientConfigType } from '../../types';
import './_index.scss';

interface CustomErrorDeps {
title: string;
subtitle: string;
http: CoreStart['http'];
chrome: CoreStart['chrome'];
config: ClientConfigType['ui']['basicauth']['login'];
}

export function CustomErrorPage(props: CustomErrorDeps) {
return (
<EuiListGroup className="custom-error-wrapper">
{props.config.showbrandimage && (
<EuiImage alt="" url={props.config.brandimage || defaultBrandImage} />
<EuiImage alt="" url={props.config.brandimage || props.chrome.logos.OpenSearch.url} />
)}
<EuiSpacer size="s" />
<EuiText size="m" textAlign="center">
Expand Down Expand Up @@ -62,6 +62,7 @@ export async function renderPage(
<Route path={ERROR_MISSING_ROLE_PATH}>
<CustomErrorPage
http={coreStart.http}
chrome={coreStart.chrome}
config={config.ui.basicauth.login}
title="Missing Role"
subtitle="No roles available for this user, please contact your system administrator."
Expand Down
5 changes: 4 additions & 1 deletion public/apps/login/login-app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@
params: AppMountParameters,
config: ClientConfigType
) {
ReactDOM.render(<LoginPage http={coreStart.http} config={config} />, params.element);
ReactDOM.render(

Check warning on line 29 in public/apps/login/login-app.tsx

View check run for this annotation

Codecov / codecov/patch

public/apps/login/login-app.tsx#L29

Added line #L29 was not covered by tests
<LoginPage http={coreStart.http} chrome={coreStart.chrome} config={config} />,
params.element
);
return () => ReactDOM.unmountComponentAtNode(params.element);
}
4 changes: 2 additions & 2 deletions public/apps/login/login-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
} from '@elastic/eui';
import { CoreStart } from '../../../../../src/core/public';
import { ClientConfigType } from '../../types';
import defaultBrandImage from '../../assets/opensearch_logo_h.svg';
import { validateCurrentPassword } from '../../utils/login-utils';
import {
ANONYMOUS_AUTH_LOGIN,
Expand All @@ -39,6 +38,7 @@ import {

interface LoginPageDeps {
http: CoreStart['http'];
chrome: CoreStart['chrome'];
config: ClientConfigType;
}

Expand Down Expand Up @@ -259,7 +259,7 @@ export function LoginPage(props: LoginPageDeps) {
<EuiImage
size="fullWidth"
alt=""
url={props.config.ui.basicauth.login.brandimage || defaultBrandImage}
url={props.config.ui.basicauth.login.brandimage || props.chrome.logos.OpenSearch.url}
/>
)}
<EuiSpacer size="s" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ exports[`Login page renders renders with default value: string 1`] = `
<EuiImage
alt=""
size="fullWidth"
url="test-file-stub"
url="/ui/logos/opensearch_on_light.svg"
/>
<EuiSpacer
size="s"
Expand Down Expand Up @@ -469,7 +469,7 @@ exports[`Login page renders renders with default value: string array 1`] = `
<EuiImage
alt=""
size="fullWidth"
url="test-file-stub"
url="/ui/logos/opensearch_on_light.svg"
/>
<EuiSpacer
size="s"
Expand Down
34 changes: 27 additions & 7 deletions public/apps/login/test/login-page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { ClientConfigType } from '../../../types';
import { LoginPage, extractNextUrlFromWindowLocation } from '../login-page';
import { validateCurrentPassword } from '../../../utils/login-utils';
import { API_AUTH_LOGOUT } from '../../../../common';
import { chromeServiceMock } from '../../../../../../src/core/public/mocks';

jest.mock('../../../utils/login-utils', () => ({
validateCurrentPassword: jest.fn(),
Expand Down Expand Up @@ -84,12 +85,17 @@ describe('test extractNextUrlFromWindowLocation', () => {
});

describe('Login page', () => {
let chrome: ReturnType<typeof chromeServiceMock.createStartContract>;
const mockHttpStart = {
basePath: {
serverBasePath: '/app/opensearch-dashboards',
},
};

beforeEach(() => {
chrome = chromeServiceMock.createStartContract();
});

describe('renders', () => {
it('renders with config value: string array', () => {
const config: ClientConfigType = {
Expand All @@ -99,7 +105,9 @@ describe('Login page', () => {
logout_url: API_AUTH_LOGOUT,
},
};
const component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
const component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
expect(component).toMatchSnapshot();
});

Expand All @@ -111,7 +119,9 @@ describe('Login page', () => {
logout_url: API_AUTH_LOGOUT,
},
};
const component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
const component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
expect(component).toMatchSnapshot();
});

Expand All @@ -123,7 +133,9 @@ describe('Login page', () => {
logout_url: API_AUTH_LOGOUT,
},
};
const component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
const component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
expect(component).toMatchSnapshot();
});

Expand All @@ -134,7 +146,9 @@ describe('Login page', () => {
type: [''],
},
};
const component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
const component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
expect(component).toMatchSnapshot();
});

Expand All @@ -145,7 +159,9 @@ describe('Login page', () => {
type: '',
},
};
const component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
const component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
expect(component).toMatchSnapshot();
});
});
Expand All @@ -162,7 +178,9 @@ describe('Login page', () => {
};
beforeEach(() => {
useState.mockImplementation((initialValue) => [initialValue, setState]);
component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
});

it('should update user name field on change event', () => {
Expand Down Expand Up @@ -195,7 +213,9 @@ describe('Login page', () => {
beforeEach(() => {
useState.mockImplementation(() => ['user1', setState]);
useState.mockImplementation(() => ['password1', setState]);
component = shallow(<LoginPage http={mockHttpStart as any} config={config as any} />);
component = shallow(
<LoginPage http={mockHttpStart as any} chrome={chrome} config={config as any} />
);
});

it('submit click event', () => {
Expand Down
10 changes: 0 additions & 10 deletions public/assets/opensearch_logo_h.svg

This file was deleted.

Loading