Skip to content

Commit

Permalink
Table - allow noItemMessage to be node
Browse files Browse the repository at this point in the history
  • Loading branch information
nreese committed Mar 15, 2018
1 parent 3e1eff1 commit 2cd0bcd
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 4 deletions.
39 changes: 39 additions & 0 deletions src/components/basic_table/__snapshots__/basic_table.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,45 @@ exports[`EuiBasicTable basic - empty - custom message 1`] = `
</div>
`;

exports[`EuiBasicTable basic - empty - custom message as node 1`] = `
<div
className="euiBasicTable testClass1 testClass2"
>
<EuiTable>
<EuiTableHeader>
<EuiTableHeaderCell
align="left"
isSortAscending={false}
isSorted={false}
key="_data_h_name_0"
scope="col"
>
Name
</EuiTableHeaderCell>
</EuiTableHeader>
<EuiTableBody>
<EuiTableRow>
<EuiTableRowCell
align="center"
colSpan={1}
textOnly={true}
>
<p>
no items, click
<a
href={true}
>
here
</a>
to make some
</p>
</EuiTableRowCell>
</EuiTableRow>
</EuiTableBody>
</EuiTable>
</div>
`;

exports[`EuiBasicTable basic - empty 1`] = `
<div
className="euiBasicTable testClass1 testClass2"
Expand Down
12 changes: 10 additions & 2 deletions src/components/basic_table/basic_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ export const SelectionType = PropTypes.shape({
selectableMessage: PropTypes.func // (selectable, item) => boolean;
});

export const NoItemsMessageType = PropTypes.oneOfType([PropTypes.string, PropTypes.node]);

const SortingType = PropTypes.shape({
sort: PropertySortType
});
Expand All @@ -133,7 +135,7 @@ const BasicTablePropTypes = {
onChange: PropTypes.func,
error: PropTypes.string,
loading: PropTypes.bool,
noItemsMessage: PropTypes.string,
noItemsMessage: NoItemsMessageType,
className: PropTypes.string
};

Expand Down Expand Up @@ -421,11 +423,17 @@ export class EuiBasicTable extends Component {

renderEmptyBody() {
const colSpan = this.props.columns.length + (this.props.selection ? 1 : 0);
let message;
if (typeof this.props.noItemsMessage === 'string') {
message = (<div>{ this.props.noItemsMessage }</div>);
} else {
message = this.props.noItemsMessage;
}
return (
<EuiTableBody>
<EuiTableRow>
<EuiTableRowCell align="center" colSpan={colSpan}>
<div>{ this.props.noItemsMessage }</div>
{message}
</EuiTableRowCell>
</EuiTableRow>
</EuiTableBody>
Expand Down
21 changes: 21 additions & 0 deletions src/components/basic_table/basic_table.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ describe('EuiBasicTable', () => {
expect(component).toMatchSnapshot();
});

test('basic - empty - custom message as node', () => {

const props = {
...requiredProps,
items: [],
columns: [
{
field: 'name',
name: 'Name',
description: 'description'
}
],
noItemsMessage: (<p>no items, click <a href>here</a> to make some</p>)
};
const component = shallow(
<EuiBasicTable {...props} />
);

expect(component).toMatchSnapshot();
});

test('basic - with items', () => {

const props = {
Expand Down
5 changes: 3 additions & 2 deletions src/components/basic_table/in_memory_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import PropTypes from 'prop-types';
import {
EuiBasicTable,
ColumnType,
SelectionType
SelectionType,
NoItemsMessageType
} from './basic_table';
import {
defaults as paginationBarDefaults
Expand All @@ -22,7 +23,7 @@ const InMemoryTablePropTypes = {
columns: PropTypes.arrayOf(ColumnType).isRequired,
items: PropTypes.array,
loading: PropTypes.bool,
message: PropTypes.string,
message: NoItemsMessageType,
error: PropTypes.string,
search: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({
defaultQuery: QueryType,
Expand Down

0 comments on commit 2cd0bcd

Please sign in to comment.