2017-08-28 21:30:12 +02:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2017-06-29 08:36:10 +02:00
|
|
|
import { Menu, MenuItem, IconButton } from 'react-mdl';
|
2016-11-10 14:26:24 +01:00
|
|
|
|
|
|
|
class AddStrategy extends React.Component {
|
2017-07-10 23:38:44 +02:00
|
|
|
static propTypes = {
|
|
|
|
strategies: PropTypes.array.isRequired,
|
|
|
|
addStrategy: PropTypes.func.isRequired,
|
|
|
|
fetchStrategies: PropTypes.func.isRequired,
|
2017-08-28 19:15:47 +02:00
|
|
|
};
|
2016-11-10 14:26:24 +01:00
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
addStrategy = strategyName => {
|
|
|
|
const selectedStrategy = this.props.strategies.find(
|
|
|
|
s => s.name === strategyName
|
|
|
|
);
|
2016-11-10 14:26:24 +01:00
|
|
|
const parameters = {};
|
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
selectedStrategy.parameters.forEach(({ name }) => {
|
|
|
|
parameters[name] = '';
|
|
|
|
});
|
2016-11-10 14:26:24 +01:00
|
|
|
|
|
|
|
this.props.addStrategy({
|
|
|
|
name: selectedStrategy.name,
|
|
|
|
parameters,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
stopPropagation(e) {
|
2016-12-04 13:55:43 +01:00
|
|
|
e.stopPropagation();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
|
2017-08-28 19:15:47 +02:00
|
|
|
render() {
|
2016-12-10 12:54:09 +01:00
|
|
|
const menuStyle = {
|
|
|
|
maxHeight: '300px',
|
|
|
|
overflowY: 'auto',
|
|
|
|
backgroundColor: 'rgb(247, 248, 255)',
|
|
|
|
};
|
2016-12-04 11:56:41 +01:00
|
|
|
return (
|
2017-08-28 19:15:47 +02:00
|
|
|
<div
|
|
|
|
style={{
|
|
|
|
position: 'relative',
|
|
|
|
width: '25px',
|
|
|
|
height: '25px',
|
|
|
|
display: 'inline-block',
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<IconButton
|
|
|
|
name="add"
|
|
|
|
id="strategies-add"
|
|
|
|
raised
|
|
|
|
accent
|
|
|
|
title="Add Strategy"
|
|
|
|
onClick={this.stopPropagation}
|
|
|
|
/>
|
|
|
|
<Menu
|
|
|
|
target="strategies-add"
|
|
|
|
valign="bottom"
|
|
|
|
align="right"
|
|
|
|
ripple
|
|
|
|
style={menuStyle}
|
|
|
|
>
|
2016-12-04 13:51:31 +01:00
|
|
|
<MenuItem disabled>Add Strategy:</MenuItem>
|
2017-08-28 19:15:47 +02:00
|
|
|
{this.props.strategies.map(s => (
|
|
|
|
<MenuItem
|
|
|
|
key={s.name}
|
|
|
|
title={s.description}
|
|
|
|
onClick={() => this.addStrategy(s.name)}
|
|
|
|
>
|
|
|
|
{s.name}
|
|
|
|
</MenuItem>
|
|
|
|
))}
|
2016-12-04 13:51:31 +01:00
|
|
|
</Menu>
|
2016-11-15 23:14:30 +01:00
|
|
|
</div>
|
2016-11-10 14:26:24 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default AddStrategy;
|