OptionPicker.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. onChange={option => onChange(option.value)}
  38. getOptionValue={i => i.value}
  39. getOptionLabel={i => i.label}
  40. value={selectedOption}
  41. noOptionsMessage={() => 'No metrics found'}
  42. />
  43. );
  44. }
  45. }