mirror of
				https://github.com/Unleash/unleash.git
				synced 2025-10-27 11:02:16 +01:00 
			
		
		
		
	inital, needs refactor
This commit is contained in:
		
							parent
							
								
									0f7ac32ca1
								
							
						
					
					
						commit
						97188ac7dd
					
				@ -2,6 +2,7 @@ import React, { PropTypes } from 'react';
 | 
				
			|||||||
import { connect } from 'react-redux';
 | 
					import { connect } from 'react-redux';
 | 
				
			||||||
import { Input, Switch, Button } from 'react-toolbox';
 | 
					import { Input, Switch, Button } from 'react-toolbox';
 | 
				
			||||||
import { createFeatureToggles } from '../../store/feature-actions';
 | 
					import { createFeatureToggles } from '../../store/feature-actions';
 | 
				
			||||||
 | 
					import ConfigureStrategy from './ConfigureStrategy';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const mapStateToProps = (state) => ({
 | 
					const mapStateToProps = (state) => ({
 | 
				
			||||||
    strategies: state.strategies.toJS(),
 | 
					    strategies: state.strategies.toJS(),
 | 
				
			||||||
@ -15,11 +16,8 @@ class AddFeatureToggle extends React.Component {
 | 
				
			|||||||
                name: '',
 | 
					                name: '',
 | 
				
			||||||
                description: '',
 | 
					                description: '',
 | 
				
			||||||
                enabled: false,
 | 
					                enabled: false,
 | 
				
			||||||
                strategies: [
 | 
					                strategies: [],
 | 
				
			||||||
                    { name: 'default' },
 | 
					 | 
				
			||||||
                ],
 | 
					 | 
				
			||||||
            },
 | 
					            },
 | 
				
			||||||
            showAddStrategy: false,
 | 
					 | 
				
			||||||
        };
 | 
					        };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -40,11 +38,6 @@ class AddFeatureToggle extends React.Component {
 | 
				
			|||||||
        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;
 | 
				
			||||||
@ -53,20 +46,45 @@ class AddFeatureToggle extends React.Component {
 | 
				
			|||||||
        this.setState({ featureToggle: updatedFeatureToggle });
 | 
					        this.setState({ featureToggle: updatedFeatureToggle });
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    cancelConfig = () => {
 | 
				
			||||||
 | 
					        this.setState({ configureStrategy: undefined });
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    renderAddStrategy () {
 | 
					    renderAddStrategy () {
 | 
				
			||||||
        if (this.state.showAddStrategy) {
 | 
					        if (this.state.configureStrategy) {
 | 
				
			||||||
            return (
 | 
					            return (
 | 
				
			||||||
                <div>
 | 
					                <div>
 | 
				
			||||||
                    <h4>Adding strat</h4>
 | 
					                    <ConfigureStrategy strategy={this.state.configureStrategy} cancelConfig={this.cancelConfig} />
 | 
				
			||||||
                    <p>Possible: {this.props.strategies.map(s => s.name).join(', ')}</p>
 | 
					 | 
				
			||||||
                </div>
 | 
					                </div>
 | 
				
			||||||
            );
 | 
					            );
 | 
				
			||||||
        } else {
 | 
					        } else {
 | 
				
			||||||
            return <a onClick={this.addStrategy} href="#addStrategy">Add strategy..</a>;
 | 
					            return (
 | 
				
			||||||
 | 
					                <div>
 | 
				
			||||||
 | 
					                    <strong>Choose an activation strategy:</strong>
 | 
				
			||||||
 | 
					                    <ul>{this.renderPossibleStrategies()}</ul>
 | 
				
			||||||
 | 
					                </div>
 | 
				
			||||||
 | 
					            );
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    renderPossibleStrategies () {
 | 
				
			||||||
 | 
					        const configure = (strategy, evt) => {
 | 
				
			||||||
 | 
					            evt.preventDefault();
 | 
				
			||||||
 | 
					            this.setState({
 | 
				
			||||||
 | 
					                configureStrategy: strategy,
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        const configuredStrategies = this.state.featureToggle.strategies;
 | 
				
			||||||
 | 
					        return this.props.strategies
 | 
				
			||||||
 | 
					            .filter(s => !configuredStrategies.find(selected => selected.name === s.name))
 | 
				
			||||||
 | 
					            .map((s) => (
 | 
				
			||||||
 | 
					                <li key={s.name}><a href={`#configure-${s.name}`} onClick={configure.bind(this, s)}>{s.name}</a></li>
 | 
				
			||||||
 | 
					            ));
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    render () {
 | 
					    render () {
 | 
				
			||||||
 | 
					        const configuredStrategies = this.state.featureToggle.strategies;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        return (
 | 
					        return (
 | 
				
			||||||
            <div>
 | 
					            <div>
 | 
				
			||||||
                <form onSubmit={this.onSubmit}>
 | 
					                <form onSubmit={this.onSubmit}>
 | 
				
			||||||
@ -98,6 +116,7 @@ class AddFeatureToggle extends React.Component {
 | 
				
			|||||||
                    <section>
 | 
					                    <section>
 | 
				
			||||||
                        <h3>Strategies</h3>
 | 
					                        <h3>Strategies</h3>
 | 
				
			||||||
                        {this.renderAddStrategy()}
 | 
					                        {this.renderAddStrategy()}
 | 
				
			||||||
 | 
					                        <p>Configured: {configuredStrategies.map(s => s.name).join(', ')}</p>
 | 
				
			||||||
                    </section>
 | 
					                    </section>
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    <br />
 | 
					                    <br />
 | 
				
			||||||
 | 
				
			|||||||
@ -0,0 +1,54 @@
 | 
				
			|||||||
 | 
					import React, { PropTypes } from 'react';
 | 
				
			||||||
 | 
					import { Button, Input } from 'react-toolbox';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class ConfigureStrategy extends React.Component {
 | 
				
			||||||
 | 
					    constructor () {
 | 
				
			||||||
 | 
					        super();
 | 
				
			||||||
 | 
					        this.state = {};
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    static propTypes () {
 | 
				
			||||||
 | 
					        return {
 | 
				
			||||||
 | 
					            strategy: PropTypes.object.isRequired,
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    addStrategy = (evt) => {
 | 
				
			||||||
 | 
					        evt.preventDefault();
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    handleChange = (key, value) => {
 | 
				
			||||||
 | 
					        const change = {};
 | 
				
			||||||
 | 
					        change[key] = value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const newState = Object.assign({}, this.state, change);
 | 
				
			||||||
 | 
					        this.setState(newState);
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    renderInputFields () {
 | 
				
			||||||
 | 
					        const strategy = this.props.strategy;
 | 
				
			||||||
 | 
					        if (strategy.parametersTemplate) {
 | 
				
			||||||
 | 
					            return Object.keys(strategy.parametersTemplate).map(field => (
 | 
				
			||||||
 | 
					                <Input key={field} name={field} label={field} onChange={this.handleChange.bind(null, field)} />
 | 
				
			||||||
 | 
					            ));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    render () {
 | 
				
			||||||
 | 
					        let inputFields = this.renderInputFields();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        return (
 | 
				
			||||||
 | 
					            <div style={{ backgroundColor: '#ECECEC', padding: '10px' }}>
 | 
				
			||||||
 | 
					                <h4>{this.props.strategy.name}</h4>
 | 
				
			||||||
 | 
					                <p>{this.props.strategy.description}</p>
 | 
				
			||||||
 | 
					                {inputFields}
 | 
				
			||||||
 | 
					                <Button raised label="add strategy" />
 | 
				
			||||||
 | 
					                <Button raised accent label="cancel" onClick={this.props.cancelConfig} />
 | 
				
			||||||
 | 
					            </div>
 | 
				
			||||||
 | 
					        );
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					export default (ConfigureStrategy);
 | 
				
			||||||
@ -6,7 +6,7 @@ const init = new List([
 | 
				
			|||||||
        {
 | 
					        {
 | 
				
			||||||
            name: 'ActiveForUserWithEmail',
 | 
					            name: 'ActiveForUserWithEmail',
 | 
				
			||||||
            description: 'Active for user with specified email',
 | 
					            description: 'Active for user with specified email',
 | 
				
			||||||
            parametersTemplate: { emails: 'string' },
 | 
					            parametersTemplate: { emails: 'string', ids: 'string' },
 | 
				
			||||||
        }),
 | 
					        }),
 | 
				
			||||||
]);
 | 
					]);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user