mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-19 00:15:43 +01:00
custom Dropdown for selecting strategy to add
This commit is contained in:
parent
a4d013c9eb
commit
80fdef429b
@ -1,13 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { Button } from 'react-toolbox';
|
import { Button, Dropdown } from 'react-toolbox';
|
||||||
|
|
||||||
class AddStrategy extends React.Component {
|
class AddStrategy extends React.Component {
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
selectedStrategy: props.strategies[0],
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static propTypes () {
|
static propTypes () {
|
||||||
return {
|
return {
|
||||||
@ -17,22 +11,8 @@ class AddStrategy extends React.Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillReceiveProps (nextProps) {
|
addStrategy = (strategyName) => {
|
||||||
// this will fix async strategies list loading after mounted
|
|
||||||
if (!this.state.selectedStrategy && nextProps.strategies.length > 0) {
|
|
||||||
this.setState({ selectedStrategy: nextProps.strategies[0] });
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleChange = (evt) => {
|
|
||||||
const strategyName = evt.target.value;
|
|
||||||
const selectedStrategy = this.props.strategies.find(s => s.name === strategyName);
|
const selectedStrategy = this.props.strategies.find(s => s.name === strategyName);
|
||||||
this.setState({ selectedStrategy });
|
|
||||||
}
|
|
||||||
|
|
||||||
addStrategy = (evt) => {
|
|
||||||
evt.preventDefault();
|
|
||||||
const selectedStrategy = this.state.selectedStrategy;
|
|
||||||
const parameters = {};
|
const parameters = {};
|
||||||
const keys = Object.keys(selectedStrategy.parametersTemplate || {});
|
const keys = Object.keys(selectedStrategy.parametersTemplate || {});
|
||||||
keys.forEach(prop => { parameters[prop] = ''; });
|
keys.forEach(prop => { parameters[prop] = ''; });
|
||||||
@ -44,27 +24,48 @@ class AddStrategy extends React.Component {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
customItem (item) {
|
||||||
|
const containerStyle = {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'row',
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const contentStyle = {
|
||||||
|
display: 'flex',
|
||||||
|
flexDirection: 'column',
|
||||||
|
flexGrow: 2,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div style={containerStyle}>
|
||||||
|
<div style={contentStyle}>
|
||||||
|
<strong>{item.name}</strong>
|
||||||
|
<small>{item.description}</small>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const strategies = this.props.strategies.map(s => (
|
const strats = this.props.strategies.map(s => {
|
||||||
<option key={s.name} value={s.name}>{s.name}</option>
|
s.value = s.name;
|
||||||
));
|
return s;
|
||||||
|
});
|
||||||
const selectedStrategy = this.state.selectedStrategy || this.props.strategies[0];
|
|
||||||
|
|
||||||
if (!selectedStrategy) {
|
|
||||||
return <i>Strategies loading...</i>;
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<select value={selectedStrategy.name} onChange={this.handleChange}>
|
<Dropdown
|
||||||
{strategies}
|
auto={false}
|
||||||
</select>
|
source={strats}
|
||||||
<Button icon="add" accent flat label="add strategy" onClick={this.addStrategy} />
|
onChange={this.addStrategy}
|
||||||
<p><strong>Description:</strong> {selectedStrategy.description}</p>
|
label="Select activation strategy to add"
|
||||||
|
template={this.customItem}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export default AddStrategy;
|
export default AddStrategy;
|
||||||
|
Loading…
Reference in New Issue
Block a user