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

61 lines
1.8 KiB
React
Raw Normal View History

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 {
static propTypes = {
strategies: PropTypes.array.isRequired,
addStrategy: PropTypes.func.isRequired,
fetchStrategies: PropTypes.func.isRequired,
};
2016-11-10 14:26:24 +01:00
addStrategy = strategyName => {
2017-08-28 21:40:44 +02:00
const selectedStrategy = this.props.strategies.find(s => s.name === strategyName);
2016-11-10 14:26:24 +01:00
const parameters = {};
selectedStrategy.parameters.forEach(({ name }) => {
parameters[name] = '';
});
2016-11-10 14:26:24 +01:00
this.props.addStrategy({
name: selectedStrategy.name,
parameters,
});
};
stopPropagation(e) {
2016-12-04 13:55:43 +01:00
e.stopPropagation();
e.preventDefault();
}
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 21:40:44 +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}
/>
2017-08-28 21:40:44 +02:00
<Menu target="strategies-add" valign="bottom" align="right" ripple style={menuStyle}>
2016-12-04 13:51:31 +01:00
<MenuItem disabled>Add Strategy:</MenuItem>
{this.props.strategies.map(s => (
2017-08-28 21:40:44 +02:00
<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;