diff --git a/ui/src/alerts/components/AlertsTable.js b/ui/src/alerts/components/AlertsTable.js index 3921301f5b..48fdcc2d70 100644 --- a/ui/src/alerts/components/AlertsTable.js +++ b/ui/src/alerts/components/AlertsTable.js @@ -30,13 +30,17 @@ const AlertsTable = React.createClass({ this.filterAlerts(newProps.alerts, this.state.searchTerm); }, - filterAlerts(allAlerts, searchTerm) { - const alerts = allAlerts.filter((h) => { - return h.name.toLowerCase().search(searchTerm.toLowerCase()) !== -1 || - h.host.toLowerCase().search(searchTerm.toLowerCase()) !== -1 || - h.level.toLowerCase().search(searchTerm.toLowerCase()) !== -1; + filterAlerts(searchTerm) { + const filteredAlerts = this.props.alerts.filter((h) => { + if (h.host === null || h.name === null || h.level === null) { + return false; + } + + return h.name.toLowerCase().search((searchTerm).toLowerCase()) !== -1 || + h.host.toLowerCase().search((searchTerm).toLowerCase()) !== -1 || + h.level.toLowerCase().search((searchTerm).toLowerCase()) !== -1; }); - this.setState({searchTerm, filteredAlerts: alerts}); + this.setState({searchTerm, filteredAlerts}); }, changeSort(key) { @@ -67,7 +71,7 @@ const AlertsTable = React.createClass({

{this.props.alerts.length} Alerts

- +
@@ -82,9 +86,9 @@ const AlertsTable = React.createClass({ { - alerts.map(({name, time, value, host, level}) => { + alerts.map(({name, level, time, host, value}) => { return ( - + @@ -111,8 +115,23 @@ const SearchBar = React.createClass({ onSearch: PropTypes.func.isRequired, }, - handleChange() { - this.props.onSearch(this.refs.searchInput.value); + getInitialState() { + return { + searchTerm: '', + }; + }, + + componentWillMount() { + const waitPeriod = 300; + this.handleSearch = _.debounce(this.handleSearch, waitPeriod); + }, + + handleSearch() { + this.props.onSearch(this.state.searchTerm); + }, + + handleChange(e) { + this.setState({searchTerm: e.target.value}, this.handleSearch); }, render() { @@ -122,8 +141,8 @@ const SearchBar = React.createClass({ type="text" className="form-control" placeholder="Filter Alerts by Name..." - ref="searchInput" onChange={this.handleChange} + value={this.state.searchTerm} />
{name} {level} {(new Date(Number(time)).toISOString())}