<commit_before>import cx from 'classnames';
import * as React from 'react';
import debounce from 'lodash/debounce';
import IconButton from 'material-ui/IconButton';
import FilterIcon from 'material-ui/svg-icons/action/search';

export default class PlaylistFilter extends React.Component {
  static propTypes = {
    onFilter: React.PropTypes.func.isRequired
  };

  state = {
    open: false,
    value: ''
  };

  onFilter = debounce(value => {
    this.props.onFilter(value);
  }, 200);

  clearFilter() {
    if (this.state.value !== '') {
      this.props.onFilter('');
    }
  }

  handleClick = () => {
    const isOpen = !this.state.open;
    if (isOpen) {
      this.input.focus();
    } else {
      this.clearFilter();
    }

    this.setState({
      open: isOpen,
      value: ''
    });
  };

  handleChange = event => {
    this.setState({ value: event.target.value });
    this.onFilter(event.target.value);
  };

  refInput = input => {
    this.input = input;
  };

  render() {
    const isOpen = this.state.open;
    return (
      <div className="PlaylistMediaFilter">
        <IconButton onClick={this.handleClick}>
          <FilterIcon color={isOpen ? '#fff' : '#555'} hoverColor="#fff" />
        </IconButton>
        <input
          type="text"
          ref={this.refInput}
          className={cx('PlaylistMediaFilter-input', isOpen && 'is-open')}
          value={this.state.value}
          onChange={this.handleChange}
        />
      </div>
    );
  }
}
<commit_msg>playlists: fix filter input autofocus<commit_after>import cx from 'classnames';
import * as React from 'react';
import debounce from 'lodash/debounce';
import IconButton from 'material-ui/IconButton';
import FilterIcon from 'material-ui/svg-icons/action/search';

export default class PlaylistFilter extends React.Component {
  static propTypes = {
    onFilter: React.PropTypes.func.isRequired
  };

  state = {
    open: false,
    value: ''
  };

  onFilter = debounce(value => {
    this.props.onFilter(value);
  }, 200);

  clearFilter() {
    if (this.state.value !== '') {
      this.props.onFilter('');
    }
  }

  handleClick = () => {
    const isOpen = !this.state.open;

    if (!isOpen) {
      this.clearFilter();
    }

    this.setState({
      open: isOpen,
      value: ''
    }, () => {
      if (isOpen) {
        this.input.focus();
      }
    });
  };

  handleChange = event => {
    this.setState({ value: event.target.value });
    this.onFilter(event.target.value);
  };

  refInput = input => {
    this.input = input;
  };

  render() {
    const isOpen = this.state.open;
    return (
      <div className="PlaylistMediaFilter">
        <IconButton onClick={this.handleClick}>
          <FilterIcon color={isOpen ? '#fff' : '#555'} hoverColor="#fff" />
        </IconButton>
        <input
          type="text"
          ref={this.refInput}
          className={cx('PlaylistMediaFilter-input', isOpen && 'is-open')}
          value={this.state.value}
          onChange={this.handleChange}
        />
      </div>
    );
  }
}

{'fraction_non_alphanumeric': 0.15457516339869282, 'fraction_numerical': 0.00392156862745098, 'mean_word_length': 2.435465768799102, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 24, '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': '7554408', 'n_tokens_mistral': 986, 'n_tokens_neox': 960, 'n_words': 185}