From 0a0515e13988618b9ce300934c807628d8aeb65a Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Sat, 29 Nov 2014 13:37:06 +0100 Subject: [PATCH] When user chooses to use a custom strategy she should get an input field for each strategy parameter. closes #53 --- public/js/components/TabView.jsx | 4 +- public/js/components/feature/FeatureForm.jsx | 82 ++++++++++++++++--- public/js/components/feature/FeatureList.jsx | 4 +- .../feature/FeatureTogglesComponent.jsx | 2 - public/js/components/log/LogEntryList.jsx | 2 +- 5 files changed, 75 insertions(+), 19 deletions(-) diff --git a/public/js/components/TabView.jsx b/public/js/components/TabView.jsx index dc031a68a7..9211791405 100644 --- a/public/js/components/TabView.jsx +++ b/public/js/components/TabView.jsx @@ -43,8 +43,8 @@ var TabView = React.createClass({
-
-
+
+
{this.state.activeTab.content}
diff --git a/public/js/components/feature/FeatureForm.jsx b/public/js/components/feature/FeatureForm.jsx index 51055b4490..70915fd20d 100644 --- a/public/js/components/feature/FeatureForm.jsx +++ b/public/js/components/feature/FeatureForm.jsx @@ -4,7 +4,11 @@ var strategyStore = require('../../stores/StrategyStore'); var FeatureForm = React.createClass({ getInitialState: function() { - return {strategyOptions: []}; + return { + strategyOptions: [], + requiredParams: [], + currentStrategy: this.props.feature ? this.props.feature.strategy : "default" + }; }, componentWillMount: function() { @@ -12,8 +16,40 @@ var FeatureForm = React.createClass({ }, handleStrategyResponse: function(response) { - var strategyNames = response.strategies.map(function(s) { return s.name; }); - this.setState({strategyOptions: strategyNames}); + this.setState({strategyOptions: response.strategies}); + if(this.props.feature) { + this.setSelectedStrategy(this.props.feature.strategy); + } + }, + + onStrategyChange: function(e) { + this.setSelectedStrategy(e.target.value); + this.setState({currentStrategy: e.target.value}); + }, + + getParameterValue: function(name) { + if(this.props.feature && this.props.feature.parameters) { + return this.props.feature.parameters[name]; + } else { + return ""; + } + }, + + setSelectedStrategy: function(name) { + var selected = this.state.strategyOptions.filter(function(strategy) { + return strategy.name === name; + }); + + var requiredParams = []; + var key; + + if(selected[0] && selected[0].parametersTemplate) { + for(key in selected[0].parametersTemplate) { + requiredParams.push({name: key, value: this.getParameterValue(key)}); + } + } + this.setState({requiredParams: requiredParams}); + }, render: function() { @@ -49,8 +85,8 @@ var FeatureForm = React.createClass({
-
- {this.renderStrategyOptions()}
@@ -66,6 +102,9 @@ var FeatureForm = React.createClass({
+ + {this.renderStrategyProperties()} +
@@ -78,14 +117,24 @@ var FeatureForm = React.createClass({ }, renderStrategyOptions: function() { - var currentStrategy = this.props.feature ? this.props.feature.strategy : "default"; - - return this.state.strategyOptions.map(function(name) { + return this.state.strategyOptions.map(function(strategy) { return ( - ); + }.bind(this)); + }, + + renderStrategyProperties: function() { + return this.state.requiredParams.map(function(param) { + return }); }, @@ -95,8 +144,9 @@ var FeatureForm = React.createClass({ var feature = { name: this.refs.name.getValue(), description: this.refs.description.getValue(), - strategy: this.refs.strategy.getDOMNode().value, - enabled: this.refs.enabled.getDOMNode().checked + strategy: this.state.currentStrategy, + enabled: this.refs.enabled.getDOMNode().checked, + parameters: this.getParameters() }; this.props.onSubmit(feature); @@ -105,6 +155,14 @@ var FeatureForm = React.createClass({ cancelFeature: function(e) { e.preventDefault(); this.props.onCancel(); + }, + + getParameters: function() { + var parameters = {}; + this.state.requiredParams.forEach(function(param) { + parameters[param.name] = this.refs[param.name].getValue(); + }.bind(this)); + return parameters; } }); diff --git a/public/js/components/feature/FeatureList.jsx b/public/js/components/feature/FeatureList.jsx index 41afe41a0d..513782191c 100644 --- a/public/js/components/feature/FeatureList.jsx +++ b/public/js/components/feature/FeatureList.jsx @@ -13,8 +13,8 @@ var FeatureList = React.createClass({ }.bind(this)); return ( -
- +
+
diff --git a/public/js/components/feature/FeatureTogglesComponent.jsx b/public/js/components/feature/FeatureTogglesComponent.jsx index d4a0bf762b..47a2af6231 100644 --- a/public/js/components/feature/FeatureTogglesComponent.jsx +++ b/public/js/components/feature/FeatureTogglesComponent.jsx @@ -113,8 +113,6 @@ var FeatureTogglesComponent = React.createClass({ {this.state.createView ? this.renderCreateView() : this.renderCreateButton()} -
- ; }); return ( -
+