<commit_before>class PaginatedTable extends React.Component {

  // TODO: Set default and req'd props
  constructor(props) {
    super(props)
    this.state = {
      data: [],
      loading: null,
      err: null,

      limit: Number(this.getParameterByName('limit')) || props.limit,
      offset: Number(this.getParameterByName('offset')) || 0,
      search: this.getParameterByName('search') || '',
      ordering: this.getParameterByName('ordering') || '',

      count: 0,
      query: props.query || {},
    }
  }

  componentDidMount() {
    this.fetchData()
  }

  /**
   * Event handler to increment/decrement page of paginated data. Runs
   * fetchData() after value is set.
   * @param  {SyntheticEvent} event Event generated via onClick
   * @param  {Number} direction     Increment value for page (i.e. -1 for last page, 1 for next page)
   * @return {null}
   */
  changePage(event, direction){
    this.setState(
      previousState => {
        let change = (direction * previousState.limit);
        return {
          offset: Math.max(previousState.offset + change, 0)
        }
      },
      () => this.fetchData()
    )
  }

  /**
   * Event handler to alter number of elements per page of paginated data. Runs
   * fetchData() after value is set.
   * @param  {SyntheticEvent} event     Event generated via onClick
   * @return {null}
   */
  changeLimit(event) {
    const limit = Number(event.target.value)
    this.setState(
      prevState => {
        // Adjust offset so that it starts at an interval of the new limit
        // (i.e. if we were looking at third page of data, it will still show
        // third page of data with new values)
        let offset = Math.floor(prevState.offset / prevState.limit) * limit;
        // If new limit makes current page empty, set values so that view is
        // of last page that would contain data
        if (offset >= prevState.count) {
          offset = (Math.ceil(prevState.count / limit) - 1) * limit
        }
        return { limit, offset }
      },
      () => this.fetchData(false)
    )
  }

  /**
   * Set search query for API. Runs fetchData() after value is set.
   * @param  {String} value Query string
   * @return {null}
   */
  changeSearch(value) {
    this.setState({ search: value }, () => this.fetchData(false) )
  }

  /**
   * Set ordering value for API.
   * @param  {String} orderName Order value. Prepend with '-' for descending
   *                            order.
   * @return {null}
   */<commit_msg>Fixes #1995 -- Clear table offset when searching (#1996)<commit_after>class PaginatedTable extends React.Component {

  // TODO: Set default and req'd props
  constructor(props) {
    super(props)
    this.state = {
      data: [],
      loading: null,
      err: null,

      limit: Number(this.getParameterByName('limit')) || props.limit,
      offset: Number(this.getParameterByName('offset')) || 0,
      search: this.getParameterByName('search') || '',
      ordering: this.getParameterByName('ordering') || '',

      count: 0,
      query: props.query || {},
    }
  }

  componentDidMount() {
    this.fetchData()
  }

  /**
   * Event handler to increment/decrement page of paginated data. Runs
   * fetchData() after value is set.
   * @param  {SyntheticEvent} event Event generated via onClick
   * @param  {Number} direction     Increment value for page (i.e. -1 for last page, 1 for next page)
   * @return {null}
   */
  changePage(event, direction){
    this.setState(
      previousState => {
        let change = (direction * previousState.limit);
        return {
          offset: Math.max(previousState.offset + change, 0)
        }
      },
      () => this.fetchData()
    )
  }

  /**
   * Event handler to alter number of elements per page of paginated data. Runs
   * fetchData() after value is set.
   * @param  {SyntheticEvent} event     Event generated via onClick
   * @return {null}
   */
  changeLimit(event) {
    const limit = Number(event.target.value)
    this.setState({ limit, offset: 0 }, () => this.fetchData(false) )
  }

  /**
   * Set search query for API. Runs fetchData() after value is set.
   * @param  {String} value Query string
   * @return {null}
   */
  changeSearch(value) {
    this.setState({ search: value, offset: 0 }, () => this.fetchData(false) )
  }

  /**
   * Set ordering value for API.
   * @param  {String} orderName Order value. Prepend with '-' for descending
   *                            order.
   * @return {null}
   */
{'fraction_non_alphanumeric': 0.12424983329628807, 'fraction_numerical': 0.0046677039342076015, 'mean_word_length': 2.3758439609902475, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, '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': '7238547', 'n_tokens_mistral': 1349, 'n_tokens_neox': 1314, 'n_words': 403}