1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/public/js/components/feature/FeatureList.jsx

90 lines
2.5 KiB
React
Raw Normal View History

2014-11-03 13:54:06 +01:00
var React = require('react');
var Feature = require('./Feature');
2014-10-30 18:25:38 +01:00
var noop = function() {};
2014-10-30 18:25:38 +01:00
var FeatureList = React.createClass({
propTypes: {
2015-03-17 22:01:46 +01:00
features: React.PropTypes.array.isRequired,
strategies: React.PropTypes.array.isRequired
},
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() {
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));
return (
<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-10-30 18:25:38 +01:00
}
});
2015-03-17 22:01:46 +01:00
module.exports = FeatureList;