Commit 3797054e by Patrick O'Carroll

made a view of filtered list

parent 5079dcdc
...@@ -47,16 +47,12 @@ export class AlertRuleList extends React.Component<IContainerProps, any> { ...@@ -47,16 +47,12 @@ export class AlertRuleList extends React.Component<IContainerProps, any> {
onSearchFilter(event) { onSearchFilter(event) {
this.setState({ search: event.target.value }); this.setState({ search: event.target.value });
console.log('yo');
} }
render() { render() {
const { nav, alertList } = this.props; const { nav, alertList } = this.props;
let regex = new RegExp(this.state.search, 'ig'); let regex = new RegExp(this.state.search, 'ig');
const filteredAlerts = alertList.rules.filter(alert => {
return regex.test(alert.name) || regex.test(alert.stateText);
});
return ( return (
<div> <div>
...@@ -94,7 +90,7 @@ export class AlertRuleList extends React.Component<IContainerProps, any> { ...@@ -94,7 +90,7 @@ export class AlertRuleList extends React.Component<IContainerProps, any> {
<section> <section>
<ol className="alert-rule-list"> <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> </ol>
</section> </section>
</div> </div>
......
...@@ -31,4 +31,11 @@ export const AlertListStore = types ...@@ -31,4 +31,11 @@ export const AlertListStore = types
self.rules.push(AlertRule.create(rule)); self.rules.push(AlertRule.create(rule));
} }
}), }),
}))
.views(self => ({
searchFilter(regex) {
return self.rules.filter(alert => {
return regex.test(alert.name) || regex.test(alert.stateText);
});
},
})); }));
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment