diff --git a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx
index 0fc10c51de..88239b25c2 100644
--- a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx
+++ b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx
@@ -13,6 +13,7 @@ class AddFeatureToggleUI extends React.Component {
removeStrategy: PropTypes.func.required,
onSubmit: PropTypes.func.required,
onCancel: PropTypes.func.required,
+ editmode: PropTypes.bool,
};
}
@@ -26,6 +27,7 @@ class AddFeatureToggleUI extends React.Component {
type="text"
label="Name"
name="name"
+ disabled={this.props.editmode}
required
value={this.props.featureToggle.name}
onChange={this.props.updateField.bind(this, 'name')} />
@@ -62,7 +64,7 @@ class AddFeatureToggleUI extends React.Component {
-
+
);
diff --git a/packages/unleash-frontend-next/src/component/feature/EditFeatureToggle.jsx b/packages/unleash-frontend-next/src/component/feature/EditFeatureToggle.jsx
index bcb407a4e0..da4f65be3d 100644
--- a/packages/unleash-frontend-next/src/component/feature/EditFeatureToggle.jsx
+++ b/packages/unleash-frontend-next/src/component/feature/EditFeatureToggle.jsx
@@ -1,20 +1,21 @@
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
+import { updateFeatureToggle } from '../../store/feature-actions';
+import AddFeatureToggleUI from './AddFeatureToggleUI';
-const mapStateToProps = (state) => ({
+const mapStateToProps = (state, ownProps) => ({
strategies: state.strategies.toJS(),
+ featureToggle: state.features.toJS().find(toggle => toggle.name === ownProps.featureToggleName) || {},
});
-class EditFeatureToggle extends React.Component {
- constructor () {
- super();
+class AddFeatureToggle extends React.Component {
+ constructor (props) {
+ super(props);
this.state = {
- featureToggle: {
- name: '',
- description: '',
- enabled: false,
- strategies: [],
- },
+ name: props.featureToggle.name || '',
+ description: props.featureToggle.description || '',
+ enabled: props.featureToggle.enabled || false,
+ strategies: props.featureToggle.strategies || [],
};
}
@@ -22,6 +23,8 @@ class EditFeatureToggle extends React.Component {
return {
dispatch: PropTypes.func.isRequired,
strategies: PropTypes.array,
+ featureToggle: PropTypes.featureToggle.isRequired,
+ fetchFeatureToggles: PropTypes.func.isRequired,
};
}
@@ -29,13 +32,51 @@ class EditFeatureToggle extends React.Component {
router: React.PropTypes.object,
}
+ onSubmit = (evt) => {
+ evt.preventDefault();
+ this.props.dispatch(updateFeatureToggle(this.state));
+ this.context.router.push('/features');
+ };
+
+ onCancel = (evt) => {
+ evt.preventDefault();
+ this.context.router.push('/features');
+ };
+
+ updateField = (key, value) => {
+ const change = {};
+ change[key] = value;
+ this.setState(change);
+ };
+
+ addStrategy = (strategy) => {
+ const strategies = this.state.strategies;
+ strategies.push(strategy);
+ this.setState({ strategies });
+ }
+
+ removeStrategy = (strategy) => {
+ const strategies = this.state.strategies.filter(s => s !== strategy);
+ this.setState({ strategies });
+ }
+
render () {
return (
edit input
+