diff --git a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx index ba5937df87..f9371286f7 100644 --- a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx +++ b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx @@ -1,9 +1,7 @@ import React, { PropTypes } from 'react'; import { connect } from 'react-redux'; -import { Input, Switch, Button } from 'react-toolbox'; import { createFeatureToggles } from '../../store/feature-actions'; -import AddFeatureToggleStrategy from './AddFeatureToggleStrategy'; -import ConfiguredStrategies from './ConfiguredStrategies'; +import AddFeatureToggleUI from './AddFeatureToggleUI'; const mapStateToProps = (state) => ({ strategies: state.strategies.toJS(), @@ -13,12 +11,10 @@ class AddFeatureToggle extends React.Component { constructor () { super(); this.state = { - featureToggle: { - name: '', - description: '', - enabled: false, - strategies: [], - }, + name: '', + description: '', + enabled: false, + strategies: [], }; } @@ -35,79 +31,44 @@ class AddFeatureToggle extends React.Component { onSubmit = (evt) => { evt.preventDefault(); - this.props.dispatch(createFeatureToggles(this.state.featureToggle)); + this.props.dispatch(createFeatureToggles(this.state)); this.context.router.push('/features'); }; - handleChange = (key, value) => { + onCancel = (evt) => { + evt.preventDefault(); + this.context.router.push('/features'); + }; + + updateField = (key, value) => { const change = {}; change[key] = value; - const updatedFeatureToggle = Object.assign({}, this.state.featureToggle, change); - - this.setState({ featureToggle: updatedFeatureToggle }); + this.setState(change); }; addStrategy = (strategy) => { - const strategies = this.state.featureToggle.strategies; + const strategies = this.state.strategies; strategies.push(strategy); - const updatedFeatureToggle = Object.assign({}, this.state.featureToggle, { strategies }); - this.setState({ featureToggle: updatedFeatureToggle }); + this.setState({ strategies }); } removeStrategy = (strategy) => { - const strategies = this.state.featureToggle.strategies.filter(s => s !== strategy); - const updatedFeatureToggle = Object.assign({}, this.state.featureToggle, { strategies }); - this.setState({ featureToggle: updatedFeatureToggle }); + const strategies = this.state.strategies.filter(s => s !== strategy); + this.setState({ strategies }); } render () { - const configuredStrategies = this.state.featureToggle.strategies; - return (
-
-
- - - -
- - - -
-
- -
- Activation strategies - -
- -
- -
- -
- - -
); } diff --git a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx new file mode 100644 index 0000000000..0fc10c51de --- /dev/null +++ b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggleUI.jsx @@ -0,0 +1,72 @@ +import React, { PropTypes } from 'react'; +import { Input, Switch, Button } from 'react-toolbox'; +import AddFeatureToggleStrategy from './AddFeatureToggleStrategy'; +import ConfiguredStrategies from './ConfiguredStrategies'; + +class AddFeatureToggleUI extends React.Component { + static propTypes () { + return { + strategies: PropTypes.array.required, + featureToggle: PropTypes.object, + updateField: PropTypes.func.required, + addStrategy: PropTypes.func.required, + removeStrategy: PropTypes.func.required, + onSubmit: PropTypes.func.required, + onCancel: PropTypes.func.required, + }; + } + + render () { + const configuredStrategies = this.props.featureToggle.strategies; + + return ( +
+
+ + + +
+ + + +
+
+ +
+ Activation strategies + +
+ +
+ +
+ +
+ + +