From e299f88062120bdcb1496f7a0096913537e59e79 Mon Sep 17 00:00:00 2001 From: sveisvei Date: Sat, 10 Dec 2016 23:16:21 +0100 Subject: [PATCH] simple list input type --- .../feature/form/strategy-configure.jsx | 32 +++++++++++++---- .../feature/form/strategy-input-list.jsx | 36 +++++++++++++++++++ 2 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 frontend/src/component/feature/form/strategy-input-list.jsx diff --git a/frontend/src/component/feature/form/strategy-configure.jsx b/frontend/src/component/feature/form/strategy-configure.jsx index 2d2ae63313..cc8453b9ff 100644 --- a/frontend/src/component/feature/form/strategy-configure.jsx +++ b/frontend/src/component/feature/form/strategy-configure.jsx @@ -1,7 +1,12 @@ import React, { PropTypes } from 'react'; -import { Textfield, Button, Card, CardTitle, CardText, CardActions, CardMenu, IconButton, Icon } from 'react-mdl'; +import { + Textfield, Button, + Card, CardTitle, CardText, CardActions, CardMenu, + IconButton, Icon, +} from 'react-mdl'; import { Link } from 'react-router'; import StrategyInputPersentage from './strategy-input-persentage'; +import StrategyInputList from './strategy-input-list'; const style = { flex: '1', @@ -20,14 +25,22 @@ class StrategyConfigure extends React.Component { }; } + // shouldComponentUpdate (props, nextProps) { + // console.log({ props, nextProps }); + // } + handleConfigChange = (key, e) => { + this.setConfig(key, e.target.value); + }; + + setConfig = (key, value) => { const parameters = this.props.strategy.parameters || {}; - parameters[key] = e.target.value; + parameters[key] = value; const updatedStrategy = Object.assign({}, this.props.strategy, { parameters }); this.props.updateStrategy(updatedStrategy); - }; + } handleRemove = (evt) => { evt.preventDefault(); @@ -41,8 +54,9 @@ class StrategyConfigure extends React.Component { return null; } return keys.map(field => { - if (strategyDefinition.parametersTemplate[field] === 'percentage') { - let value = this.props.strategy.parameters[field]; + const type = strategyDefinition.parametersTemplate[field]; + let value = this.props.strategy.parameters[field]; + if (type === 'percentage') { if (value == null || (typeof value === 'string' && value === '')) { value = 50; // default value } @@ -51,6 +65,12 @@ class StrategyConfigure extends React.Component { field={field} onChange={this.handleConfigChange.bind(this, field)} value={1 * value} />); + } else if (type === 'list') { + let list = []; + if (typeof value === 'string') { + list = value.split(','); + } + return (); } else { return ( ); } diff --git a/frontend/src/component/feature/form/strategy-input-list.jsx b/frontend/src/component/feature/form/strategy-input-list.jsx new file mode 100644 index 0000000000..1a93ce5200 --- /dev/null +++ b/frontend/src/component/feature/form/strategy-input-list.jsx @@ -0,0 +1,36 @@ +import React from 'react'; +import { + Textfield, + IconButton, + Chip, +} from 'react-mdl'; + +export default ({ field, list, setConfig }) => ( +
+
{field}
+ {list.map((entryValue, index) => ( + { + list[index] = null; + setConfig(field, list.filter(Boolean).join(',')); + }}>{entryValue} + ))} + +
{ + e.preventDefault(); + e.stopPropagation(); + + const inputValue = document.querySelector(`[name="${field}_input"]`); + if (inputValue && inputValue.value) { + list.push(inputValue.value); + inputValue.value = ''; + setConfig(field, list.join(',')); + } + }}> +
+ + +
+
+ +
+);