<commit_before>import { Component } from 'react';
import PropTypes from 'prop-types';
import { HOC } from 'formsy-react';
import { get } from 'lodash';

class Select extends Component {
  static propTypes = {
    className: PropTypes.string,
    title: PropTypes.string,
    name: PropTypes.string,
    type: PropTypes.string,
    setValue: PropTypes.func,
    showRequired: PropTypes.func,
    showError: PropTypes.func,
    getErrorMessage: PropTypes.func,
    getValue: PropTypes.func,
    keyLabel: PropTypes.string,
    keyValue: PropTypes.string,
    items: PropTypes.array,
    multiple: PropTypes.bool,
    defaultDisplay: PropTypes.string,
  }

  static defaultProps = {
    keyLabel: undefined,
    keyValue: undefined,
    items: [],
    mutliple: false,
  }

  componentDidMount() {
    const { defaultDisplay, setValue } = this.props;
    setValue([defaultDisplay]);
  }

  componentWillReceiveProps(nextProps) {
    const { defaultDisplay } = this.props;

    if (nextProps.defaultDisplay !== defaultDisplay) {
      this.props.setValue([nextProps.defaultDisplay]);
    }
  }

  render() {
    const { props } = this;
    const { items, multiple, getValue } = this.props;
    const addClassName = get(props, 'className', '');
    const className = `form-group ${addClassName}`;
    const defaultLabel = get(this.props, 'keyLabel', 'label');
    const defaultValue = get(this.props, 'keyValue', 'value');

    return (
      <div className={className}>
        <label htmlFor={props.name}>{props.title}</label>
        <select
          name={props.name}
          onChange={this.changeValue.bind(this)}
          multiple={multiple}
          value={getValue()}>
          { !!getValue() ? <option defaultValue hidden>Choose here</option> : null }
          { items.map((item, key) => {
            return <option key= {key} value= {item[defaultValue]}> {item[defaultLabel] ? item[defaultLabel] : item[defaultValue] } </option>;
          })}
        </select>
      </div>
    );
  }

  changeValue(event) {
    const { setValue } = this.props;
    const selected = event.target;
    const values = [...selected.options].filter(option => option.selected).map(option => option.value);
    setValue(values);
  }
}

export default HOC(Select);<commit_msg>[FIX] - check is multiple select<commit_after>import { Component } from 'react';
import PropTypes from 'prop-types';
import { HOC } from 'formsy-react';
import { get } from 'lodash';

class Select extends Component {
  static propTypes = {
    className: PropTypes.string,
    title: PropTypes.string,
    name: PropTypes.string,
    type: PropTypes.string,
    setValue: PropTypes.func,
    showRequired: PropTypes.func,
    showError: PropTypes.func,
    getErrorMessage: PropTypes.func,
    getValue: PropTypes.func,
    keyLabel: PropTypes.string,
    keyValue: PropTypes.string,
    items: PropTypes.array,
    multiple: PropTypes.bool,
    defaultDisplay: PropTypes.string,
  }

  static defaultProps = {
    keyLabel: undefined,
    keyValue: undefined,
    items: [],
    mutliple: false,
  }

  componentDidMount() {
    const { defaultDisplay, setValue } = this.props;
    setValue([defaultDisplay]);
  }

  componentWillReceiveProps(nextProps) {
    const { defaultDisplay } = this.props;

    if (nextProps.defaultDisplay !== defaultDisplay) {
      this.props.setValue([nextProps.defaultDisplay]);
    }
  }

  render() {
    const { props } = this;
    const { items, multiple, getValue } = this.props;
    const addClassName = get(props, 'className', '');
    const className = `form-group ${addClassName}`;
    const defaultLabel = get(this.props, 'keyLabel', 'label');
    const defaultValue = get(this.props, 'keyValue', 'value');

    return (
      <div className={className}>
        <label htmlFor={props.name}>{props.title}</label>
        <select
          name={props.name}
          onChange={this.changeValue.bind(this)}
          multiple={multiple}
          value={getValue()}>
          { !!getValue() ? <option defaultValue hidden>Choose here</option> : null }
          { items.map((item, key) => {
            return <option key= {key} value= {item[defaultValue]}> {item[defaultLabel] ? item[defaultLabel] : item[defaultValue] } </option>;
          })}
        </select>
      </div>
    );
  }

  changeValue(event) {
    const hasMultiple = get(event.target.attributes, 'multiple', false);
    const { setValue } = this.props;
    const selected = event.target;
    const values = [...selected.options].filter(option => option.selected).map(option => option.value);
    if (!hasMultiple) {
      setValue(values[0]);
    } else {
      setValue(values);
    }
  }
}

export default HOC(Select);
{'fraction_non_alphanumeric': 0.13814389101745422, 'fraction_numerical': 0.00021285653469561516, 'mean_word_length': 3.0825369244135534, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1769238', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1382, 'n_words': 304}