OptionPicker.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from 'react';
  2. import Select from 'react-select';
  3. import _ from 'lodash';
  4. import DescriptionOption from 'app/core/components/Picker/DescriptionOption';
  5. import IndicatorsContainer from 'app/core/components/Picker/IndicatorsContainer';
  6. import ResetStyles from 'app/core/components/Picker/ResetStyles';
  7. import NoOptionsMessage from 'app/core/components/Picker/NoOptionsMessage';
  8. export interface Props {
  9. onChange: (value: string) => void;
  10. options: any[];
  11. searchable: boolean;
  12. selected: string;
  13. placeholder?: string;
  14. className?: string;
  15. groups?: boolean;
  16. }
  17. export class OptionPicker extends React.Component<Props, any> {
  18. constructor(props) {
  19. super(props);
  20. }
  21. render() {
  22. const { onChange, options, selected, placeholder, className, searchable } = this.props;
  23. const selectedOption = options.find(option => option.value === selected);
  24. return (
  25. <Select
  26. placeholder={placeholder}
  27. classNamePrefix={`gf-form-select-box`}
  28. className={className}
  29. options={options}
  30. components={{
  31. Option: DescriptionOption,
  32. IndicatorsContainer,
  33. NoOptionsMessage,
  34. }}
  35. styles={ResetStyles}
  36. isSearchable={searchable}
  37. maxMenuHeight={50}
  38. onChange={option => onChange(option.value)}
  39. getOptionValue={i => i.value}
  40. getOptionLabel={i => i.label}
  41. value={selectedOption}
  42. noOptionsMessage={() => 'No metrics found'}
  43. />
  44. );
  45. }
  46. }