Skip to content

Commit

Permalink
Add the ability to cancel the new feature form.
Browse files Browse the repository at this point in the history
  • Loading branch information
jarib authored and ivarconr committed Feb 20, 2020
1 parent 9a58973 commit dcb6215
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions unleash-server/public/js/unleash.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,13 @@ var UnsavedFeature = React.createClass({
</div>

<div className="form-group col-md-1">
<button type="submit" className="btn btn-primary btn-xs" onClick={this.saveFeature}>
<button className="btn btn-primary btn-xs" onClick={this.saveFeature}>
Save
</button>

<button className="btn btn-xs" onClick={this.cancelFeature}>
Cancel
</button>
</div>

</form>
Expand All @@ -97,6 +101,11 @@ var UnsavedFeature = React.createClass({
this.props.feature.enabled = this.refs.enabled.getDOMNode().checked;

this.props.onSubmit(this.props.feature);
},

cancelFeature: function(e) {
e.preventDefault();
this.props.onCancel(this.props.feature);
}
});

Expand Down Expand Up @@ -139,7 +148,8 @@ var FeatureList = React.createClass({
<UnsavedFeature
key={key}
feature={feature}
onSubmit={this.props.onFeatureSubmit} />
onSubmit={this.props.onFeatureSubmit}
onCancel={this.props.onFeatureCancel} />
);
}.bind(this));

Expand Down Expand Up @@ -281,6 +291,18 @@ var Unleash = React.createClass({
this.forceUpdate();
},

cancelNewFeature: function (feature) {
var unsaved = [];

this.state.unsavedFeatures.forEach(function (f) {
if (f.name !== feature.name) {
unsaved.push(f);
}
});

this.setState({unsavedFeatures: unsaved});
},

render: function() {
return (
<div>
Expand All @@ -291,6 +313,7 @@ var Unleash = React.createClass({
savedFeatures={this.state.savedFeatures}
onFeatureChanged={this.updateFeature}
onFeatureSubmit={this.createFeature}
onFeatureCancel={this.cancelNewFeature}
onNewFeature={this.newFeature}
/>
</div>
Expand Down

0 comments on commit dcb6215

Please sign in to comment.