<commit_before>import React from 'react'
import propTypes from 'prop-types'

import MdClose from 'react-icons/lib/md/close'

import './SearchBar.css'
import { E2E_DISCOVER_PAGE_SEARCH_INPUT_ID } from '~data/e2eConstants'

class SearchBar extends React.Component {
  state = {
    inputValue: this.props.searchValue
  }
  handleSubmit = e => {
    e.preventDefault()
    this.props.onFormSubmit(this.state.inputValue)
  }
  handleChange = e => {
    const { value } = e.currentTarget
    this.setState(() => ({ inputValue: value }))
    if (value === '') {
      this.props.onCancelSearch()
    }
  }
  handleCancelSearchClicked = () => {
    const { onCancelSearch } = this.props
    this.setState(() => ({ inputValue: '' }))
    onCancelSearch()
  }
  render () {
    const { inputValue } = this.state
    const { albumsCount } = this.props
    const placeholder = `Search in ${albumsCount} albums`
    return (
      <form className='albums-page__search-bar' onSubmit={this.handleSubmit}>
        <input
          id={E2E_DISCOVER_PAGE_SEARCH_INPUT_ID}
          placeholder={placeholder}
          className='albums-page__search-input'
          type='text'
          value={inputValue}
          onChange={this.handleChange}
        />
        <button
          type='button'
          disabled={inputValue === ''}
          id='cancel-search'
          className='albums-page__cancel-search round-button'
          onClick={this.handleCancelSearchClicked}
        >
          <MdClose />
        </button>
      </form>
    )
  }
}

SearchBar.propTypes = {
  searchValue: propTypes.string.isRequired,
  albumsCount: propTypes.number.isRequired,
  onFormSubmit: propTypes.func.isRequired,
  onCancelSearch: propTypes.func.isRequired
}

export default SearchBar
<commit_msg>fix(): disable latest albums request on empty search if search was not performed<commit_after>import React from 'react'
import propTypes from 'prop-types'

import MdClose from 'react-icons/lib/md/close'

import './SearchBar.css'
import { E2E_DISCOVER_PAGE_SEARCH_INPUT_ID } from '~data/e2eConstants'

class SearchBar extends React.Component {
  state = {
    inputValue: this.props.searchValue
  }
  handleSubmit = e => {
    e.preventDefault()
    this.props.onFormSubmit(this.state.inputValue)
  }
  handleChange = e => {
    const { value } = e.currentTarget
    this.setState(() => ({ inputValue: value }))
    if (value === '' && this.props.searchValue !== '') {
      this.props.onCancelSearch()
    }
  }
  handleCancelSearchClicked = () => {
    const { onCancelSearch } = this.props
    this.setState(() => ({ inputValue: '' }))
    onCancelSearch()
  }
  render () {
    const { inputValue } = this.state
    const { albumsCount } = this.props
    const placeholder = `Search in ${albumsCount} albums`
    return (
      <form className='albums-page__search-bar' onSubmit={this.handleSubmit}>
        <input
          id={E2E_DISCOVER_PAGE_SEARCH_INPUT_ID}
          placeholder={placeholder}
          className='albums-page__search-input'
          type='text'
          value={inputValue}
          onChange={this.handleChange}
        />
        <button
          type='button'
          disabled={inputValue === ''}
          id='cancel-search'
          className='albums-page__cancel-search round-button'
          onClick={this.handleCancelSearchClicked}
        >
          <MdClose />
        </button>
      </form>
    )
  }
}

SearchBar.propTypes = {
  searchValue: propTypes.string.isRequired,
  albumsCount: propTypes.number.isRequired,
  onFormSubmit: propTypes.func.isRequired,
  onCancelSearch: propTypes.func.isRequired
}

export default SearchBar

{'fraction_non_alphanumeric': 0.12315270935960591, 'fraction_numerical': 0.0016420361247947454, 'mean_word_length': 2.8112617309697603, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 25, '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': '981504', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1110, 'n_words': 199}