<commit_before>import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import * as selectors from '../selectors';
import {getIsLoading as getIsUnitLoading} from '../../unit/selectors';
import {searchUnits, fetchUnitSuggestions, clearSearch} from '../actions';
import SearchBar from './SearchBar';
import SearchSuggestions from './SearchSuggestions';


class SearchContainer extends Component {
  static propTypes = {
    unitSuggestions: PropTypes.array,
    searchUnits: PropTypes.func,
    fetchUnitSuggestions: PropTypes.func,
    searchDisabled: PropTypes.bool,
    onSearch: PropTypes.func
  }

  constructor(props) {
    super(props);

    this.state = {
      searchPhrase: ''
    };

    this.search = this.search.bind(this);
    this.getSuggestions = this.getSuggestions.bind(this);
    this.onInputChange = this.onInputChange.bind(this);
    this.clear = this.clear.bind(this);
  }

  onInputChange(value: string) {
    this.setState({searchPhrase: value});
    this.getSuggestions(value);
  }

  search() {
    this.props.searchUnits(this.state.searchPhrase);
    this.props.onSearch(this.state.searchPhrase);
  }

  getSuggestions(searchPhrase: string) {
    this.props.fetchUnitSuggestions(searchPhrase);
  }

  clear() {
    this.setState({searchPhrase: ''});
    this.props.clearSearch();
  }

  render() {
    const {unitSuggestions, isActive, searchDisabled} = this.props;
    const {searchPhrase} = this.state;

    return (
      <div className="search-container">
        <SearchBar
          input={searchPhrase}
          onInput={this.onInputChange}
          onSubmit={this.search}
          onClear={this.clear}
          searchActive={isActive}
          disabled={searchDisabled} />
        <SearchSuggestions openAllResults={this.search} units={unitSuggestions}/>
      </div>
    );
  }
}
<commit_msg>Fix show search suggestions logic<commit_after>import React, {Component, PropTypes} from 'react';
import {bindActionCreators} from 'redux';
import {connect} from 'react-redux';
import * as selectors from '../selectors';
import {getIsLoading as getIsUnitLoading} from '../../unit/selectors';
import {searchUnits, fetchUnitSuggestions, clearSearch} from '../actions';
import SearchBar from './SearchBar';
import SearchSuggestions from './SearchSuggestions';

const InitialState = {
  searchPhrase: '',
  showSuggestions: false
};


class SearchContainer extends Component {
  static propTypes = {
    unitSuggestions: PropTypes.array,
    searchUnits: PropTypes.func,
    fetchUnitSuggestions: PropTypes.func,
    searchDisabled: PropTypes.bool,
    onSearch: PropTypes.func
  }

  constructor(props) {
    super(props);

    this.state = InitialState;

    this.search = this.search.bind(this);
    this.getSuggestions = this.getSuggestions.bind(this);
    this.onInputChange = this.onInputChange.bind(this);
    this.clear = this.clear.bind(this);
  }

  onInputChange(value: string) {
    this.setState({
      searchPhrase: value,
      showSuggestions: true
    });
    this.getSuggestions(value);
  }

  search() {
    this.props.searchUnits(this.state.searchPhrase);
    this.props.onSearch(this.state.searchPhrase);
    this.setState({
      showSuggestions: false
    });
  }

  getSuggestions(searchPhrase: string) {
    this.props.fetchUnitSuggestions(searchPhrase);
  }

  clear() {
    this.setState(InitialState);
    this.props.clearSearch();
  }

  render() {
    const {unitSuggestions, isActive, searchDisabled} = this.props;
    const {searchPhrase, showSuggestions} = this.state;

    return (
      <div className="search-container">
        <SearchBar
          input={searchPhrase}
          onInput={this.onInputChange}
          onSubmit={this.search}
          onClear={this.clear}
          searchActive={isActive}
          disabled={searchDisabled} />
        {showSuggestions && <SearchSuggestions openAllResults={this.search} units={unitSuggestions}/>}
      </div>
    );
  }
}

{'fraction_non_alphanumeric': 0.12587238285144567, 'fraction_numerical': 0.0, 'mean_word_length': 3.503928170594837, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1783161', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1193, 'n_words': 225}