import React, { PropTypes } from 'react'; import ControlLabelWithTooltip from './ControlLabelWithTooltip'; import { slugify } from '../../modules/utils'; import Select, { Creatable } from 'react-select'; const propTypes = { name: PropTypes.string.isRequired, choices: PropTypes.array, value: PropTypes.oneOfType([PropTypes.string, PropTypes.number, PropTypes.array]).isRequired, label: PropTypes.string, description: PropTypes.string, onChange: PropTypes.func, multi: PropTypes.bool, freeForm: PropTypes.bool, }; const defaultProps = { multi: false, freeForm: false, value: '', label: null, description: null, onChange: () => {}, }; export default class SelectField extends React.Component { onChange(opt) { let optionValue = opt ? opt.value : null; // if multi, return options values as an array if (this.props.multi) { optionValue = opt ? opt.map((o) => o.value) : null; } if (this.props.name === 'datasource' && optionValue !== null) { this.props.onChange(this.props.name, optionValue, opt.label); } else { this.props.onChange(this.props.name, optionValue); } } renderOption(opt) { if (this.props.name === 'viz_type') { const url = `/static/assets/images/viz_thumbnails/${opt.value}.png`; return (