From 80fdef429bfe9774cc1ab85804ab3168adc9f139 Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Tue, 25 Oct 2016 23:09:58 +0200 Subject: [PATCH] custom Dropdown for selecting strategy to add --- .../src/component/feature/strategies-add.jsx | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/packages/unleash-frontend-next/src/component/feature/strategies-add.jsx b/packages/unleash-frontend-next/src/component/feature/strategies-add.jsx index 5968beb45b..35eba052d4 100644 --- a/packages/unleash-frontend-next/src/component/feature/strategies-add.jsx +++ b/packages/unleash-frontend-next/src/component/feature/strategies-add.jsx @@ -1,13 +1,7 @@ import React, { PropTypes } from 'react'; -import { Button } from 'react-toolbox'; +import { Button, Dropdown } from 'react-toolbox'; class AddStrategy extends React.Component { - constructor (props) { - super(props); - this.state = { - selectedStrategy: props.strategies[0], - }; - } static propTypes () { return { @@ -17,22 +11,8 @@ class AddStrategy extends React.Component { }; } - componentWillReceiveProps (nextProps) { - // this will fix async strategies list loading after mounted - if (!this.state.selectedStrategy && nextProps.strategies.length > 0) { - this.setState({ selectedStrategy: nextProps.strategies[0] }); - } - } - - handleChange = (evt) => { - const strategyName = evt.target.value; + addStrategy = (strategyName) => { const selectedStrategy = this.props.strategies.find(s => s.name === strategyName); - this.setState({ selectedStrategy }); - } - - addStrategy = (evt) => { - evt.preventDefault(); - const selectedStrategy = this.state.selectedStrategy; const parameters = {}; const keys = Object.keys(selectedStrategy.parametersTemplate || {}); keys.forEach(prop => { parameters[prop] = ''; }); @@ -44,27 +24,48 @@ class AddStrategy extends React.Component { }); }; + customItem (item) { + const containerStyle = { + display: 'flex', + flexDirection: 'row', + }; + + + const contentStyle = { + display: 'flex', + flexDirection: 'column', + flexGrow: 2, + }; + + return ( +
+
+ {item.name} + {item.description} +
+
+ ); + } + render () { - const strategies = this.props.strategies.map(s => ( - - )); - - const selectedStrategy = this.state.selectedStrategy || this.props.strategies[0]; - - if (!selectedStrategy) { - return Strategies loading...; - } + const strats = this.props.strategies.map(s => { + s.value = s.name; + return s; + }); return (
- -
); } } + export default AddStrategy;