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

50 lines
1.6 KiB
React
Raw Normal View History

2016-11-10 14:26:24 +01:00
import React, { PropTypes } from 'react';
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 {
static propTypes = {
strategies: PropTypes.array.isRequired,
addStrategy: PropTypes.func.isRequired,
fetchStrategies: PropTypes.func.isRequired,
2016-11-10 14:26:24 +01:00
}
addStrategy = (strategyName) => {
const selectedStrategy = this.props.strategies.find(s => s.name === strategyName);
const parameters = {};
2016-12-13 19:56:52 +01:00
selectedStrategy.parameters.forEach(({ name }) => { parameters[name] = ''; });
2016-11-10 14:26:24 +01:00
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-10 22:20:26 +01:00
<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>
2016-12-13 19:56:52 +01: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;