'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 (feature) { if (this.props.feature && this.props.feature.parameters) { return this.props.feature.parameters[feature]; } return ''; }, setSelectedStrategy (strategyName) { const selectedStrategy = this.props.strategies.filter(strategy => strategy.name === strategyName)[0]; if (selectedStrategy) { this.setStrategyParams(selectedStrategy); } else { this.setState({ currentStrategy: 'default', requiredParams: [], }); } }, setStrategyParams (strategy) { const requiredParams = []; let key; for (key in strategy.parametersTemplate) { if (Object.hasOwnProperty.call(strategy.parametersTemplate, key)) { 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 (