'use strict'; const React = require('react'); const TextInput = require('../form/TextInput'); const FeatureForm = React.createClass({ getInitialState() { return { strategyOptions: this.props.strategies, requiredParams: [], currentStrategy: this.props.feature ? this.props.feature.strategy : 'default', }; }, componentWillMount() { if (this.props.feature) { this.setSelectedStrategy(this.props.feature.strategy); } }, onStrategyChange(e) { this.setSelectedStrategy(e.target.value); this.setState({ currentStrategy: e.target.value }); }, getParameterValue(name) { if (this.props.feature && this.props.feature.parameters) { return this.props.feature.parameters[name]; } else { return ''; } }, setSelectedStrategy(name) { const selectedStrategy = this.props.strategies.filter(strategy => strategy.name === name)[0]; if (selectedStrategy) { this.setStrategyParams(selectedStrategy); } else { this.setState({ currentStrategy: 'default', requiredParams: [], }); } }, setStrategyParams(strategy) { const requiredParams = []; let key; for (key in strategy.parametersTemplate) { requiredParams.push({ name: key, value: this.getParameterValue(key) }); } this.setState({ requiredParams }); }, render() { const feature = this.props.feature || { name: '', strategy: 'default', enabled: false, }; const idPrefix = this.props.feature ? this.props.feature.name : 'new'; return (