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

82 lines
2.5 KiB
React
Raw Normal View History

var React = require('react');
var FeatureList = require('./FeatureList');
var FeatureForm = require('./FeatureForm');
var FeatureActions = require('../../stores/FeatureToggleActions');
2015-03-17 20:29:03 +01:00
var ErrorActions = require('../../stores/ErrorActions');
var FeatureToggleStore = require('../../stores/FeatureToggleStore');
2015-03-17 22:01:46 +01:00
var StrategyStore = require('../../stores/StrategyStore');
2014-10-30 18:25:38 +01:00
2014-11-03 14:00:45 +01:00
var FeatureTogglesComponent = React.createClass({
2014-10-30 18:25:38 +01:00
getInitialState: function() {
return {
features: FeatureToggleStore.getFeatureToggles(),
createView: false
2014-10-30 18:25:38 +01:00
};
},
onFeatureToggleChange: function() {
this.setState({
features: FeatureToggleStore.getFeatureToggles()
});
},
componentDidMount: function() {
this.unsubscribe = FeatureToggleStore.listen(this.onFeatureToggleChange);
},
componentWillUnmount: function() {
this.unsubscribe();
},
2014-10-30 18:25:38 +01:00
updateFeature: function (feature) {
2015-03-17 20:29:03 +01:00
FeatureActions.update.triggerPromise(feature);
2014-10-31 12:25:18 +01:00
},
2014-12-15 22:40:07 +01:00
archiveFeature: function (feature) {
2015-03-17 20:29:03 +01:00
FeatureActions.archive.triggerPromise(feature);
2014-12-15 22:40:07 +01:00
},
2014-10-30 18:25:38 +01:00
createFeature: function (feature) {
FeatureActions.create.triggerPromise(feature)
2015-03-17 20:29:03 +01:00
.then(this.cancelNewFeature);
2014-10-30 18:25:38 +01:00
},
newFeature: function() {
2014-11-03 13:54:06 +01:00
this.setState({createView: true});
2014-10-30 18:25:38 +01:00
},
2015-03-17 20:29:03 +01:00
cancelNewFeature: function () {
2014-11-03 13:54:06 +01:00
this.setState({createView: false});
2015-03-17 20:29:03 +01:00
ErrorActions.clear();
2014-11-10 14:55:56 +01:00
},
2014-10-30 18:25:38 +01:00
render: function() {
return (
<div>
2014-11-03 13:54:06 +01:00
{this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
<FeatureList
2014-11-03 13:54:06 +01:00
features={this.state.features}
onFeatureChanged={this.updateFeature}
2014-12-15 22:40:07 +01:00
onFeatureArchive={this.archiveFeature}
onFeatureSubmit={this.createFeature}
onFeatureCancel={this.cancelNewFeature}
2015-03-17 22:01:46 +01:00
onNewFeature={this.newFeature}
strategies={StrategyStore.getStrategies()} />
2014-10-30 18:25:38 +01:00
</div>
);
2014-11-03 13:54:06 +01:00
},
renderCreateView: function() {
2015-03-17 22:01:46 +01:00
return <FeatureForm
onCancel={this.cancelNewFeature}
onSubmit={this.createFeature}
strategies={StrategyStore.getStrategies()} />;
2014-11-03 13:54:06 +01:00
},
renderCreateButton: function() {
2015-03-17 20:29:03 +01:00
return <button className="mal" onClick={this.newFeature}>Create feature toggle</button>;
2014-10-30 18:25:38 +01:00
}
});
module.exports = FeatureTogglesComponent;