1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/public/js/components/feature/Feature.jsx

93 lines
2.6 KiB
React
Raw Normal View History

2014-10-30 18:25:38 +01:00
var React = require('react');
var FeatureForm = require('./FeatureForm');
2014-11-17 11:15:10 +01:00
var LogEntryList = require('../log/LogEntryList');
var eventStore = require('../../stores/EventStore');
2014-10-30 18:25:38 +01:00
2014-11-03 13:54:06 +01:00
var Feature = React.createClass({
getInitialState: function() {
return {
2014-11-17 11:15:10 +01:00
editMode: false,
showHistory: false,
events: []
};
},
2014-11-17 11:15:10 +01:00
handleEventsResponse: function(response) {
this.setState({events: response});
},
toggleHistory: function() {
eventStore.getEventsByName(this.props.feature.name).then(this.handleEventsResponse);
this.setState({showHistory: !this.state.showHistory});
},
toggleEditMode: function() {
this.setState({editMode: !this.state.editMode});
},
saveFeature: function(feature) {
this.props.onChange(feature);
this.toggleEditMode();
2014-10-30 18:25:38 +01:00
},
render: function() {
return this.state.editMode ? this.renderEditMode() : this.renderViewMode();
},
2014-10-31 10:30:23 +01:00
renderEditMode: function() {
return (
<tr>
2014-11-13 19:55:34 +01:00
<td colSpan="5">
<FeatureForm feature={this.props.feature} onSubmit={this.saveFeature} onCancel={this.toggleEditMode} />
</td>
</tr>
);
},
renderViewMode: function() {
return (
2014-11-17 11:15:10 +01:00
<tbody>
<tr>
<td width="20">
<span className={this.props.feature.enabled ? "toggle-active" : "toggle-inactive"} title="Status">
</span>
</td>
<td>
{this.props.feature.name}
</td>
2014-10-31 10:30:23 +01:00
2014-11-17 11:15:10 +01:00
<td className='opaque smalltext word-break' width="600">
{this.props.feature.description || '\u00a0'}
</td>
2014-11-10 16:21:22 +01:00
2014-11-17 11:15:10 +01:00
<td>
{this.props.feature.strategy}
</td>
2014-11-25 13:54:25 +01:00
<td>
<input className="mrs mbs" type='button' value='Edit' onClick={this.toggleEditMode}/>
2014-11-17 11:15:10 +01:00
<input type='button' value='History' onClick={this.toggleHistory} />
</td>
</tr>
{this.state.showHistory ? this.renderHistory() : this.renderEmptyRow()}
</tbody>
2014-10-30 18:25:38 +01:00
);
2014-11-17 11:15:10 +01:00
},
renderEmptyRow: function() {
return (<tr />);
},
renderHistory: function() {
return (<tr>
<td colSpan="5"><LogEntryList events={this.state.events} /></td>
</tr>);
2014-10-30 18:25:38 +01:00
}
2014-11-17 11:15:10 +01:00
2014-10-30 18:25:38 +01:00
});
2014-11-03 13:54:06 +01:00
module.exports = Feature;