1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/packages/unleash-frontend/public/js/components/strategy/StrategiesComponent.jsx

63 lines
1.6 KiB
React
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const React = require('react');
const StrategyList = require('./StrategyList');
const StrategyForm = require('./StrategyForm');
const StrategyActions = require('../../stores/StrategyActions');
const StrategiesComponent = React.createClass({
getInitialState() {
return {
2016-06-18 21:55:46 +02:00
createView: false,
};
},
2016-06-18 21:53:18 +02:00
onNewStrategy() {
2016-06-18 21:55:46 +02:00
this.setState({ createView: true });
},
2016-06-18 21:53:18 +02:00
onCancelNewStrategy() {
2016-06-18 21:55:46 +02:00
this.setState({ createView: false });
},
2016-06-18 21:53:18 +02:00
onSave(strategy) {
2015-03-17 22:01:46 +01:00
StrategyActions.create.triggerPromise(strategy)
.then(this.onCancelNewStrategy);
},
2016-06-18 21:53:18 +02:00
onRemove(strategy) {
2015-03-17 22:01:46 +01:00
StrategyActions.remove.triggerPromise(strategy);
2014-12-09 09:22:54 +01:00
},
2016-06-18 21:53:18 +02:00
render() {
return (
<div>
2015-03-28 09:51:31 +01:00
<h1>Activation Strategies</h1>
2015-03-17 22:01:46 +01:00
{this.state.createView ?
this.renderCreateView() : this.renderCreateButton()}
<hr />
2015-03-17 20:29:03 +01:00
<StrategyList
strategies={this.props.strategies}
2015-03-17 20:29:03 +01:00
onRemove={this.onRemove} />
</div>
2015-03-17 20:29:03 +01:00
);
},
2016-06-18 21:53:18 +02:00
renderCreateView() {
2015-03-17 20:29:03 +01:00
return (
<StrategyForm
onCancelNewStrategy={this.onCancelNewStrategy}
onSave={this.onSave}
/>);
2016-06-18 21:55:46 +02:00
},
2015-03-17 22:01:46 +01:00
2016-06-18 21:55:46 +02:00
renderCreateButton() {
return (
2015-03-17 22:01:46 +01:00
<button className="mal" onClick={this.onNewStrategy}>
Create strategy
</button>
);
2016-06-18 21:55:46 +02:00
},
});
2015-03-17 22:01:46 +01:00
2016-06-18 21:53:18 +02:00
module.exports = StrategiesComponent;