selectAsyncField.tsx 1022 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import React from 'react';
  2. import SelectAsyncControl from './selectAsyncControl';
  3. import SelectField from './selectField';
  4. class SelectAsyncField extends SelectField {
  5. static defaultProps = {
  6. ...SelectField.defaultProps,
  7. placeholder: 'Start typing to search for an issue',
  8. };
  9. onResults = data => {
  10. const {name} = this.props;
  11. const results = data && data[name];
  12. return (results && results.map(({id, text}) => ({value: id, label: text}))) || [];
  13. };
  14. onQuery = query =>
  15. // Used by legacy integrations
  16. ({autocomplete_query: query, autocomplete_field: this.props.name});
  17. getField() {
  18. // Callers should be able to override all props except onChange
  19. // FormField calls props.onChange via `setValue`
  20. return (
  21. <SelectAsyncControl
  22. id={this.getId()}
  23. onResults={this.onResults}
  24. onQuery={this.onQuery}
  25. {...this.props}
  26. value={this.state.value}
  27. onChange={this.onChange}
  28. />
  29. );
  30. }
  31. }
  32. export default SelectAsyncField;