mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-20 00:08:02 +01:00
Get rid of 'unsaved features'
This commit is contained in:
parent
32f50fa116
commit
8cacf42dd2
@ -1,6 +1,6 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
|
|
||||||
var SavedFeature = React.createClass({
|
var Feature = React.createClass({
|
||||||
onChange: function(event) {
|
onChange: function(event) {
|
||||||
this.props.onChange({
|
this.props.onChange({
|
||||||
name: this.props.feature.name,
|
name: this.props.feature.name,
|
||||||
@ -28,4 +28,4 @@ var SavedFeature = React.createClass({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = SavedFeature;
|
module.exports = Feature;
|
@ -1,13 +1,13 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
|
|
||||||
var UnsavedFeature = React.createClass({
|
var FeatureForm = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
return (
|
return (
|
||||||
<form ref="form" className="bg-blue-xlt">
|
<form ref="form" className="bg-blue-xlt">
|
||||||
<div className="line mal ptl pbl">
|
<div className="line mal ptl pbl">
|
||||||
|
|
||||||
<div className="unit prl r-size1of6">
|
<div className="unit prl r-size1of6">
|
||||||
<input ref="enabled" type="checkbox" defaultValue={this.props.feature.enabled} />
|
<input ref="enabled" type="checkbox" defaultValue={false} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="unit r-size2of5">
|
<div className="unit r-size2of5">
|
||||||
@ -16,7 +16,6 @@ var UnsavedFeature = React.createClass({
|
|||||||
className="mbs"
|
className="mbs"
|
||||||
id="name"
|
id="name"
|
||||||
ref="name"
|
ref="name"
|
||||||
defaultValue={this.props.feature.name}
|
|
||||||
placeholder="Enter name" />
|
placeholder="Enter name" />
|
||||||
|
|
||||||
<input className=""
|
<input className=""
|
||||||
@ -29,7 +28,7 @@ var UnsavedFeature = React.createClass({
|
|||||||
<select id="strategy"
|
<select id="strategy"
|
||||||
ref="strategy"
|
ref="strategy"
|
||||||
className=""
|
className=""
|
||||||
defaultValue={this.props.feature.strategy}>
|
defaultValue="default">
|
||||||
<option value="default">default</option>
|
<option value="default">default</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
@ -51,18 +50,20 @@ var UnsavedFeature = React.createClass({
|
|||||||
saveFeature: function(e) {
|
saveFeature: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
this.props.feature.name = this.refs.name.getDOMNode().value;
|
var feature = {
|
||||||
this.props.feature.description = this.refs.description.getDOMNode().value;
|
name: this.refs.name.getDOMNode().value,
|
||||||
this.props.feature.strategy = this.refs.strategy.getDOMNode().value;
|
description: this.refs.description.getDOMNode().value,
|
||||||
this.props.feature.enabled = this.refs.enabled.getDOMNode().checked;
|
strategy: this.refs.strategy.getDOMNode().value,
|
||||||
|
enabled: this.refs.enabled.getDOMNode().checked
|
||||||
|
}
|
||||||
|
|
||||||
this.props.onSubmit(this.props.feature);
|
this.props.onSubmit(feature);
|
||||||
},
|
},
|
||||||
|
|
||||||
cancelFeature: function(e) {
|
cancelFeature: function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
this.props.onCancel(this.props.feature);
|
this.props.onCancel();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
module.exports = UnsavedFeature;
|
module.exports = FeatureForm;
|
@ -1,47 +1,18 @@
|
|||||||
var React = require('react');
|
var React = require('react');
|
||||||
var SavedFeature = require('./SavedFeature');
|
var Feature = require('./Feature');
|
||||||
var UnsavedFeature = require('./UnsavedFeature');
|
|
||||||
|
|
||||||
var FeatureList = React.createClass({
|
var FeatureList = React.createClass({
|
||||||
render: function() {
|
render: function() {
|
||||||
var featureNodes = [];
|
var featureNodes = this.props.features.map(function(feature) {
|
||||||
|
return (
|
||||||
this.props.unsavedFeatures.forEach(function(feature, idx) {
|
<Feature
|
||||||
var key = 'new-' + idx;
|
|
||||||
featureNodes.push(
|
|
||||||
<UnsavedFeature
|
|
||||||
key={key}
|
|
||||||
feature={feature}
|
|
||||||
onSubmit={this.props.onFeatureSubmit}
|
|
||||||
onCancel={this.props.onFeatureCancel} />
|
|
||||||
);
|
|
||||||
}.bind(this));
|
|
||||||
|
|
||||||
this.props.savedFeatures.forEach(function(feature) {
|
|
||||||
featureNodes.push(
|
|
||||||
<SavedFeature
|
|
||||||
key={feature.name}
|
key={feature.name}
|
||||||
feature={feature}
|
feature={feature}
|
||||||
onChange={this.props.onFeatureChanged} />
|
onChange={this.props.onFeatureChanged} />
|
||||||
);
|
);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
||||||
return (
|
return <div>{featureNodes}</div>;
|
||||||
<div>
|
|
||||||
<div className="line">
|
|
||||||
<div className="unit r-size1of4">
|
|
||||||
<h2>Features</h2>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="unit r-size3of4 rightify prl ptm">
|
|
||||||
<button className="" onClick={this.props.onNewFeature}>New</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<hr />
|
|
||||||
{featureNodes}
|
|
||||||
</div>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -2,14 +2,15 @@ var React = require('react');
|
|||||||
var Timer = require('../../utils/Timer');
|
var Timer = require('../../utils/Timer');
|
||||||
var ErrorMessages = require('../ErrorMessages');
|
var ErrorMessages = require('../ErrorMessages');
|
||||||
var FeatureList = require('./FeatureList');
|
var FeatureList = require('./FeatureList');
|
||||||
|
var FeatureForm = require('./FeatureForm');
|
||||||
var FeatureStore = require('../../stores/FeatureStore');
|
var FeatureStore = require('../../stores/FeatureStore');
|
||||||
|
|
||||||
var FeatureToggleComponent = React.createClass({
|
var FeatureToggleComponent = React.createClass({
|
||||||
getInitialState: function() {
|
getInitialState: function() {
|
||||||
return {
|
return {
|
||||||
savedFeatures: [],
|
features: [],
|
||||||
unsavedFeatures: [],
|
|
||||||
errors: [],
|
errors: [],
|
||||||
|
createView: false,
|
||||||
featurePoller: new Timer(this.loadFeaturesFromServer, this.props.pollInterval),
|
featurePoller: new Timer(this.loadFeaturesFromServer, this.props.pollInterval),
|
||||||
featureStore: new FeatureStore()
|
featureStore: new FeatureStore()
|
||||||
};
|
};
|
||||||
@ -29,7 +30,7 @@ var FeatureToggleComponent = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
setFeatures: function (data) {
|
setFeatures: function (data) {
|
||||||
this.setState({savedFeatures: data.features});
|
this.setState({features: data.features});
|
||||||
},
|
},
|
||||||
|
|
||||||
handleError: function (error) {
|
handleError: function (error) {
|
||||||
@ -38,7 +39,7 @@ var FeatureToggleComponent = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
updateFeature: function (changeRequest) {
|
updateFeature: function (changeRequest) {
|
||||||
var newFeatures = this.state.savedFeatures;
|
var newFeatures = this.state.features;
|
||||||
newFeatures.forEach(function(f){
|
newFeatures.forEach(function(f){
|
||||||
if(f.name === changeRequest.name) {
|
if(f.name === changeRequest.name) {
|
||||||
f[changeRequest.field] = changeRequest.value;
|
f[changeRequest.field] = changeRequest.value;
|
||||||
@ -63,49 +64,17 @@ var FeatureToggleComponent = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
createFeature: function (feature) {
|
createFeature: function (feature) {
|
||||||
var created = function() {
|
|
||||||
var unsaved = [], state = this.state;
|
|
||||||
|
|
||||||
this.state.unsavedFeatures.forEach(function(f) {
|
|
||||||
// TODO: make sure we don't overwrite an existing feature
|
|
||||||
if (f.name === feature.name) {
|
|
||||||
state.savedFeatures.unshift(f);
|
|
||||||
} else {
|
|
||||||
unsaved.push(f);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({unsavedFeatures: unsaved});
|
|
||||||
}.bind(this);
|
|
||||||
|
|
||||||
|
|
||||||
this.state.featureStore.createFeature(feature)
|
this.state.featureStore.createFeature(feature)
|
||||||
.then(created)
|
.then(this.cancelNewFeature)
|
||||||
.catch(this.handleError);
|
.catch(this.handleError);
|
||||||
},
|
},
|
||||||
|
|
||||||
newFeature: function() {
|
newFeature: function() {
|
||||||
var blankFeature = {
|
this.setState({createView: true});
|
||||||
name: '',
|
|
||||||
enabled: false,
|
|
||||||
strategy: 'default',
|
|
||||||
parameters: {}
|
|
||||||
};
|
|
||||||
|
|
||||||
this.state.unsavedFeatures.push(blankFeature);
|
|
||||||
this.forceUpdate();
|
|
||||||
},
|
},
|
||||||
|
|
||||||
cancelNewFeature: function (feature) {
|
cancelNewFeature: function (feature) {
|
||||||
var unsaved = [];
|
this.setState({createView: false});
|
||||||
|
|
||||||
this.state.unsavedFeatures.forEach(function (f) {
|
|
||||||
if (f.name !== feature.name) {
|
|
||||||
unsaved.push(f);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
this.setState({unsavedFeatures: unsaved});
|
|
||||||
},
|
},
|
||||||
|
|
||||||
clearErrors: function() {
|
clearErrors: function() {
|
||||||
@ -118,16 +87,30 @@ var FeatureToggleComponent = React.createClass({
|
|||||||
<ErrorMessages
|
<ErrorMessages
|
||||||
errors={this.state.errors}
|
errors={this.state.errors}
|
||||||
onClearErrors={this.clearErrors} />
|
onClearErrors={this.clearErrors} />
|
||||||
|
|
||||||
|
{this.state.createView ? this.renderCreateView() : this.renderCreateButton()}
|
||||||
|
|
||||||
|
<hr />
|
||||||
|
|
||||||
<FeatureList
|
<FeatureList
|
||||||
unsavedFeatures={this.state.unsavedFeatures}
|
features={this.state.features}
|
||||||
savedFeatures={this.state.savedFeatures}
|
|
||||||
onFeatureChanged={this.updateFeature}
|
onFeatureChanged={this.updateFeature}
|
||||||
onFeatureSubmit={this.createFeature}
|
onFeatureSubmit={this.createFeature}
|
||||||
onFeatureCancel={this.cancelNewFeature}
|
onFeatureCancel={this.cancelNewFeature}
|
||||||
onNewFeature={this.newFeature} />
|
onNewFeature={this.newFeature} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
|
||||||
|
renderCreateView: function() {
|
||||||
|
return <FeatureForm onCancel={this.cancelNewFeature} onSubmit={this.createFeature} />
|
||||||
|
},
|
||||||
|
|
||||||
|
renderCreateButton: function() {
|
||||||
|
return <button className="mal" onClick={this.newFeature}>Create feature toggle</button>
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = FeatureToggleComponent;
|
module.exports = FeatureToggleComponent;
|
@ -69,10 +69,8 @@ var StrategyComponent = React.createClass({
|
|||||||
|
|
||||||
renderCreateButton: function() {
|
renderCreateButton: function() {
|
||||||
return (
|
return (
|
||||||
<p className="">
|
<button className="mal" onClick={this.handleNewStrategy}>Create strategy</button>
|
||||||
<button className="" onClick={this.handleNewStrategy}>Create strategy</button>
|
);
|
||||||
</p>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user