var React = require('react'); var TextInput = require('../form/TextInput'); var strategyStore = require('../../stores/StrategyStore'); var FeatureForm = React.createClass({ getInitialState: function() { return { strategyOptions: [], requiredParams: [], currentStrategy: this.props.feature ? this.props.feature.strategy : "default" }; }, componentWillMount: function() { strategyStore.getStrategies().then(this.handleStrategyResponse); }, handleStrategyResponse: function(response) { 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() { var feature = this.props.feature || { name: '', strategy: 'default', enabled: false }; return (