Skip to content

feat(eui): add noItemsMessage prop to EuiInMemoryTable #8812

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions packages/eui/changelogs/upcoming/8812.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- Added `noItemsMessage` prop to `EuiInMemoryTable`

**Deprecations**

- Deprecated `message` prop in `EuiInMemoryTable` in favor of `noItemsMessage` which is a more meaningful prop name; there are no functional changes

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const meta: Meta<EuiInMemoryTableProps> = {
error: '',
loading: false,
// Set to strings for easier testing
message: '',
noItemsMessage: '',
childrenBetween: '',
// Inherited from EuiTable
responsiveBreakpoint: 'm',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('EuiInMemoryTable', () => {
expect(container.firstChild).toMatchSnapshot();
});

test('with message', () => {
test('with noItemsMessage', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
items: [],
Expand All @@ -64,14 +64,14 @@ describe('EuiInMemoryTable', () => {
description: 'description',
},
],
message: 'where my items at?',
noItemsMessage: 'where my items at?',
};
const { getByText } = render(<EuiInMemoryTable {...props} />);

expect(getByText('where my items at?')).toBeTruthy();
});

test('with message and loading', () => {
test('with noItemsMessage and loading', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
items: [],
Expand All @@ -82,7 +82,7 @@ describe('EuiInMemoryTable', () => {
description: 'description',
},
],
message: 'Loading items....',
noItemsMessage: 'Loading items....',
loading: true,
};
const { container } = render(<EuiInMemoryTable {...props} />);
Expand Down Expand Up @@ -136,10 +136,10 @@ describe('EuiInMemoryTable', () => {
expect(getByText('expanded row content')).toBeTruthy();
});

test('with items and message - expecting to show the items', () => {
test('with items and noItemsMessage - expecting to show the items', () => {
const props: EuiInMemoryTableProps<BasicItem> = {
...requiredProps,
message: 'show me!',
noItemsMessage: 'show me!',
items: [
{ id: '1', name: 'name1' },
{ id: '2', name: 'name2' },
Expand Down Expand Up @@ -1036,7 +1036,7 @@ describe('EuiInMemoryTable', () => {
defaultQuery: 'No',
},
className: 'testTable',
message: <span className="customMessage">No items found!</span>,
noItemsMessage: <span className="customMessage">No items found!</span>,
};

const { container } = render(<EuiInMemoryTable {...props} />);
Expand Down Expand Up @@ -1080,7 +1080,7 @@ describe('EuiInMemoryTable', () => {
defaultQuery: 'No',
},
className: 'testTable',
message: <span className="customMessage">No items found!</span>,
noItemsMessage: <span className="customMessage">No items found!</span>,
};

const { container: container2 } = render(
Expand Down
11 changes: 10 additions & 1 deletion packages/eui/src/components/basic_table/in_memory_table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,15 @@ type InMemoryTableProps<T extends object> = Omit<
EuiBasicTableProps<T>,
'pagination' | 'sorting' | 'noItemsMessage' | 'onChange'
> & {
/**
* Message to display if table is empty
* @deprecated Use `noItemsMessage` instead.
*/
message?: ReactNode;
/**
* Message to display if table is empty
*/
noItemsMessage?: ReactNode;
/**
* Configures {@link Search}.
*/
Expand Down Expand Up @@ -677,6 +685,7 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
columns,
loading,
message,
noItemsMessage,
error,
selection,
compressed,
Expand Down Expand Up @@ -750,7 +759,7 @@ export class EuiInMemoryTable<T extends object = object> extends Component<
onChange={this.onTableChange}
error={error}
loading={loading}
noItemsMessage={message}
noItemsMessage={noItemsMessage || message}
tableLayout={tableLayout}
compressed={compressed}
itemIdToExpandedRowMap={itemIdToExpandedRowMap}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ export default () => {
rowHeader="firstName"
error={error}
loading={loading}
message={message}
noItemsMessage={message}
search={search}
sorting={true}
pagination={pagination}
Expand Down