2016-11-10 14:26:24 +01:00
|
|
|
import React, { PropTypes } from 'react';
|
2016-12-04 11:56:41 +01:00
|
|
|
// import Dropdown from 'react-toolbox/lib/dropdown';
|
|
|
|
// TODO use menu
|
|
|
|
import { Icon } from 'react-mdl';
|
2016-11-10 14:26:24 +01:00
|
|
|
|
|
|
|
class AddStrategy extends React.Component {
|
|
|
|
|
|
|
|
static propTypes () {
|
|
|
|
return {
|
|
|
|
strategies: PropTypes.array.isRequired,
|
|
|
|
addStrategy: PropTypes.func.isRequired,
|
|
|
|
fetchStrategies: PropTypes.func.isRequired,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
addStrategy = (strategyName) => {
|
|
|
|
const selectedStrategy = this.props.strategies.find(s => s.name === strategyName);
|
|
|
|
const parameters = {};
|
|
|
|
const keys = Object.keys(selectedStrategy.parametersTemplate || {});
|
|
|
|
keys.forEach(prop => { parameters[prop] = ''; });
|
|
|
|
|
|
|
|
|
|
|
|
this.props.addStrategy({
|
|
|
|
name: selectedStrategy.name,
|
|
|
|
parameters,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
customItem (item) {
|
|
|
|
const containerStyle = {
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'row',
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const contentStyle = {
|
|
|
|
display: 'flex',
|
|
|
|
flexDirection: 'column',
|
|
|
|
flexGrow: 2,
|
|
|
|
marginLeft: '10px',
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={containerStyle}>
|
2016-12-04 11:56:41 +01:00
|
|
|
<Icon value="add" />
|
2016-11-10 14:26:24 +01:00
|
|
|
<div style={contentStyle}>
|
|
|
|
<strong>{item.name}</strong>
|
|
|
|
<small>{item.description}</small>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
render () {
|
|
|
|
const strats = this.props.strategies.map(s => {
|
|
|
|
s.value = s.name;
|
|
|
|
return s;
|
|
|
|
});
|
|
|
|
|
2016-12-04 11:56:41 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
<Dropdown
|
2016-11-15 23:14:30 +01:00
|
|
|
allowBlank={false}
|
|
|
|
auto
|
|
|
|
source={strats}
|
|
|
|
onChange={this.addStrategy}
|
|
|
|
label="Click to add activation strategy"
|
|
|
|
template={this.customItem}
|
|
|
|
/>
|
2016-12-04 11:56:41 +01:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div style={{ maxWidth: '400px', marginTop: '20px' }}>
|
|
|
|
|
2016-11-15 23:14:30 +01:00
|
|
|
</div>
|
2016-11-10 14:26:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default AddStrategy;
|