<commit_before>import PropTypes from 'prop-types'
import React, {PureComponent, ChangeEvent} from 'react'

import _ from 'lodash'

import {showMeasurements} from 'src/shared/apis/metaQuery'
import showMeasurementsParser from 'src/shared/parsing/showMeasurements'

import {Query, Source} from 'src/types'

import FancyScrollbar from 'src/shared/components/FancyScrollbar'
import MeasurementListFilter from 'src/shared/components/MeasurementListFilter'
import MeasurementListItem from 'src/shared/components/MeasurementListItem'

interface Props {
  query: Query
  querySource: Source
  onChooseTag: () => void
  onGroupByTag: () => void
  onToggleTagAcceptance: () => void
  onChooseMeasurement: (measurement: string) => void
}

interface State {
  measurements: string[]
  filterText: string
  filtered: string[]
}

const {shape} = PropTypes

class MeasurementList extends PureComponent<Props, State> {
  public static contextTypes = {
    source: shape({
      links: shape({}).isRequired,
    }).isRequired,
  }

  public static defaultProps: Partial<Props> = {
    querySource: null,
  }

  constructor(props) {
    super(props)
    this.state = {
      filterText: '',
      filtered: [],
      measurements: [],
    }

    this.handleEscape = this.handleEscape.bind(this)
    this.handleFilterText = this.handleFilterText.bind(this)
    this.handleAcceptReject = this.handleAcceptReject.bind(this)
    this.handleFilterMeasuremet = this.handleFilterMeasuremet.bind(this)
    this.handleChoosemeasurement = this.handleChoosemeasurement.bind(this)
  }

  public componentDidMount() {
    if (!this.props.query.database) {
      return
    }

    this.getMeasurements()
  }

  public componentDidUpdate(prevProps) {
    const {query, querySource} = this.props

    if (!query.database) {
      return
    }

    if (
      prevProps.query.database === query.database &&
      _.isEqual(prevProps.querySource, querySource)
    ) {
      return
    }

    this.getMeasurements()
  }

  public handleFilterText(e: ChangeEvent<HTMLInputElement>) {
    e.stopPropagation()
    const filterText = e.target.value
    this.setState({
      filterText,
      filtered: this.handleFilterMeasuremet(filterText),
    })
  }

  public handleFilterMeasuremet(filter) {
    return this.state.measurements.filter(m =>
      m.toLowerCase().includes(filter.toLowerCase())
    )<commit_msg>Remove unnecessary type<commit_after>import PropTypes from 'prop-types'
import React, {PureComponent} from 'react'

import _ from 'lodash'

import {showMeasurements} from 'src/shared/apis/metaQuery'
import showMeasurementsParser from 'src/shared/parsing/showMeasurements'

import {Query, Source} from 'src/types'

import FancyScrollbar from 'src/shared/components/FancyScrollbar'
import MeasurementListFilter from 'src/shared/components/MeasurementListFilter'
import MeasurementListItem from 'src/shared/components/MeasurementListItem'

interface Props {
  query: Query
  querySource: Source
  onChooseTag: () => void
  onGroupByTag: () => void
  onToggleTagAcceptance: () => void
  onChooseMeasurement: (measurement: string) => void
}

interface State {
  measurements: string[]
  filterText: string
  filtered: string[]
}

const {shape} = PropTypes

class MeasurementList extends PureComponent<Props, State> {
  public static contextTypes = {
    source: shape({
      links: shape({}).isRequired,
    }).isRequired,
  }

  public static defaultProps: Partial<Props> = {
    querySource: null,
  }

  constructor(props) {
    super(props)
    this.state = {
      filterText: '',
      filtered: [],
      measurements: [],
    }

    this.handleEscape = this.handleEscape.bind(this)
    this.handleFilterText = this.handleFilterText.bind(this)
    this.handleAcceptReject = this.handleAcceptReject.bind(this)
    this.handleFilterMeasuremet = this.handleFilterMeasuremet.bind(this)
    this.handleChoosemeasurement = this.handleChoosemeasurement.bind(this)
  }

  public componentDidMount() {
    if (!this.props.query.database) {
      return
    }

    this.getMeasurements()
  }

  public componentDidUpdate(prevProps) {
    const {query, querySource} = this.props

    if (!query.database) {
      return
    }

    if (
      prevProps.query.database === query.database &&
      _.isEqual(prevProps.querySource, querySource)
    ) {
      return
    }

    this.getMeasurements()
  }

  public handleFilterText(e) {
    e.stopPropagation()
    const filterText = e.target.value
    this.setState({
      filterText,
      filtered: this.handleFilterMeasuremet(filterText),
    })
  }

  public handleFilterMeasuremet(filter) {
    return this.state.measurements.filter(m =>
      m.toLowerCase().includes(filter.toLowerCase())
    )
{'fraction_non_alphanumeric': 0.10861264319049639, 'fraction_numerical': 0.0, 'mean_word_length': 3.7771023302938196, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 18, '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': '4882802', 'n_tokens_mistral': 1421, 'n_tokens_neox': 1393, 'n_words': 276}