All files / src/hocs/components/filter select.js

9.09% Statements 1/11
0% Branches 0/2
0% Functions 0/4
9.09% Lines 1/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50        4x                                                                                          
import React, {Component} from 'react';
import PropTypes from 'prop-types';
import {Select} from 'antd';
import isUndefined from 'lodash/isUndefined';
const Option = Select.Option;
import {injectIntl} from 'react-intl';
 
@injectIntl
export default class SelectFilter extends Component {
  static propTypes = {
    onChange: PropTypes.func,
    name: PropTypes.string,
    options: PropTypes.array,
    label: PropTypes.string,
    intl: PropTypes.object,
  };
 
  static defaultProps = {
    options: []
  }
 
  onSelect = val => {
    const {onChange, options} = this.props;
    if (isUndefined(val)) {
      return onChange({});
    }
    const selectedCondition = options[val].condition;
    onChange(selectedCondition);
  }
 
  render() {
    const {options, intl} = this.props;
    const placeholder = intl.formatMessage({id: 'query.filter.select.placeholder'});
    return (
      <Select
        style={{width: 120}}
        placeholder={placeholder}
        onChange={(val) => this.onSelect(val)}
        allowClear
      >
        {options.map((cond, i) => (
          <Option value={i} key={i}>
            {cond.text}
          </Option>
        ))}
      </Select>
    );
  }
}