<commit_before>import _ from 'lodash';
import React from 'react/addons';
import {Input} from 'react-bootstrap';
import {SelectorMenu} from 'sprintly-ui';

var DropdownFilter = React.createClass({

  propTypes: {
    name: React.PropTypes.string.isRequired,
    updateFilters: React.PropTypes.func,
    options: React.PropTypes.array
  },

  getDefaultProps: function() {
    return {
      options: [],
      updateFilters: function() {}
    }
  },

  onChange: function(member) {
    let value = member.value;
    this.props.updateFilters(this.props.name, value)
  },

  update: function(field, value, ev) {
    let checked = ev.target.checked;
    let criteria = '';
    let options = {};

    if (!checked) {
      options.unset = true;
    }

    if (checked && field === 'me') {
      criteria = value;
    }
    this.props.updateFilters(this.props.name, criteria, options);
  },

  renderMembers: function(option) {
    let active = _.findWhere(option.members, { id: this.props.criteria });
    let defaultSelection = active ? `${active.first_name} ${active.last_name.slice(0,1)}.` : '';

    let members = _.map(option.members, function(member) {
      let title = `${member.first_name} ${member.last_name.slice(0,1)}.`;
      return {
        title,
        value: member.id
      }
    }, this);

    return (
      <div className="form-group selector" key="members-dropdown">
        <SelectorMenu
          optionsList={_.sortBy(members, 'title')}
          defaultSelection={defaultSelection}
          onSelectionChange={(title) => {
            this.onChange(_.findWhere(members, { title }))
          }}
        />
      </div>
    );
  },

  renderCriteriaFormField: function(option) {
    if (option.members) {
      return this.renderMembers(option);
    }
<commit_msg>use SelectorMenu as a controlled component<commit_after>import _ from 'lodash';
import React from 'react/addons';
import {Input} from 'react-bootstrap';
import {SelectorMenu} from 'sprintly-ui';

var DropdownFilter = React.createClass({

  propTypes: {
    name: React.PropTypes.string.isRequired,
    updateFilters: React.PropTypes.func,
    options: React.PropTypes.array
  },

  getDefaultProps: function() {
    return {
      options: [],
      updateFilters: function() {}
    }
  },

  onChange: function(member) {
    let value = member.value;
    this.props.updateFilters(this.props.name, value)
  },

  update: function(field, value, ev) {
    let checked = ev.target.checked;
    let criteria = '';
    let options = {};

    if (!checked) {
      options.unset = true;
    }

    if (checked && field === 'me') {
      criteria = value;
    }
    this.props.updateFilters(this.props.name, criteria, options);
  },

  renderMembers: function(option) {
    let active = _.findWhere(option.members, { id: this.props.criteria });
    let selection = active ? `${active.first_name} ${active.last_name.slice(0,1)}.` : '';

    let members = _.map(option.members, function(member) {
      let title = `${member.first_name} ${member.last_name.slice(0,1)}.`;
      return {
        title,
        value: member.id
      }
    }, this);

    return (
      <div className="form-group selector" key="members-dropdown">
        <SelectorMenu
          optionsList={_.sortBy(members, 'title')}
          selection={selection}
          onSelectionChange={(title) => {
            this.onChange(_.findWhere(members, { title }))
          }}
        />
      </div>
    );
  },

  renderCriteriaFormField: function(option) {
    if (option.members) {
      return this.renderMembers(option);
    }

{'fraction_non_alphanumeric': 0.14517029592406477, 'fraction_numerical': 0.002233389168062535, 'mean_word_length': 2.740083507306889, 'pattern_counts': {'":': 0, '<': 9, '<?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': '930529', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1094, 'n_words': 217}