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

124 lines
4.2 KiB
React
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const React = require('react');
const FeatureForm = require('./FeatureForm');
const LogEntryList = require('../log/LogEntryList');
const eventStore = require('../../stores/EventStore');
const Feature = React.createClass({
2016-07-02 11:54:50 +02:00
getInitialState () {
return {
2014-11-17 11:15:10 +01:00
editMode: false,
showHistory: false,
2016-06-18 21:55:46 +02:00
events: [],
};
},
2016-07-02 11:54:50 +02:00
handleEventsResponse (response) {
2016-06-18 21:55:46 +02:00
this.setState({ events: response });
2014-11-17 11:15:10 +01:00
},
2016-07-02 11:54:50 +02:00
toggleHistory () {
2014-11-17 11:15:10 +01:00
eventStore.getEventsByName(this.props.feature.name).then(this.handleEventsResponse);
2016-06-18 21:55:46 +02:00
this.setState({ showHistory: !this.state.showHistory });
2014-11-17 11:15:10 +01:00
},
2016-07-02 11:54:50 +02:00
toggleEditMode () {
2016-06-18 21:55:46 +02:00
this.setState({ editMode: !this.state.editMode });
},
2016-07-02 11:54:50 +02:00
saveFeature (feature) {
this.props.onChange(feature);
this.toggleEditMode();
2014-10-30 18:25:38 +01:00
},
2016-07-02 11:54:50 +02:00
archiveFeature () {
2016-06-18 22:23:19 +02:00
if (window.confirm(`Are you sure you want to delete ${this.props.feature.name}?`)) { // eslint-disable-line no-alert
2014-12-15 22:40:07 +01:00
this.props.onArchive(this.props.feature);
}
},
2014-10-31 10:30:23 +01:00
2016-07-02 11:54:50 +02:00
renderEditMode () {
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>
);
},
2016-07-02 11:54:50 +02:00
render () {
return (
<tbody className="feature">
2016-06-18 21:55:46 +02: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=
2016-08-25 13:24:14 +02:00
{this.props.feature.enabled ? 'toggle-active' : 'toggle-inactive'} title="Status" />
2014-11-17 11:15:10 +01:00
</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
2016-06-18 21:55:46 +02:00
title="Archive"
2015-03-23 18:47:23 +01:00
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
2016-06-18 21:55:46 +02:00
className={this.state.editMode ? 'primary' : ''}
title="Edit"
2015-03-23 18:47:23 +01:00
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
2016-06-18 21:55:46 +02:00
className={this.state.showHistory ? 'primary' : ''}
title="History"
2015-03-23 18:47:23 +01:00
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
},
2016-07-02 11:54:50 +02:00
renderEmptyRow () {
2014-11-17 11:15:10 +01:00
return (<tr />);
},
2016-07-02 11:54:50 +02:00
renderHistory () {
2014-11-17 11:15:10 +01:00
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>);
2016-06-18 21:55:46 +02: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;