2014-11-03 13:54:06 +01:00
|
|
|
var React = require('react');
|
|
|
|
var Feature = require('./Feature');
|
2014-10-30 18:25:38 +01:00
|
|
|
|
2014-12-19 06:54:51 +01:00
|
|
|
var noop = function() {};
|
|
|
|
|
2014-10-30 18:25:38 +01:00
|
|
|
var FeatureList = React.createClass({
|
2014-12-19 06:54:51 +01:00
|
|
|
propTypes: {
|
2015-03-17 22:01:46 +01:00
|
|
|
features: React.PropTypes.array.isRequired,
|
|
|
|
strategies: React.PropTypes.array.isRequired
|
2014-12-19 06:54:51 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
onFeatureChanged: noop,
|
|
|
|
onFeatureArchive: noop
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
filter: undefined
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
onFilterChange: function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
this.setState({filter: e.target.value.trim()});
|
|
|
|
},
|
|
|
|
|
|
|
|
filteredFeatures: function() {
|
|
|
|
if(this.state.filter) {
|
|
|
|
var regex = new RegExp(this.state.filter, "i");
|
|
|
|
|
|
|
|
return this.props.features.filter(function(item) {
|
|
|
|
return regex.test(item.name) || regex.test(item.strategy);
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return this.props.features;
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
|
2014-10-30 18:25:38 +01:00
|
|
|
render: function() {
|
2014-12-19 06:54:51 +01:00
|
|
|
var featureNodes = this.filteredFeatures().map(function(feature) {
|
2014-11-03 13:54:06 +01:00
|
|
|
return (
|
|
|
|
<Feature
|
2014-10-30 18:25:38 +01:00
|
|
|
key={feature.name}
|
|
|
|
feature={feature}
|
2014-12-15 22:40:07 +01:00
|
|
|
onChange={this.props.onFeatureChanged}
|
2015-03-17 22:01:46 +01:00
|
|
|
onArchive={this.props.onFeatureArchive}
|
|
|
|
strategies={this.props.strategies}
|
|
|
|
/>
|
2014-10-30 18:25:38 +01:00
|
|
|
);
|
|
|
|
}.bind(this));
|
|
|
|
|
2014-11-13 10:46:45 +01:00
|
|
|
return (
|
2014-12-19 06:54:51 +01:00
|
|
|
<div className=''>
|
|
|
|
<table className='outerborder man'>
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th></th>
|
|
|
|
<th>Name</th>
|
|
|
|
<th className="hide-lt480">Strategy</th>
|
|
|
|
<th></th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>
|
|
|
|
<tr>
|
|
|
|
<td colSpan="4">
|
|
|
|
<input
|
|
|
|
name="filter"
|
|
|
|
ref="filter"
|
|
|
|
type="text"
|
|
|
|
placeholder="Filter by name or strategy"
|
|
|
|
onChange={this.onFilterChange}
|
|
|
|
value={this.state.filter}
|
|
|
|
/>
|
|
|
|
</td>
|
|
|
|
</tr>
|
|
|
|
</tbody>
|
|
|
|
{featureNodes}
|
|
|
|
</table>
|
|
|
|
</div>
|
2014-11-13 10:46:45 +01:00
|
|
|
);
|
2014-10-30 18:25:38 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-03-17 22:01:46 +01:00
|
|
|
module.exports = FeatureList;
|