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/Feature.jsx

125 lines
4.2 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-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
},
2014-12-15 22:40:07 +01:00
archiveFeature: function() {
2015-03-23 18:47:23 +01:00
if (window.confirm("Are you sure you want to delete " + this.props.feature.name + "?")) {
2014-12-15 22:40:07 +01:00
this.props.onArchive(this.props.feature);
}
},
2014-10-31 10:30:23 +01:00
renderEditMode: function() {
return (
<tr>
<td colSpan="4" className="pan man no-border">
2015-03-17 22:01:46 +01:00
<FeatureForm
feature={this.props.feature}
onSubmit={this.saveFeature}
onCancel={this.toggleEditMode}
strategies={this.props.strategies} />
</td>
</tr>
);
},
2014-11-29 12:12:48 +01:00
render: function() {
return (
<tbody className="feature">
2014-11-29 12:12:48 +01:00
<tr className={this.state.editMode ? "edit bg-lilac-xlt" : ""}>
2014-11-17 11:15:10 +01:00
<td width="20">
2015-03-23 18:47:23 +01:00
<span className=
{this.props.feature.enabled ? "toggle-active" : "toggle-inactive"} title="Status">
2014-11-17 11:15:10 +01:00
</span>
</td>
<td>
{this.props.feature.name} <br />
<span className="opaque smalltext word-break">
{this.props.feature.description || '\u00a0'}
</span>
2014-11-17 11:15:10 +01:00
</td>
2014-11-10 16:21:22 +01:00
<td className="hide-lt480">
2014-11-17 11:15:10 +01:00
{this.props.feature.strategy}
</td>
2014-12-15 22:40:07 +01:00
<td width="150">
<div className="line">
2014-12-15 22:40:07 +01:00
<div className="unit size1of3">
2015-03-23 18:47:23 +01:00
<button
title='Archive'
onClick={this.archiveFeature}>
2014-12-15 22:40:07 +01:00
<span className="icon-kryss1" />
</button>
</div>
<div className="unit size1of3">
2015-03-23 18:47:23 +01:00
<button
className={this.state.editMode ? "primary" : ""}
title='Edit'
onClick={this.toggleEditMode}>
<span className="icon-redigere" />
</button>
</div>
2014-12-15 22:40:07 +01:00
<div className="unit size1of3">
2015-03-23 18:47:23 +01:00
<button
className={this.state.showHistory ? "primary" : ""}
title='History'
onClick={this.toggleHistory}>
<span className="icon-visning_liste" />
</button>
</div>
</div>
2014-11-17 11:15:10 +01:00
</td>
</tr>
2014-11-29 12:12:48 +01:00
{this.state.editMode ? this.renderEditMode() : this.renderEmptyRow()}
2014-11-17 11:15:10 +01:00
{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="4" className="no-border">
2014-11-29 12:12:48 +01:00
<LogEntryList events={this.state.events} />
</td>
2014-11-17 11:15:10 +01:00
</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
});
2015-03-17 22:01:46 +01:00
module.exports = Feature;