1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-23 20:07:40 +02:00
unleash.unleash/frontend/src/component/feature/form/strategies-add.jsx

53 lines
1.7 KiB
React
Raw Normal View History

2016-11-10 14:26:24 +01:00
import React, { PropTypes } from 'react';
2016-12-04 13:51:31 +01:00
import { Menu, MenuItem, IconButton } 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,
});
};
2016-12-04 13:55:43 +01:00
stopPropagation (e) {
e.stopPropagation();
e.preventDefault();
}
2016-11-10 14:26:24 +01: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 (
2016-12-04 13:51:31 +01:00
<div style={{ position: 'relative', width: '25px', height: '25px', display: 'inline-block' }} >
2016-12-04 13:55:43 +01:00
<IconButton name="add" id="strategies-add" colored title="Sort" onClick={this.stopPropagation}/>
2016-12-10 12:54:09 +01:00
<Menu target="strategies-add" valign="top" align="left" ripple style={menuStyle} onClick={
2016-12-04 13:51:31 +01:00
(e) => this.setSort(e.target.getAttribute('data-target'))}>
<MenuItem disabled>Add Strategy:</MenuItem>
{this.props.strategies.map((s) => <MenuItem key={s.name} onClick={() => this.addStrategy(s.name)}>{s.name}</MenuItem>)}
</Menu>
2016-11-15 23:14:30 +01:00
</div>
2016-11-10 14:26:24 +01:00
);
}
}
export default AddStrategy;