2016-10-27 16:14:30 +00:00
|
|
|
import React, { Component, PropTypes } from 'react';
|
2016-11-09 18:08:00 +00:00
|
|
|
import { difference } from 'lodash';
|
2016-10-27 16:14:30 +00:00
|
|
|
import Select from 'react-select';
|
|
|
|
|
import 'react-select/dist/react-select.css';
|
|
|
|
|
|
2016-11-14 17:32:13 +00:00
|
|
|
import targetInterface from 'interfaces/target';
|
2016-10-27 16:14:30 +00:00
|
|
|
|
|
|
|
|
class SelectTargetsInput extends Component {
|
|
|
|
|
static propTypes = {
|
2016-11-23 21:10:32 +00:00
|
|
|
className: PropTypes.string,
|
2016-10-27 16:14:30 +00:00
|
|
|
isLoading: PropTypes.bool,
|
|
|
|
|
menuRenderer: PropTypes.func,
|
2016-11-21 15:38:23 +00:00
|
|
|
onClose: PropTypes.func,
|
2016-10-27 16:14:30 +00:00
|
|
|
onTargetSelect: PropTypes.func,
|
|
|
|
|
onTargetSelectInputChange: PropTypes.func,
|
|
|
|
|
selectedTargets: PropTypes.arrayOf(targetInterface),
|
|
|
|
|
targets: PropTypes.arrayOf(targetInterface),
|
|
|
|
|
};
|
|
|
|
|
|
2016-11-09 18:08:00 +00:00
|
|
|
filterOptions = (options) => {
|
|
|
|
|
const { selectedTargets } = this.props;
|
|
|
|
|
|
|
|
|
|
return difference(options, selectedTargets);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 16:14:30 +00:00
|
|
|
render () {
|
|
|
|
|
const {
|
2016-11-23 21:10:32 +00:00
|
|
|
className,
|
2016-10-27 16:14:30 +00:00
|
|
|
isLoading,
|
|
|
|
|
menuRenderer,
|
2016-11-21 15:38:23 +00:00
|
|
|
onClose,
|
2016-10-27 16:14:30 +00:00
|
|
|
onTargetSelect,
|
|
|
|
|
onTargetSelectInputChange,
|
|
|
|
|
selectedTargets,
|
|
|
|
|
targets,
|
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Select
|
2016-11-23 21:10:32 +00:00
|
|
|
className={`${className} target-select`}
|
2016-10-27 16:14:30 +00:00
|
|
|
isLoading={isLoading}
|
2016-11-09 18:08:00 +00:00
|
|
|
filterOptions={this.filterOptions}
|
|
|
|
|
labelKey="display_text"
|
2016-10-27 16:14:30 +00:00
|
|
|
menuRenderer={menuRenderer}
|
|
|
|
|
multi
|
|
|
|
|
name="targets"
|
|
|
|
|
options={targets}
|
|
|
|
|
onChange={onTargetSelect}
|
2016-11-21 15:38:23 +00:00
|
|
|
onClose={onClose}
|
2016-10-27 16:14:30 +00:00
|
|
|
onInputChange={onTargetSelectInputChange}
|
|
|
|
|
placeholder="Label Name, Host Name, IP Address, etc."
|
|
|
|
|
resetValue={[]}
|
2016-11-23 21:10:32 +00:00
|
|
|
scrollMenuIntoView={false}
|
|
|
|
|
tabSelectsValue={false}
|
2016-10-27 16:14:30 +00:00
|
|
|
value={selectedTargets}
|
2016-11-09 18:08:00 +00:00
|
|
|
valueKey="display_text"
|
2016-10-27 16:14:30 +00:00
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default SelectTargetsInput;
|