1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/public/js/components/strategy/StrategiesComponent.jsx
2020-02-20 08:30:23 +01:00

62 lines
1.7 KiB
JavaScript

var React = require('react');
var StrategyList = require('./StrategyList');
var StrategyForm = require('./StrategyForm');
var StrategyActions = require('../../stores/StrategyActions');
var StrategiesComponent = React.createClass({
getInitialState: function() {
return {
createView: false
};
},
onNewStrategy: function() {
this.setState({createView: true});
},
onCancelNewStrategy: function() {
this.setState({createView: false});
},
onSave: function(strategy) {
StrategyActions.create.triggerPromise(strategy)
.then(this.onCancelNewStrategy);
},
onRemove: function(strategy) {
StrategyActions.remove.triggerPromise(strategy);
},
render: function() {
return (
<div>
<h1>Activation Strategies</h1>
{this.state.createView ?
this.renderCreateView() : this.renderCreateButton()}
<hr />
<StrategyList
strategies={this.props.strategies}
onRemove={this.onRemove} />
</div>
);
},
renderCreateView: function() {
return (
<StrategyForm
onCancelNewStrategy={this.onCancelNewStrategy}
onSave={this.onSave}
/>);
},
renderCreateButton: function() {
return (
<button className="mal" onClick={this.onNewStrategy}>
Create strategy
</button>
);
}
});
module.exports = StrategiesComponent;