From 97188ac7ddcebe5bd94c809cc541b3dff2a7ddb4 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 20 Oct 2016 18:58:16 +0200 Subject: [PATCH] inital, needs refactor --- .../component/feature/AddFeatureToggle.jsx | 45 +++++++++++----- .../component/feature/ConfigureStrategy.jsx | 54 +++++++++++++++++++ .../{feature => strategy}/AddStrategy.jsx | 0 .../src/store/strategy-store.js | 2 +- 4 files changed, 87 insertions(+), 14 deletions(-) create mode 100644 packages/unleash-frontend-next/src/component/feature/ConfigureStrategy.jsx rename packages/unleash-frontend-next/src/component/{feature => strategy}/AddStrategy.jsx (100%) diff --git a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx index c2e1375211..6d97a565f9 100644 --- a/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx +++ b/packages/unleash-frontend-next/src/component/feature/AddFeatureToggle.jsx @@ -2,6 +2,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 ConfigureStrategy from './ConfigureStrategy'; const mapStateToProps = (state) => ({ strategies: state.strategies.toJS(), @@ -15,11 +16,8 @@ class AddFeatureToggle extends React.Component { name: '', description: '', enabled: false, - strategies: [ - { name: 'default' }, - ], + strategies: [], }, - showAddStrategy: false, }; } @@ -40,11 +38,6 @@ class AddFeatureToggle extends React.Component { this.context.router.push('/features'); }; - addStrategy = (evt) => { - evt.preventDefault(); - this.setState({ showAddStrategy: true }); - } - handleChange = (key, value) => { const change = {}; change[key] = value; @@ -53,20 +46,45 @@ class AddFeatureToggle extends React.Component { this.setState({ featureToggle: updatedFeatureToggle }); }; + cancelConfig = () => { + this.setState({ configureStrategy: undefined }); + }; + renderAddStrategy () { - if (this.state.showAddStrategy) { + if (this.state.configureStrategy) { return (
-

Adding strat

-

Possible: {this.props.strategies.map(s => s.name).join(', ')}

+
); } else { - return Add strategy..; + return ( +
+ Choose an activation strategy: + +
+ ); } } + 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) => ( +
  • {s.name}
  • + )); + } + render () { + const configuredStrategies = this.state.featureToggle.strategies; + return (
    @@ -98,6 +116,7 @@ class AddFeatureToggle extends React.Component {

    Strategies

    {this.renderAddStrategy()} +

    Configured: {configuredStrategies.map(s => s.name).join(', ')}


    diff --git a/packages/unleash-frontend-next/src/component/feature/ConfigureStrategy.jsx b/packages/unleash-frontend-next/src/component/feature/ConfigureStrategy.jsx new file mode 100644 index 0000000000..64efe67157 --- /dev/null +++ b/packages/unleash-frontend-next/src/component/feature/ConfigureStrategy.jsx @@ -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 => ( + + )); + } + } + + + render () { + let inputFields = this.renderInputFields(); + + return ( +
    +

    {this.props.strategy.name}

    +

    {this.props.strategy.description}

    + {inputFields} +
    + ); + } +} + +export default (ConfigureStrategy); diff --git a/packages/unleash-frontend-next/src/component/feature/AddStrategy.jsx b/packages/unleash-frontend-next/src/component/strategy/AddStrategy.jsx similarity index 100% rename from packages/unleash-frontend-next/src/component/feature/AddStrategy.jsx rename to packages/unleash-frontend-next/src/component/strategy/AddStrategy.jsx diff --git a/packages/unleash-frontend-next/src/store/strategy-store.js b/packages/unleash-frontend-next/src/store/strategy-store.js index 642ba1d524..2ee40754d8 100644 --- a/packages/unleash-frontend-next/src/store/strategy-store.js +++ b/packages/unleash-frontend-next/src/store/strategy-store.js @@ -6,7 +6,7 @@ const init = new List([ { name: 'ActiveForUserWithEmail', description: 'Active for user with specified email', - parametersTemplate: { emails: 'string' }, + parametersTemplate: { emails: 'string', ids: 'string' }, }), ]);