From ff4beac7f78a0f6751049fb92fc9b8a535db5f5f Mon Sep 17 00:00:00 2001 From: Gard Rimestad Date: Wed, 12 Nov 2014 15:00:11 +0100 Subject: [PATCH] admin - Edit button for existing features --- public/js/components/feature/Feature.jsx | 44 +++++++++++++++----- public/js/components/feature/FeatureForm.jsx | 24 +++++++++-- 2 files changed, 54 insertions(+), 14 deletions(-) diff --git a/public/js/components/feature/Feature.jsx b/public/js/components/feature/Feature.jsx index 823b03debd..26b5e7cee8 100644 --- a/public/js/components/feature/Feature.jsx +++ b/public/js/components/feature/Feature.jsx @@ -1,22 +1,42 @@ var React = require('react'); +var FeatureForm = require('./FeatureForm'); var Feature = React.createClass({ - onChange: function(event) { + getInitialState: function() { + return { + editMode: false + }; + }, + + toggleEditMode: function() { + this.setState({editMode: !this.state.editMode}); + }, + + saveFeature: function(feature) { this.props.onChange({ - name: this.props.feature.name, + name: feature.name, field: 'enabled', - value: event.target.checked + value: feature.enabled }); + this.toggleEditMode(); }, render: function() { - return ( -
-
- -
+ return (
+ {this.state.editMode ? this.renderEditMode() : this.renderViewMode()} +
); + }, -
+ renderEditMode: function() { + return (); + + }, + + renderViewMode: function() { + var strikeThrough = this.props.feature.enabled ? '' : 'strikethrough'; + return ( +
+
{this.props.feature.name}
@@ -24,9 +44,13 @@ var Feature = React.createClass({ {this.props.feature.description || '\u00a0'}
-
+
{this.props.feature.strategy}
+ +
+ +
); } diff --git a/public/js/components/feature/FeatureForm.jsx b/public/js/components/feature/FeatureForm.jsx index b1af41b323..037f6f0032 100644 --- a/public/js/components/feature/FeatureForm.jsx +++ b/public/js/components/feature/FeatureForm.jsx @@ -6,7 +6,7 @@ var FeatureForm = React.createClass({ return {strategyOptions: []}; }, - componentDidMount: function() { + componentWillMount: function() { strategyStore.getStrategies().then(this.handleStrategyResponse); }, @@ -19,16 +19,27 @@ var FeatureForm = React.createClass({ }, render: function() { + var currentStrategy = this.props.feature ? this.props.feature.strategy : ""; var strategyNodes = this.state.strategyOptions.map(function(name) { - return ; + return ( + + ); }); + var feature = this.props.feature || { + name: '', + strategy: 'default', + enabled: false + }; + return (
- +
@@ -37,11 +48,15 @@ var FeatureForm = React.createClass({ className="mbs" id="name" ref="name" + disabled={feature.name.length} + defaultValue={feature.name} placeholder="Enter name" />
@@ -49,7 +64,8 @@ var FeatureForm = React.createClass({