1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/public/js/components/feature/FeatureForm.jsx

106 lines
3.1 KiB
React
Raw Normal View History

2014-10-30 18:25:38 +01:00
var React = require('react');
2014-11-12 13:47:21 +01:00
var strategyStore = require('../../stores/StrategyStore');
2014-10-30 18:25:38 +01:00
2014-11-03 13:54:06 +01:00
var FeatureForm = React.createClass({
2014-11-12 13:47:21 +01:00
getInitialState: function() {
return {strategyOptions: []};
},
componentWillMount: function() {
2014-11-12 13:47:21 +01:00
strategyStore.getStrategies().then(this.handleStrategyResponse);
},
handleStrategyResponse: function(response) {
var strategyNames = response.strategies.map(function(strategy) {
return strategy.name;
});
this.setState({strategyOptions: strategyNames});
},
2014-10-30 18:25:38 +01:00
render: function() {
var currentStrategy = this.props.feature ? this.props.feature.strategy : "";
2014-11-12 13:47:21 +01:00
var strategyNodes = this.state.strategyOptions.map(function(name) {
return (
<option value={name} selected={name === currentStrategy}>
{name}
</option>
);
2014-11-12 13:47:21 +01:00
});
var feature = this.props.feature || {
name: '',
strategy: 'default',
enabled: false
};
2014-10-30 18:25:38 +01:00
return (
2014-10-31 10:30:23 +01:00
<form ref="form" className="bg-blue-xlt">
<div className="line mal ptl pbl">
<div className="unit prl r-size1of6">
<input ref="enabled" type="checkbox" defaultChecked={feature.enabled} />
2014-10-30 18:25:38 +01:00
</div>
2014-10-31 10:30:23 +01:00
<div className="unit r-size2of5">
2014-10-30 18:25:38 +01:00
<input
type="text"
2014-10-31 10:30:23 +01:00
className="mbs"
2014-10-30 18:25:38 +01:00
id="name"
ref="name"
disabled={feature.name.length}
defaultValue={feature.name}
2014-10-30 18:25:38 +01:00
placeholder="Enter name" />
2014-10-31 10:30:23 +01:00
<input className=""
type="text"
ref="description"
defaultValue={feature.description}
disabled={feature.name.length}
2014-10-31 10:30:23 +01:00
placeholder="Enter description" />
2014-10-30 18:25:38 +01:00
</div>
2014-10-31 10:30:23 +01:00
<div className="unit r-size2of6 plm">
2014-10-30 18:25:38 +01:00
<select id="strategy"
ref="strategy"
className=""
disabled={feature.name.length}
defaultValue={feature.strategy}>
2014-11-12 13:47:21 +01:00
{strategyNodes}
2014-10-30 18:25:38 +01:00
</select>
</div>
2014-11-10 14:56:38 +01:00
<div className="unit r-size1of6 rightify">
<button className="primary mrs" onClick={this.saveFeature}>
Save
</button>
2014-10-30 18:25:38 +01:00
2014-11-10 14:56:38 +01:00
<button className="" onClick={this.cancelFeature}>
Cancel
</button>
</div>
2014-10-31 10:30:23 +01:00
</div>
</form>
2014-10-30 18:25:38 +01:00
);
},
saveFeature: function(e) {
e.preventDefault();
2014-11-03 13:54:06 +01:00
var feature = {
name: this.refs.name.getDOMNode().value,
description: this.refs.description.getDOMNode().value,
strategy: this.refs.strategy.getDOMNode().value,
enabled: this.refs.enabled.getDOMNode().checked
}
2014-10-30 18:25:38 +01:00
2014-11-03 13:54:06 +01:00
this.props.onSubmit(feature);
2014-10-30 18:25:38 +01:00
},
cancelFeature: function(e) {
e.preventDefault();
2014-11-03 13:54:06 +01:00
this.props.onCancel();
2014-10-30 18:25:38 +01:00
}
});
2014-11-03 13:54:06 +01:00
module.exports = FeatureForm;