mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	More AddFeatureToggle #153
This commit is contained in:
		
							parent
							
								
									e18675052d
								
							
						
					
					
						commit
						02cfdc522f
					
				| @ -7,7 +7,17 @@ import { addFeatureToggle } from '../../store/actions'; | |||||||
| class AddFeatureToggle extends React.Component { | class AddFeatureToggle extends React.Component { | ||||||
|     constructor () { |     constructor () { | ||||||
|         super(); |         super(); | ||||||
|         this.state = { name: '', description: '', enabled: false }; |         this.state = { | ||||||
|  |             featureToggle: { | ||||||
|  |                 name: '', | ||||||
|  |                 description: '', | ||||||
|  |                 enabled: false, | ||||||
|  |                 strategies: [ | ||||||
|  |                     { name: 'default' }, | ||||||
|  |                 ], | ||||||
|  |             }, | ||||||
|  |             showAddStrategy: false, | ||||||
|  |         }; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     static propTypes () { |     static propTypes () { | ||||||
| @ -22,18 +32,31 @@ class AddFeatureToggle extends React.Component { | |||||||
| 
 | 
 | ||||||
|     onSubmit = (evt) => { |     onSubmit = (evt) => { | ||||||
|         evt.preventDefault(); |         evt.preventDefault(); | ||||||
|         this.props.dispatch(addFeatureToggle(this.state.name)); |         this.props.dispatch(addFeatureToggle(this.state.featureToggle)); | ||||||
|         this.context.router.push('/features'); |         this.context.router.push('/features'); | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |     addStrategy = (evt) => { | ||||||
|  |         evt.preventDefault(); | ||||||
|  |         this.setState({ showAddStrategy: true }); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     handleChange = (key, value) => { |     handleChange = (key, value) => { | ||||||
|         const change = {}; |         const change = {}; | ||||||
|         change[key] = value; |         change[key] = value; | ||||||
|  |         const updatedFeatureToggle = Object.assign({}, this.state.featureToggle, change); | ||||||
| 
 | 
 | ||||||
|         const newState = Object.assign({}, this.state, change); |         this.setState({ featureToggle: updatedFeatureToggle }); | ||||||
|         this.setState(newState); |  | ||||||
|     }; |     }; | ||||||
| 
 | 
 | ||||||
|  |     renderAddStrategy () { | ||||||
|  |         if (this.state.showAddStrategy) { | ||||||
|  |             return <h4>Adding strat</h4>; | ||||||
|  |         } else { | ||||||
|  |             return <a onClick={this.addStrategy} href="#addStrategy">Add strategy..</a>; | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|     render () { |     render () { | ||||||
|         return ( |         return ( | ||||||
|             <div> |             <div> | ||||||
| @ -44,19 +67,19 @@ class AddFeatureToggle extends React.Component { | |||||||
|                             label="Name" |                             label="Name" | ||||||
|                             name="name" |                             name="name" | ||||||
|                             required |                             required | ||||||
|                             value={this.state.name} |                             value={this.state.featureToggle.name} | ||||||
|                             onChange={this.handleChange.bind(this, 'name')} /> |                             onChange={this.handleChange.bind(this, 'name')} /> | ||||||
|                         <Input |                         <Input | ||||||
|                             type="text" |                             type="text" | ||||||
|                             multiline label="Description" |                             multiline label="Description" | ||||||
|                             required |                             required | ||||||
|                             value={this.state.description} |                             value={this.state.featureToggle.description} | ||||||
|                             onChange={this.handleChange.bind(this, 'description')} /> |                             onChange={this.handleChange.bind(this, 'description')} /> | ||||||
| 
 | 
 | ||||||
|                         <br /> |                         <br /> | ||||||
| 
 | 
 | ||||||
|                         <Switch |                         <Switch | ||||||
|                             checked={this.state.enabled} |                             checked={this.state.featureToggle.enabled} | ||||||
|                             label="Enabled" |                             label="Enabled" | ||||||
|                             onChange={this.handleChange.bind(this, 'enabled')} /> |                             onChange={this.handleChange.bind(this, 'enabled')} /> | ||||||
| 
 | 
 | ||||||
| @ -64,7 +87,8 @@ class AddFeatureToggle extends React.Component { | |||||||
|                     </section> |                     </section> | ||||||
| 
 | 
 | ||||||
|                     <section> |                     <section> | ||||||
|                         <a href="#" onClick="">Add strategy..</a> |                         <h3>Strategies</h3> | ||||||
|  |                         {this.renderAddStrategy()} | ||||||
|                     </section> |                     </section> | ||||||
| 
 | 
 | ||||||
|                     <br /> |                     <br /> | ||||||
|  | |||||||
| @ -0,0 +1,53 @@ | |||||||
|  | import React, { PropTypes } from 'react'; | ||||||
|  | import { connect } from 'react-redux'; | ||||||
|  | import { Button } from 'react-toolbox'; | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class AddStrategy extends React.Component { | ||||||
|  |     constructor () { | ||||||
|  |         super(); | ||||||
|  |         this.state = { | ||||||
|  |             name: '', | ||||||
|  |             parameters: {}, | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     static propTypes () { | ||||||
|  |         return { | ||||||
|  |             StrategyDefinitions: PropTypes.array.isRequired, | ||||||
|  |         }; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     static contextTypes = { | ||||||
|  |         router: React.PropTypes.object, | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     onSubmit = (evt) => { | ||||||
|  |         evt.preventDefault(); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     addStrategy = (evt) => { | ||||||
|  |         evt.preventDefault(); | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     handleChange = (key, value) => { | ||||||
|  |         const change = {}; | ||||||
|  |         change[key] = value; | ||||||
|  | 
 | ||||||
|  |         const newState = Object.assign({}, this.state, change); | ||||||
|  |         this.setState(newState); | ||||||
|  |     }; | ||||||
|  | 
 | ||||||
|  |     render () { | ||||||
|  |         return ( | ||||||
|  |             <div> | ||||||
|  |                 <form onSubmit={this.onSubmit}> | ||||||
|  |                     New Strategy: | ||||||
|  |                     <Button type="submit" raised primary label="Create" /> | ||||||
|  |                 </form> | ||||||
|  |             </div> | ||||||
|  |         ); | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | export default connect()(AddStrategy); | ||||||
| @ -4,9 +4,9 @@ export const REQUEST_FEATURE_TOGGLES = 'REQUEST_FEATURE_TOGGLES'; | |||||||
| export const RECEIVE_FEATURE_TOGGLES = 'RECEIVE_FEATURE_TOGGLES'; | export const RECEIVE_FEATURE_TOGGLES = 'RECEIVE_FEATURE_TOGGLES'; | ||||||
| export const ERROR_RECEIVE_FEATURE_TOGGLES = 'ERROR_RECEIVE_FEATURE_TOGGLES'; | export const ERROR_RECEIVE_FEATURE_TOGGLES = 'ERROR_RECEIVE_FEATURE_TOGGLES'; | ||||||
| 
 | 
 | ||||||
| export const addFeatureToggle = (featureName) => ({ | export const addFeatureToggle = (featureToggle) => ({ | ||||||
|     type: ADD_FEATURE_TOGGLE, |     type: ADD_FEATURE_TOGGLE, | ||||||
|     name: featureName, |     featureToggle, | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| export const toggleFeature = (featureName) => ({ | export const toggleFeature = (featureName) => ({ | ||||||
|  | |||||||
| @ -7,10 +7,7 @@ import { | |||||||
| const feature = (state = {}, action) => { | const feature = (state = {}, action) => { | ||||||
|     switch (action.type) { |     switch (action.type) { | ||||||
|         case ADD_FEATURE_TOGGLE: |         case ADD_FEATURE_TOGGLE: | ||||||
|             return { |             return action.featureToggle; | ||||||
|                 name: action.name, |  | ||||||
|                 enabled: false, |  | ||||||
|             }; |  | ||||||
|         case TOGGLE_FEATURE_TOGGLE: |         case TOGGLE_FEATURE_TOGGLE: | ||||||
|             if (state.name !== action.name) { |             if (state.name !== action.name) { | ||||||
|                 return state; |                 return state; | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user