Skip to content

Commit

Permalink
Refactor login logo usage (#1568) (#1571)
Browse files Browse the repository at this point in the history
Signed-off-by: Miki <miki@amazon.com>
(cherry picked from commit ecb15d5)

Co-authored-by: Miki <miki@amazon.com>
  • Loading branch information
opensearch-trigger-bot[bot] and AMoo-Miki authored Sep 5, 2023
1 parent 9b11d2b commit b04da85
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
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 @@ export function renderApp(
params: AppMountParameters,
config: ClientConfigType
) {
ReactDOM.render(<LoginPage http={coreStart.http} config={config} />, params.element);
ReactDOM.render(
<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
4 changes: 2 additions & 2 deletions public/apps/login/test/__snapshots__/login-page.test.tsx.snap
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.

0 comments on commit b04da85

Please sign in to comment.