Enable filtering by hostname (#1139)

This commit is contained in:
Mike Stone 2017-01-31 15:12:38 -05:00 committed by GitHub
parent 7212d4c333
commit 8bb57ca02e
2 changed files with 16 additions and 3 deletions

View file

@ -64,8 +64,9 @@ class QueryResultsTable extends Component {
}
renderTableHeaderRowData = (column, index) => {
const { onFilterAttribute, onSetActiveColumn } = this;
const filterable = column === 'hostname' ? 'host_hostname' : column;
const { activeColumn, resultsFilter } = this.state;
const { onFilterAttribute, onSetActiveColumn } = this;
const filterIconClassName = classnames(`${baseClass}__filter-icon`, {
[`${baseClass}__filter-icon--is-active`]: activeColumn === column,
});
@ -75,9 +76,9 @@ class QueryResultsTable extends Component {
<span><Icon className={filterIconClassName} name="filter" />{column}</span>
<InputField
name={column}
onChange={onFilterAttribute(column)}
onChange={onFilterAttribute(filterable)}
onFocus={onSetActiveColumn(column)}
value={resultsFilter[column]}
value={resultsFilter[filterable]}
/>
</th>
);

View file

@ -3,6 +3,7 @@ import expect, { createSpy, restoreSpies } from 'expect';
import { keys } from 'lodash';
import { mount } from 'enzyme';
import { fillInFormInput } from 'test/helpers';
import QueryResultsTable from 'components/queries/QueryResultsTable';
const host = {
@ -44,6 +45,7 @@ const campaignWithQueryResults = {
...campaignWithNoQueryResults,
query_results: [
{ host_hostname: 'dfoihgsx', cwd: '/', directory: '/root' },
{ host_hostname: 'abc123', cwd: '/', directory: '/root' },
],
};
@ -85,6 +87,16 @@ describe('QueryResultsTable - component', () => {
});
});
it('filters by hostname', () => {
const hostnameInputFilter = componentWithQueryResults.find('InputField').find({ name: 'hostname' });
expect(componentWithQueryResults.find('QueryResultsRow').length).toEqual(2);
fillInFormInput(hostnameInputFilter, 'abc123');
expect(componentWithQueryResults.find('QueryResultsRow').length).toEqual(1);
});
it('calls the onExportQueryResults prop when the export button is clicked', () => {
const spy = createSpy();
const component = mount(<QueryResultsTable campaign={campaignWithQueryResults} onExportQueryResults={spy} />);