Skip to content

Commit

Permalink
Added an EuiEmptyState to Credentials
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz committed Oct 8, 2020
1 parent 44b48a2 commit 6eb5250
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { shallow } from 'enzyme';

import { CredentialsList } from './credentials_list';
import { EuiBasicTable, EuiCopy } from '@elastic/eui';
import { EuiBasicTable, EuiCopy, EuiEmptyPrompt } from '@elastic/eui';
import { IApiToken } from '../types';
import { ApiTokenTypes } from '../constants';

Expand All @@ -26,7 +26,7 @@ describe('Credentials', () => {

// Kea mocks
const values = {
apiTokens: [],
apiTokens: [apiToken],
meta: {
page: {
current: 1,
Expand Down Expand Up @@ -78,6 +78,19 @@ describe('Credentials', () => {
});
});

describe('empty state', () => {
it('renders an EuiEmptyState when no credentials are available', () => {
setMockValues({
...values,
apiTokens: [],
});

const wrapper = shallow(<CredentialsList />);
expect(wrapper.exists(EuiEmptyPrompt)).toBe(true);
expect(wrapper.exists(EuiBasicTable)).toBe(false);
});
});

describe('pagination', () => {
it('derives pagination from meta object', () => {
setMockValues({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
*/

import React, { useMemo } from 'react';
import { EuiBasicTable, EuiBasicTableColumn, EuiButtonIcon, EuiCopy } from '@elastic/eui';
import {
EuiBasicTable,
EuiBasicTableColumn,
EuiButtonIcon,
EuiCopy,
EuiEmptyPrompt,
} from '@elastic/eui';
import { CriteriaWithPagination } from '@elastic/eui/src/components/basic_table/basic_table';
import { useActions, useValues } from 'kea';

Expand Down Expand Up @@ -113,6 +119,24 @@ export const CredentialsList: React.FC = () => {
hidePerPageOptions: true,
};

if (items.length < 1) {
return (
<EuiEmptyPrompt
iconType="editorStrike"
title={
<h2>
{i18n.translate('xpack.enterpriseSearch.appSearch.credentials.empty.title', {
defaultMessage: 'No API Keys have been created yet.',
})}
</h2>
}
body={i18n.translate('xpack.enterpriseSearch.appSearch.credentials.empty.body', {
defaultMessage: 'Click Create a key to make your first one.',
})}
/>
);
}

const onTableChange = ({ page }: CriteriaWithPagination<IApiToken>) => {
const { index: current } = page;
fetchCredentials(current + 1);
Expand Down

0 comments on commit 6eb5250

Please sign in to comment.