From 8cacf42dd2f564c9192fbce8ebf7e628cfcfb2d5 Mon Sep 17 00:00:00 2001 From: Jari Bakken Date: Mon, 3 Nov 2014 13:54:06 +0100 Subject: [PATCH] Get rid of 'unsaved features' --- .../feature/{SavedFeature.jsx => Feature.jsx} | 4 +- .../{UnsavedFeature.jsx => FeatureForm.jsx} | 23 +++---- public/js/components/feature/FeatureList.jsx | 41 ++---------- .../feature/FeatureToggleComponent.jsx | 65 +++++++------------ .../components/strategy/StrategyComponent.jsx | 6 +- 5 files changed, 46 insertions(+), 93 deletions(-) rename public/js/components/feature/{SavedFeature.jsx => Feature.jsx} (92%) rename public/js/components/feature/{UnsavedFeature.jsx => FeatureForm.jsx} (69%) diff --git a/public/js/components/feature/SavedFeature.jsx b/public/js/components/feature/Feature.jsx similarity index 92% rename from public/js/components/feature/SavedFeature.jsx rename to public/js/components/feature/Feature.jsx index 939582d542..0c6129c368 100644 --- a/public/js/components/feature/SavedFeature.jsx +++ b/public/js/components/feature/Feature.jsx @@ -1,6 +1,6 @@ var React = require('react'); -var SavedFeature = React.createClass({ +var Feature = React.createClass({ onChange: function(event) { this.props.onChange({ name: this.props.feature.name, @@ -28,4 +28,4 @@ var SavedFeature = React.createClass({ } }); -module.exports = SavedFeature; \ No newline at end of file +module.exports = Feature; \ No newline at end of file diff --git a/public/js/components/feature/UnsavedFeature.jsx b/public/js/components/feature/FeatureForm.jsx similarity index 69% rename from public/js/components/feature/UnsavedFeature.jsx rename to public/js/components/feature/FeatureForm.jsx index 7a756401b1..6af2d078e3 100644 --- a/public/js/components/feature/UnsavedFeature.jsx +++ b/public/js/components/feature/FeatureForm.jsx @@ -1,13 +1,13 @@ var React = require('react'); -var UnsavedFeature = React.createClass({ +var FeatureForm = React.createClass({ render: function() { return (
- +
@@ -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 + }, + + renderCreateButton: function() { + return } }); + + module.exports = FeatureToggleComponent; \ No newline at end of file diff --git a/public/js/components/strategy/StrategyComponent.jsx b/public/js/components/strategy/StrategyComponent.jsx index 2549f4328d..5688af2b5d 100644 --- a/public/js/components/strategy/StrategyComponent.jsx +++ b/public/js/components/strategy/StrategyComponent.jsx @@ -69,10 +69,8 @@ var StrategyComponent = React.createClass({ renderCreateButton: function() { return ( -

- -

- ); + + ); } });