<commit_before>import React from 'react';
import AutoSave from '../../../components/auto-save';

const MinMaxEditor = React.createClass({
  propTypes: {
    name: React.PropTypes.string,
    choice: React.PropTypes.object,
    workflow: React.PropTypes.object,
  },

  getInitialState() {
    return {
      min: null,
      max: null,
    };
  },

  componentWillMount() {
    this.setState({ min: this.props.choice.min, max: this.props.choice.max });
  },

  componentWillReceiveProps(newProps) {
    this.setState({ min: newProps.choice.min, max: newProps.choice.max });
  },

  onChangeMin(e) {
    this.setState({ min: e.target.value });
    this.updateWorkflow(e.target.name, e.target.value);
  },

  onChangeMax(e) {
    const newMax = e.target.value && e.target.value < this.state.min ?
      this.state.min :
      e.target.value;
    this.setState({ max: newMax });
    this.updateWorkflow(e.target.name, newMax);
  },

  updateWorkflow(name, value) {
    const changes = {};
    changes[name] = value;
    this.props.workflow.update(changes);
  },

  render() {
    return (
      <div className="min-max-editor workflow-choice-setting">
        <AutoSave resource={this.props.workflow}>
          Min{' '}
          <input
            type="number"
            inputMode="numeric"
            name={`${this.props.name}.min`}
            min="0"
            value={this.state.min}
            placeholder="0"
            size="5"
            style={{ width: '5ch' }}
            onChange={this.onChangeMin}
          />
        </AutoSave>
        <AutoSave resource={this.props.workflow}>
          Max{' '}
          <input
            type="number"
            inputMode="numeric"
            name={`${this.props.name}.max`}
            min={this.state.min ? this.state.min : 0}
            value={this.state.max}
            placeholder="∞"
            size="5"
            style={{ width: '5ch' }}
            onChange={this.onChangeMax}
          /><commit_msg>Edit the drawing tool itself Remove max/min keys if the corresponding inputs are empty.<commit_after>import React from 'react';
import AutoSave from '../../../components/auto-save';

const MinMaxEditor = React.createClass({
  propTypes: {
    name: React.PropTypes.string,
    choice: React.PropTypes.object,
    workflow: React.PropTypes.object,
  },

  getInitialState() {
    return {
      tool: null,
    };
  },

  componentWillMount() {
    this.setState({
      tool: this.props.choice,
    });
  },

  componentWillReceiveProps(newProps) {
    this.setState({
      tool: newProps.choice,
    });
  },

  onChangeMin(e) {
    const tool = this.state.tool;
    if (e.target.value) {
      tool.min = e.target.value;
    } else {
      delete tool.min;
    }
    this.updateWorkflow(tool);
  },

  onChangeMax(e) {
    const tool = this.state.tool;
    const newMax = e.target.value && e.target.value < this.state.tool.min ?
      this.state.tool.min :
      e.target.value;
    if (newMax) {
      tool.max = newMax;
    } else {
      delete tool.max;
    }
    this.updateWorkflow(tool);
  },

  updateWorkflow(tool) {
    const changes = {};
    changes[this.props.name] = tool;
    this.setState({ tool });
    this.props.workflow.update(changes);
  },

  render() {
    return (
      <div className="min-max-editor workflow-choice-setting">
        <AutoSave resource={this.props.workflow}>
          Min{' '}
          <input
            type="number"
            inputMode="numeric"
            name={`${this.props.name}.min`}
            min="0"
            value={this.state.tool.min}
            placeholder="0"
            size="5"
            style={{ width: '5ch' }}
            onChange={this.onChangeMin}
          />
        </AutoSave>
        <AutoSave resource={this.props.workflow}>
          Max{' '}
          <input
            type="number"
            inputMode="numeric"
            name={`${this.props.name}.max`}
            min={this.state.tool.min ? this.state.tool.min : 0}
            value={this.state.tool.max}
            placeholder="∞"
            size="5"
            style={{ width: '5ch' }}
            onChange={this.onChangeMax}
          />
{'fraction_non_alphanumeric': 0.15011990407673861, 'fraction_numerical': 0.003357314148681055, 'mean_word_length': 1.9623579545454546, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '3392888', 'n_tokens_mistral': 1295, 'n_tokens_neox': 1297, 'n_words': 220}