From 574ebe8f34aa0af027da65e3fd11916bf5fa0b36 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 15 Mar 2018 14:00:07 -0600 Subject: [PATCH] [BasicTable] - allow noItemMessage to be node (#516) * Table - allow noItemMessage to be node * change log * just use node propType * add example of passing node for message --- CHANGELOG.md | 2 + .../tables/in_memory/in_memory_selection.js | 12 ++++- .../__snapshots__/basic_table.test.js.snap | 47 ++++++++++++++++--- src/components/basic_table/basic_table.js | 7 +-- .../basic_table/basic_table.test.js | 21 +++++++++ src/components/basic_table/in_memory_table.js | 4 +- 6 files changed, 81 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 763c71e967b..2a9836155b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ - `EuiInMemoryTable` pass items to BasicTable when message is provided ([#517](https://github.com/elastic/eui/pull/517)). - `EuiSearchBox` now passes unused props through to `EuiFieldSearch` ([#514](https://github.com/elastic/eui/pull/514)) +- Change `EuiBasicTable` `noItemsMessage` and `EuiInMemoryTable` `messgae` propType to node +instead of just string ([#516](https://github.com/elastic/eui/pull/516)) # [`0.0.27`](https://github.com/elastic/eui/tree/v0.0.27) diff --git a/src-docs/src/views/tables/in_memory/in_memory_selection.js b/src-docs/src/views/tables/in_memory/in_memory_selection.js index ea96a0877e3..bdc67665c8a 100644 --- a/src-docs/src/views/tables/in_memory/in_memory_selection.js +++ b/src-docs/src/views/tables/in_memory/in_memory_selection.js @@ -48,7 +48,17 @@ export class Table extends Component { this.state = { loading: false, users: [], - message: 'No users, click "Load Users" to load some', + message: ( +
+ Looks like you don't have any users. Let's create some! + + Load Users + +
+ ), selection: [] }; } diff --git a/src/components/basic_table/__snapshots__/basic_table.test.js.snap b/src/components/basic_table/__snapshots__/basic_table.test.js.snap index b051c3434e0..2fd6065636d 100644 --- a/src/components/basic_table/__snapshots__/basic_table.test.js.snap +++ b/src/components/basic_table/__snapshots__/basic_table.test.js.snap @@ -23,9 +23,46 @@ exports[`EuiBasicTable basic - empty - custom message 1`] = ` colSpan={1} textOnly={true} > -
- where my items at? -
+ where my items at? + + + + + +`; + +exports[`EuiBasicTable basic - empty - custom message as node 1`] = ` +
+ + + + Name + + + + + +

+ no items, click + + here + + to make some +

@@ -56,9 +93,7 @@ exports[`EuiBasicTable basic - empty 1`] = ` colSpan={1} textOnly={true} > -
- No items found -
+ No items found diff --git a/src/components/basic_table/basic_table.js b/src/components/basic_table/basic_table.js index b96b94d89e9..da079c7114d 100644 --- a/src/components/basic_table/basic_table.js +++ b/src/components/basic_table/basic_table.js @@ -133,7 +133,7 @@ const BasicTablePropTypes = { onChange: PropTypes.func, error: PropTypes.string, loading: PropTypes.bool, - noItemsMessage: PropTypes.string, + noItemsMessage: PropTypes.node, className: PropTypes.string }; @@ -420,12 +420,13 @@ export class EuiBasicTable extends Component { } renderEmptyBody() { - const colSpan = this.props.columns.length + (this.props.selection ? 1 : 0); + const { columns, selection, noItemsMessage } = this.props; + const colSpan = columns.length + (selection ? 1 : 0); return ( -
{ this.props.noItemsMessage }
+ {noItemsMessage}
diff --git a/src/components/basic_table/basic_table.test.js b/src/components/basic_table/basic_table.test.js index 2904121c2da..a61bcc837ae 100644 --- a/src/components/basic_table/basic_table.test.js +++ b/src/components/basic_table/basic_table.test.js @@ -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: (

no items, click here to make some

) + }; + const component = shallow( + + ); + + expect(component).toMatchSnapshot(); + }); + test('basic - with items', () => { const props = { diff --git a/src/components/basic_table/in_memory_table.js b/src/components/basic_table/in_memory_table.js index 625b3067943..ecb4c3272f5 100644 --- a/src/components/basic_table/in_memory_table.js +++ b/src/components/basic_table/in_memory_table.js @@ -3,7 +3,7 @@ import PropTypes from 'prop-types'; import { EuiBasicTable, ColumnType, - SelectionType + SelectionType, } from './basic_table'; import { defaults as paginationBarDefaults @@ -22,7 +22,7 @@ const InMemoryTablePropTypes = { columns: PropTypes.arrayOf(ColumnType).isRequired, items: PropTypes.array, loading: PropTypes.bool, - message: PropTypes.string, + message: PropTypes.node, error: PropTypes.string, search: PropTypes.oneOfType([PropTypes.bool, PropTypes.shape({ defaultQuery: QueryType,