<commit_before>var r = require('r-dom')
var React = require('react')
var debug = require('debug')('tag-select')
var keys = require('lodash.keys')
var each = require('lodash.foreach')
var Typeahead = require('simple-react-typeahead')

module.exports = React.createClass({
  propTypes: {
    style: React.PropTypes.object,
    tagData: React.PropTypes.object.isRequired,
    updateTag: React.PropTypes.func.isRequired
  },

  getInitialState: function () {
    this.props.tagData
    return {
      Map: {}
    }
  },

  componentWillReceiveProps: function (nextProps) {
    var options = []
    var labelToTypeMap = {}
    var labelToDataMap = {}
    var tagData = this.props.tagData
    var withPred = tagData.triple.predicate.active
    each(tagData.triple, function (expression) {
      if(!expression.active) {
        var label = withPred ? expression.withPredLabel : expression.label
        options.push(label)
        labelToTypeMap[label] = 'triple'
        labelToDataMap[label] = expression
      }
    })

    each(tagData.filters, function (filter) {
      if (!filter.active) {
        var label = filter.label
        options.push(label)
        labelToTypeMap[label] = 'filters'
        labelToDataMap[label] = filter
      }
    })

    this.setState({ labelToTypeMap: labelToTypeMap, labelToDataMap: labelToDataMap, options: options })
  },

  render: function () {
    return r.div({ className: 'tag-select' }, [
      r(Typeahead, {
          id: 'test',
          style: this.props.style,
          array: this.state.options,
          placeholder: 'Boo',
          onSelect: this.handleSelect
        }
      )
    ])
  },

  handleSelect: function (label) {
    var type = this.state.labelToTypeMap[label]
    var id = this.state.labelToDataMap[label].id

    this.props.updateTag(type, id, true)()
  }
})<commit_msg>use new typeahead id functionality<commit_after>var r = require('r-dom')
var React = require('react')
var debug = require('debug')('tag-select')
var keys = require('lodash.keys')
var each = require('lodash.foreach')
var Typeahead = require('simple-react-typeahead')

module.exports = React.createClass({
  propTypes: {
    style: React.PropTypes.object,
    tagData: React.PropTypes.object.isRequired,
    updateTag: React.PropTypes.func.isRequired
  },

  getInitialState: function () {
    this.props.tagData
    return {
      Map: {}
    }
  },

  componentWillReceiveProps: function (nextProps) {
    var options = []
    var idToTypeMap = {}
    var tagData = nextProps.tagData
    each(tagData.triple, function (expression, key) {
      debug('all expressions', expression)
      if(!expression.active) {
        debug('expression for options', expression)
        options.push({id: expression.id, label: expression.label})
        idToTypeMap[expression.id] = 'triple'
      }
    })

    each(tagData.filters, function (filter) {
      if (!filter.active) {
        options.push({id: filter.id, label: filter.label})
        idToTypeMap[filter.id] = 'filters'
      }
    })

    this.setState({ idToTypeMap: idToTypeMap, options: options })
  },

  render: function () {
    return r.div({ className: 'tag-select' }, [
      r(Typeahead, {
          id: 'test',
          style: this.props.style,
          array: this.state.options,
          placeholder: 'Boo',
          onSelect: this.handleSelect
        }
      )
    ])
  },

  handleSelect: function (id) {
    var type = this.state.idToTypeMap[id]
    debug('id', id  )
    this.props.updateTag(type, id, true)()
  }
})
{'fraction_non_alphanumeric': 0.1335412531896796, 'fraction_numerical': 0.0, 'mean_word_length': 2.769230769230769, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '400680', 'n_tokens_mistral': 1114, 'n_tokens_neox': 1089, 'n_words': 218}