2016-06-18 21:53:18 +02:00
|
|
|
'use strict';
|
|
|
|
const React = require('react');
|
|
|
|
const FeatureList = require('./FeatureList');
|
|
|
|
const FeatureForm = require('./FeatureForm');
|
|
|
|
const FeatureActions = require('../../stores/FeatureToggleActions');
|
|
|
|
const ErrorActions = require('../../stores/ErrorActions');
|
2014-10-30 18:25:38 +01:00
|
|
|
|
2016-06-18 21:53:18 +02:00
|
|
|
const FeatureTogglesComponent = React.createClass({
|
2016-07-02 11:54:50 +02:00
|
|
|
getInitialState () {
|
2014-10-30 18:25:38 +01:00
|
|
|
return {
|
2016-06-18 21:55:46 +02:00
|
|
|
createView: false,
|
2014-10-30 18:25:38 +01:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
updateFeature (feature) {
|
2016-06-18 21:55:46 +02:00
|
|
|
FeatureActions.update.triggerPromise(feature);
|
2014-10-31 12:25:18 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
archiveFeature (feature) {
|
2015-03-17 20:29:03 +01:00
|
|
|
FeatureActions.archive.triggerPromise(feature);
|
2014-12-15 22:40:07 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
createFeature (feature) {
|
2015-03-03 19:27:17 +01:00
|
|
|
FeatureActions.create.triggerPromise(feature)
|
2015-03-17 20:29:03 +01:00
|
|
|
.then(this.cancelNewFeature);
|
2014-10-30 18:25:38 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
newFeature () {
|
2016-06-18 21:55:46 +02:00
|
|
|
this.setState({ createView: true });
|
2014-10-30 18:25:38 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
cancelNewFeature () {
|
2016-06-18 21:55:46 +02:00
|
|
|
this.setState({ createView: false });
|
2015-03-17 20:29:03 +01:00
|
|
|
ErrorActions.clear();
|
2014-11-10 14:55:56 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
render () {
|
2014-10-30 18:25:38 +01:00
|
|
|
return (
|
|
|
|
<div>
|
2014-11-03 13:54:06 +01:00
|
|
|
|
2015-03-28 09:51:31 +01:00
|
|
|
<h1>Feature Toggles</h1>
|
|
|
|
|
2014-11-03 13:54:06 +01:00
|
|
|
{this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
|
|
|
|
|
2014-11-01 14:52:37 +01:00
|
|
|
<FeatureList
|
2015-03-27 22:19:56 +01:00
|
|
|
features={this.props.features}
|
2014-11-03 13:19:32 +01:00
|
|
|
onFeatureChanged={this.updateFeature}
|
2014-12-15 22:40:07 +01:00
|
|
|
onFeatureArchive={this.archiveFeature}
|
2014-11-03 13:19:32 +01:00
|
|
|
onFeatureSubmit={this.createFeature}
|
|
|
|
onFeatureCancel={this.cancelNewFeature}
|
2015-03-17 22:01:46 +01:00
|
|
|
onNewFeature={this.newFeature}
|
2015-03-27 22:19:56 +01:00
|
|
|
strategies={this.props.strategies} />
|
2014-10-30 18:25:38 +01:00
|
|
|
</div>
|
|
|
|
);
|
2014-11-03 13:54:06 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
renderCreateView () {
|
2016-06-18 21:55:46 +02:00
|
|
|
return (<FeatureForm
|
2015-03-17 22:01:46 +01:00
|
|
|
onCancel={this.cancelNewFeature}
|
|
|
|
onSubmit={this.createFeature}
|
2016-06-18 21:55:46 +02:00
|
|
|
strategies={this.props.strategies} />);
|
2014-11-03 13:54:06 +01:00
|
|
|
},
|
|
|
|
|
2016-07-02 11:54:50 +02:00
|
|
|
renderCreateButton () {
|
2015-03-17 20:29:03 +01:00
|
|
|
return <button className="mal" onClick={this.newFeature}>Create feature toggle</button>;
|
2016-06-18 21:55:46 +02:00
|
|
|
},
|
2014-10-30 18:25:38 +01:00
|
|
|
});
|
|
|
|
|
2015-03-02 21:48:42 +01:00
|
|
|
module.exports = FeatureTogglesComponent;
|