{"size": 1071, "ext": "js", "max_stars_repo_path": "src/components/SearchFieldSelect/SearchFieldSelect.js", "max_stars_repo_name": "folio-org/ui-plugin-find-package-title", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/SearchFieldSelect/SearchFieldSelect.js", "max_issues_repo_name": "folio-org/ui-plugin-find-package-title", "max_issues_repo_issues_event_min_datetime": "2020-05-22T13:15:10.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-21T09:49:35.000Z", "max_forks_repo_path": "src/components/SearchFieldSelect/SearchFieldSelect.js", "max_forks_repo_name": "folio-org/ui-plugin-find-packages-titles", "max_forks_repo_forks_event_min_datetime": "2020-07-20T22:45:49.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-07T04:42:53.000Z"}
{"max_stars_count": null, "max_issues_count": 69, "max_forks_count": 2, "avg_line_length": 22.7872340426, "max_line_length": 108, "alphanum_fraction": 0.6591970121}
import PropTypes from 'prop-types';
import { useIntl } from 'react-intl';

import { Select } from '@folio/stripes/components';

import {
  titleSearchFields,
  titleSearchFieldsTranslationIDs,
} from '../../constants';

const propTypes = {
  value: PropTypes.string.isRequired,
  onChange: PropTypes.func.isRequired,
};

const SearchFieldSelect = ({
  value,
  onChange,
}) => {
  const intl = useIntl();
  const handleSearchFieldChange = e => {
    onChange(e.target.value);
  };

  return (
    <Select
      onChange={handleSearchFieldChange}
      value={value}
      aria-label={intl.formatMessage({ id: 'ui-plugin-find-package-title.searchPane.selectFieldToSearch' })}
      data-testid="select-field"
    >
      {Object.values(titleSearchFields).map(searchField => (
        <option
          value={searchField}
          key={searchField}
        >
          {intl.formatMessage({ id: titleSearchFieldsTranslationIDs[searchField] })}
        </option>
      ))}
    </Select>
  );
};

SearchFieldSelect.propTypes = propTypes;

export default SearchFieldSelect;
