OptionPicker.tsx 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import React from 'react';
  2. // import SimplePicker from 'app/core/components/Picker/SimplePicker';
  3. import Select from 'react-select';
  4. // import DescriptionPicker from 'app/core/components/Picker/DescriptionPicker';
  5. import DescriptionOption from 'app/core/components/Picker/DescriptionOption';
  6. import IndicatorsContainer from 'app/core/components/Picker/IndicatorsContainer';
  7. import ResetStyles from 'app/core/components/Picker/ResetStyles';
  8. import NoOptionsMessage from 'app/core/components/Picker/NoOptionsMessage';
  9. import _ from 'lodash';
  10. export interface Props {
  11. onChange: (value: string) => void;
  12. options: any[];
  13. selected: string;
  14. placeholder?: string;
  15. className?: string;
  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 } = this.props;
  23. const selectedOption = options.find(metric => metric.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. isDisabled={false}
  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. }