Skip to content

Commit

Permalink
[api_keys] fix Breadcrumbs and Navigation
Browse files Browse the repository at this point in the history
  • Loading branch information
alexwizp committed May 21, 2020
1 parent c04d0b1 commit 57cfa83
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import React from 'react';
import { render } from 'enzyme';
import { RouteComponentProps } from 'react-router-dom';
import { ScopedHistory } from 'kibana/public';

import { Header } from './header';

Expand All @@ -28,7 +29,7 @@ describe('Header', () => {
const component = render(
<Header.WrappedComponent
indexPatternId="test"
history={({} as unknown) as RouteComponentProps['history']}
history={({} as unknown) as ScopedHistory}
location={({} as unknown) as RouteComponentProps['location']}
match={({} as unknown) as RouteComponentProps['match']}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ describe('APIKeysGridPage', () => {
const getViewProperties = () => {
const { docLinks, notifications } = coreMock.createStart();
return {
getUrlForApp: (id: string) => id,
docLinks: new DocumentationLinksService(docLinks),
notifications,
apiKeysAPIClient: apiClientMock,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import moment from 'moment-timezone';
import { NotificationsStart } from 'src/core/public';
import { ApplicationStart, NotificationsStart } from 'src/core/public';
import { SectionLoading } from '../../../../../../../src/plugins/es_ui_shared/public';
import { ApiKey, ApiKeyToInvalidate } from '../../../../common/model';
import { APIKeysAPIClient } from '../api_keys_api_client';
Expand All @@ -40,6 +40,7 @@ interface Props {
notifications: NotificationsStart;
docLinks: DocumentationLinksService;
apiKeysAPIClient: PublicMethodsOf<APIKeysAPIClient>;
getUrlForApp: ApplicationStart['getUrlForApp'];
}

interface State {
Expand Down Expand Up @@ -137,7 +138,11 @@ export class APIKeysGridPage extends Component<Props, State> {
if (!isLoadingTable && apiKeys && apiKeys.length === 0) {
return (
<EuiPageContent>
<EmptyPrompt isAdmin={isAdmin} docLinks={this.props.docLinks} />
<EmptyPrompt
isAdmin={isAdmin}
docLinks={this.props.docLinks}
getUrlForApp={this.props.getUrlForApp}
/>
</EuiPageContent>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,23 @@
*/

import React, { Fragment } from 'react';
import { ApplicationStart } from 'kibana/public';

import { EuiEmptyPrompt, EuiButton, EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { DocumentationLinksService } from '../../documentation_links';

interface Props {
isAdmin: boolean;
docLinks: DocumentationLinksService;
getUrlForApp: ApplicationStart['getUrlForApp'];
}

export const EmptyPrompt: React.FunctionComponent<Props> = ({ isAdmin, docLinks }) => (
export const EmptyPrompt: React.FunctionComponent<Props> = ({
isAdmin,
docLinks,
getUrlForApp,
}) => (
<EuiEmptyPrompt
iconType="managementApp"
title={
Expand Down Expand Up @@ -53,7 +60,7 @@ export const EmptyPrompt: React.FunctionComponent<Props> = ({ isAdmin, docLinks
</Fragment>
}
actions={
<EuiButton type="primary" href="#/dev_tools" data-test-subj="goToConsoleButton">
<EuiButton type="primary" href={getUrlForApp('dev_tools')} data-test-subj="goToConsoleButton">
<FormattedMessage
id="xpack.security.management.apiKeys.table.emptyPromptConsoleButtonMessage"
defaultMessage="Go to Console"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('apiKeysManagementApp', () => {
});

expect(setBreadcrumbs).toHaveBeenCalledTimes(1);
expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: '#/some-base-path', text: 'API Keys' }]);
expect(setBreadcrumbs).toHaveBeenCalledWith([{ href: '/', text: 'API Keys' }]);
expect(container).toMatchInlineSnapshot(`
<div>
Page: {"notifications":{"toasts":{}},"docLinks":{"esDocBasePath":"https://www.elastic.co/guide/en/elasticsearch/reference/mocked-test-branch/"},"apiKeysAPIClient":{"http":{"basePath":{"basePath":"","serverBasePath":""},"anonymousPaths":{}}}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ export const apiKeysManagementApp = Object.freeze({
title: i18n.translate('xpack.security.management.apiKeysTitle', {
defaultMessage: 'API Keys',
}),
async mount({ basePath, element, setBreadcrumbs }) {
async mount({ basePath, element, setBreadcrumbs, history }) {
setBreadcrumbs([
{
text: i18n.translate('xpack.security.apiKeys.breadcrumb', {
defaultMessage: 'API Keys',
}),
href: `#${basePath}`,
href: `/`,
},
]);

const [
[{ docLinks, http, notifications, i18n: i18nStart }],
[{ docLinks, http, notifications, i18n: i18nStart, application }],
{ APIKeysGridPage },
{ APIKeysAPIClient },
] = await Promise.all([
Expand All @@ -48,6 +48,7 @@ export const apiKeysManagementApp = Object.freeze({
render(
<i18nStart.Context>
<APIKeysGridPage
getUrlForApp={application.getUrlForApp}
notifications={notifications}
docLinks={new DocumentationLinksService(docLinks)}
apiKeysAPIClient={new APIKeysAPIClient(http)}
Expand Down

0 comments on commit 57cfa83

Please sign in to comment.