Skip to content
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

Extract items and search from EuiInMemoryTable's ...rest prop #851

Merged
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## [`master`](https://github.com/elastic/eui/tree/master)

No changes since 0.0.48.
**Bug fixes**
- `EuiInMemoryTable` now applies its search filter ([#851](https://github.com/elastic/eui/pull/851))

## [`0.0.48`](https://github.com/elastic/eui/tree/v0.0.48)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,6 @@ exports[`EuiInMemoryTable with pagination 1`] = `
"id": "2",
"name": "name2",
},
Object {
"id": "3",
"name": "name3",
},
]
}
noItemsMessage="No items found"
Expand Down Expand Up @@ -541,7 +537,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and simple search
}
}
responsive={true}
search={true}
selection={
Object {
"onSelectionChanged": [Function],
Expand Down Expand Up @@ -654,10 +649,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and column rendere
"id": "2",
"name": "name2",
},
Object {
"id": "3",
"name": "name3",
},
]
}
noItemsMessage="No items found"
Expand Down Expand Up @@ -748,14 +739,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea
"id": "1",
"name": "name1",
},
Object {
"id": "2",
"name": "name2",
},
Object {
"id": "3",
"name": "name3",
},
]
}
noItemsMessage="No items found"
Expand All @@ -773,26 +756,6 @@ exports[`EuiInMemoryTable with pagination, selection, sorting and configured sea
}
}
responsive={true}
search={
Object {
"box": Object {
"aria-label": "aria-label",
"className": "testClass1 testClass2",
"data-test-subj": "test subject string",
"incremental": true,
},
"defaultQuery": "name:name1",
"filters": Array [
Object {
"field": "name",
"name": "Name1",
"negatedName": "Not Name1",
"type": "field_value_toggle",
"value": "name1",
},
],
}
}
selection={
Object {
"onSelectionChanged": [Function],
Expand Down
2 changes: 2 additions & 0 deletions src/components/basic_table/in_memory_table.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ export class EuiInMemoryTable extends Component {
sorting: hasSorting,
itemIdToExpandedRowMap,
itemId,
items: _unuseditems, // eslint-disable-line no-unused-vars
search, // eslint-disable-line no-unused-vars
...rest
} = this.props;

Expand Down
73 changes: 72 additions & 1 deletion src/components/basic_table/in_memory_table.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount, shallow } from 'enzyme';
import { requiredProps } from '../../test';

import { EuiInMemoryTable } from './in_memory_table';
import { ENTER } from '../../services/key_codes';

describe('EuiInMemoryTable', () => {

Expand Down Expand Up @@ -522,4 +523,74 @@ describe('EuiInMemoryTable', () => {
expect(component).toMatchSnapshot();
});

describe('search interaction & functionality', () => {
it('updates the results as based on the entered query', () => {
const items = [
{
active: true,
name: 'Kansas'
},
{
active: true,
name: 'North Dakota'
},
{
active: false,
name: 'Florida'
},
];

const columns = [
{
field: 'active',
name: 'Is Active'
},
{
field: 'name',
name: 'Name'
}
];

const search = {};

const props = { items, columns, search, className: 'testTable' };

const component = mount(
<EuiInMemoryTable {...props}/>
);

// should render with all three results visible
expect(component.find('.testTable EuiTableRow').length).toBe(3);

const searchField = component.find('EuiFieldSearch input[type="search"]');

searchField.simulate(
'keyUp',
{
target: {
value: 'is:active',
},
keyCode: ENTER
}
);
component.update();

// should render with the two active results
expect(component.find('.testTable EuiTableRow').length).toBe(2);

searchField.simulate(
'keyUp',
{
target: {
value: 'active:false',
},
keyCode: ENTER
}
);
component.update();

// should render with the one inactive result
expect(component.find('.testTable EuiTableRow').length).toBe(1);
});
});
});