<commit_before>import React from "react";
import PropTypes from "prop-types";

import { Filter } from "../../controllers";

class CheckboxFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {string} name
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      name: PropTypes.string.isRequired
    };
  }

  render() {
    return <InputFacet type="checkbox" {...this.props} />;
  }
}

class RadioFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {string} name
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      name: PropTypes.string.isRequired
    };
  }

  render() {
    return <InputFacet type="radio" {...this.props} />;
  }
}

class SelectFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {string} name
   * @property {Object} options
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      name: PropTypes.string.isRequired,
      options: PropTypes.object.isRequired
    };
  }

  constructor(props) {
    super(props);

    this.state = { active: props.filter.isSet(props.name) };
  }

  componentDidMount() {
    this.unregister = this.props.filter.register(this.filterChanged);
  }

  componentWillUnmount() {
    this.unregister();
  }

  filterChanged = filter => {
    this.setState({ active: filter.get() });
  };

  handleChange = e => {
    filter.set(e.target.value, true);
  };

  render() {
    const { filter, name, options, ...rest } = this.props;

    const optionsRendered = Object.keys(options).map(o => {
      return (
        <option value={o} key={o}>
          {options[o]}
        </option>
      );
    });
    return (
      <select value={this.state.active} onChange={this.handleChange}>
        {optionsRendered}
      </select>
    );
  }
}

class InputFacet extends React.Component {
  constructor(props) {
    super(props);

    this.state = { active: props.filter.isSet(props.name) };
  }

  componentDidMount() {
    this.unregister = this.props.filter.register(this.filterChanged);<commit_msg>ui/facets: fix SelectFacet<commit_after>import React from "react";
import PropTypes from "prop-types";

import { Filter } from "../../controllers";

class CheckboxFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {string} name
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      name: PropTypes.string.isRequired
    };
  }

  render() {
    return <InputFacet type="checkbox" {...this.props} />;
  }
}

class RadioFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {string} name
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      name: PropTypes.string.isRequired
    };
  }

  render() {
    return <InputFacet type="radio" {...this.props} />;
  }
}

class SelectFacet extends React.Component {
  /**
   * propTypes
   * @property {Filter} filter
   * @property {Object} options
   */
  static get propTypes() {
    return {
      filter: PropTypes.instanceOf(Filter).isRequired,
      options: PropTypes.object.isRequired
    };
  }

  constructor(props) {
    super(props);

    const current = props.filter.get();
    if (current.length > 0) {
      this.state = { active: current[0] };
    }
  }

  componentDidMount() {
    this.unregister = this.props.filter.register(this.filterChanged);
  }

  componentWillUnmount() {
    this.unregister();
  }

  filterChanged = (filter) => {
    const current = this.props.filter.get();
    if (current.length > 0) {
      this.setState({ active: current[0] });
    }
  };

  handleChange = (e) => {
    this.props.filter.set(e.target.value, true);
  };

  render() {
    const { filter, name, options, ...rest } = this.props;

    const optionsRendered = Object.keys(options).map(o => {
      return (
        <option value={o} key={o}>
          {options[o]}
        </option>
      );
    });
    return (
      <select value={this.state.active} onChange={this.handleChange}>
        {optionsRendered}
      </select>
    );
  }
}

class InputFacet extends React.Component {
  constructor(props) {
    super(props);

    this.state = { active: props.filter.isSet(props.name) };
  }

  componentDidMount() {
    this.unregister = this.props.filter.register(this.filterChanged);
{'fraction_non_alphanumeric': 0.1472325530518486, 'fraction_numerical': 0.0008750820389411508, 'mean_word_length': 2.7231270358306188, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '80226', 'n_tokens_mistral': 1434, 'n_tokens_neox': 1434, 'n_words': 282}