1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/packages/unleash-frontend/public/js/components/feature/FeatureList.jsx

85 lines
2.3 KiB
React
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const React = require('react');
const Feature = require('./Feature');
2014-10-30 18:25:38 +01:00
2016-06-18 21:53:18 +02:00
const noop = function() {};
2016-06-18 21:53:18 +02:00
const FeatureList = React.createClass({
propTypes: {
2015-03-17 22:01:46 +01:00
features: React.PropTypes.array.isRequired,
strategies: React.PropTypes.array.isRequired
},
2016-06-18 21:53:18 +02:00
getDefaultProps() {
return {
onFeatureChanged: noop,
onFeatureArchive: noop
};
},
2016-06-18 21:53:18 +02:00
getInitialState() {
return {
filter: undefined
};
},
2016-06-18 21:53:18 +02:00
onFilterChange(e) {
e.preventDefault();
this.setState({filter: e.target.value.trim()});
},
2016-06-18 21:53:18 +02:00
filteredFeatures() {
if(this.state.filter) {
2016-06-18 21:53:18 +02:00
const regex = new RegExp(this.state.filter, "i");
2016-06-18 21:53:18 +02:00
return this.props.features.filter(item => regex.test(item.name) || regex.test(item.strategy));
} else {
return this.props.features;
}
},
2016-06-18 21:53:18 +02:00
render() {
const featureNodes = this.filteredFeatures().map(feature => <Feature
key={feature.name}
feature={feature}
onChange={this.props.onFeatureChanged}
onArchive={this.props.onFeatureArchive}
strategies={this.props.strategies}
/>);
2014-10-30 18:25:38 +01:00
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;