-
+
@@ -16,7 +16,6 @@ var UnsavedFeature = React.createClass({
className="mbs"
id="name"
ref="name"
- defaultValue={this.props.feature.name}
placeholder="Enter name" />
+ defaultValue="default">
@@ -51,18 +50,20 @@ var UnsavedFeature = React.createClass({
saveFeature: function(e) {
e.preventDefault();
- this.props.feature.name = this.refs.name.getDOMNode().value;
- this.props.feature.description = this.refs.description.getDOMNode().value;
- this.props.feature.strategy = this.refs.strategy.getDOMNode().value;
- this.props.feature.enabled = this.refs.enabled.getDOMNode().checked;
+ var feature = {
+ name: this.refs.name.getDOMNode().value,
+ description: this.refs.description.getDOMNode().value,
+ strategy: this.refs.strategy.getDOMNode().value,
+ enabled: this.refs.enabled.getDOMNode().checked
+ }
- this.props.onSubmit(this.props.feature);
+ this.props.onSubmit(feature);
},
cancelFeature: function(e) {
e.preventDefault();
- this.props.onCancel(this.props.feature);
+ this.props.onCancel();
}
});
-module.exports = UnsavedFeature;
\ No newline at end of file
+module.exports = FeatureForm;
\ No newline at end of file
diff --git a/public/js/components/feature/FeatureList.jsx b/public/js/components/feature/FeatureList.jsx
index b7ff973982..ccda9aa0a9 100644
--- a/public/js/components/feature/FeatureList.jsx
+++ b/public/js/components/feature/FeatureList.jsx
@@ -1,47 +1,18 @@
-var React = require('react');
-var SavedFeature = require('./SavedFeature');
-var UnsavedFeature = require('./UnsavedFeature');
+var React = require('react');
+var Feature = require('./Feature');
var FeatureList = React.createClass({
render: function() {
- var featureNodes = [];
-
- this.props.unsavedFeatures.forEach(function(feature, idx) {
- var key = 'new-' + idx;
- featureNodes.push(
-
- );
- }.bind(this));
-
- this.props.savedFeatures.forEach(function(feature) {
- featureNodes.push(
-
);
}.bind(this));
- return (
-
-
-
-
Features
-
-
-
-
-
-
-
-
- {featureNodes}
-
- );
+ return
{featureNodes}
;
}
});
diff --git a/public/js/components/feature/FeatureToggleComponent.jsx b/public/js/components/feature/FeatureToggleComponent.jsx
index 1259cd30f4..10b189091c 100644
--- a/public/js/components/feature/FeatureToggleComponent.jsx
+++ b/public/js/components/feature/FeatureToggleComponent.jsx
@@ -2,14 +2,15 @@ var React = require('react');
var Timer = require('../../utils/Timer');
var ErrorMessages = require('../ErrorMessages');
var FeatureList = require('./FeatureList');
+var FeatureForm = require('./FeatureForm');
var FeatureStore = require('../../stores/FeatureStore');
var FeatureToggleComponent = React.createClass({
getInitialState: function() {
return {
- savedFeatures: [],
- unsavedFeatures: [],
+ features: [],
errors: [],
+ createView: false,
featurePoller: new Timer(this.loadFeaturesFromServer, this.props.pollInterval),
featureStore: new FeatureStore()
};
@@ -29,7 +30,7 @@ var FeatureToggleComponent = React.createClass({
},
setFeatures: function (data) {
- this.setState({savedFeatures: data.features});
+ this.setState({features: data.features});
},
handleError: function (error) {
@@ -38,7 +39,7 @@ var FeatureToggleComponent = React.createClass({
},
updateFeature: function (changeRequest) {
- var newFeatures = this.state.savedFeatures;
+ var newFeatures = this.state.features;
newFeatures.forEach(function(f){
if(f.name === changeRequest.name) {
f[changeRequest.field] = changeRequest.value;
@@ -63,49 +64,17 @@ var FeatureToggleComponent = React.createClass({
},
createFeature: function (feature) {
- var created = function() {
- var unsaved = [], state = this.state;
-
- this.state.unsavedFeatures.forEach(function(f) {
- // TODO: make sure we don't overwrite an existing feature
- if (f.name === feature.name) {
- state.savedFeatures.unshift(f);
- } else {
- unsaved.push(f);
- }
- });
-
- this.setState({unsavedFeatures: unsaved});
- }.bind(this);
-
-
this.state.featureStore.createFeature(feature)
- .then(created)
+ .then(this.cancelNewFeature)
.catch(this.handleError);
},
newFeature: function() {
- var blankFeature = {
- name: '',
- enabled: false,
- strategy: 'default',
- parameters: {}
- };
-
- this.state.unsavedFeatures.push(blankFeature);
- this.forceUpdate();
+ this.setState({createView: true});
},
cancelNewFeature: function (feature) {
- var unsaved = [];
-
- this.state.unsavedFeatures.forEach(function (f) {
- if (f.name !== feature.name) {
- unsaved.push(f);
- }
- });
-
- this.setState({unsavedFeatures: unsaved});
+ this.setState({createView: false});
},
clearErrors: function() {
@@ -118,16 +87,30 @@ var FeatureToggleComponent = React.createClass({
+
+ {this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
+
+
+
);
+ },
+
+ renderCreateView: function() {
+ return