made a view of filtered list

This commit is contained in:
Patrick O'Carroll 2018-01-05 14:17:50 +01:00
parent 5079dcdc62
commit 3797054eb4
2 changed files with 8 additions and 5 deletions

View File

@ -47,16 +47,12 @@ export class AlertRuleList extends React.Component<IContainerProps, any> {
onSearchFilter(event) {
this.setState({ search: event.target.value });
console.log('yo');
}
render() {
const { nav, alertList } = this.props;
let regex = new RegExp(this.state.search, 'ig');
const filteredAlerts = alertList.rules.filter(alert => {
return regex.test(alert.name) || regex.test(alert.stateText);
});
return (
<div>
@ -94,7 +90,7 @@ export class AlertRuleList extends React.Component<IContainerProps, any> {
<section>
<ol className="alert-rule-list">
{filteredAlerts.map(rule => <AlertRuleItem rule={rule} key={rule.id} />)}
{alertList.searchFilter(regex).map(rule => <AlertRuleItem rule={rule} key={rule.id} />)}
</ol>
</section>
</div>

View File

@ -31,4 +31,11 @@ export const AlertListStore = types
self.rules.push(AlertRule.create(rule));
}
}),
}))
.views(self => ({
searchFilter(regex) {
return self.rules.filter(alert => {
return regex.test(alert.name) || regex.test(alert.stateText);
});
},
}));