<commit_before>import React from 'components/react';

import BaseView from 'js/views/base-view';

// @todo Validate input on select onChange:
//    * Check if integer
//    * Check if value is within boundaries
//    * Check if properties belong to selected service

export default class ThemesNew extends BaseView {
  constructor(props) {
    super(props);

    this.state = {
      getters: [],
      setters: [],

      selectedGetterIndex: -1,
      selectedGetterValueIndex: -1,

      selectedSetterIndex: -1,
      selectedSetterValueIndex: -1
    };

    this.foxbox = props.foxbox;

    this.updateServices = this.updateServices.bind(this);
    this.onGetterSelected = this.onGetterSelected.bind(this);
    this.onGetterValueSelected = this.onGetterValueSelected.bind(this);
    this.onSetterSelected = this.onSetterSelected.bind(this);
    this.onSetterValueSelected = this.onSetterValueSelected.bind(this);
    this.onSaveRecipe = this.onSaveRecipe.bind(this);
  }

  componentDidMount() {
    Promise.all([
      this.foxbox.recipes.getGetters(),
      this.foxbox.recipes.getSetters()
    ])
    .then(services => this.updateServices(services))
    .catch(console.error.bind(console));
  }

  updateServices([getters, setters] = [[], []]) {
    this.setState({ getters, setters });
  }

  onGetterSelected(evt) {
    if (evt.target.value) {
      const selectedGetterIndex = Number(evt.target.value);
      this.setState({ selectedGetterIndex });
    } else {
      this.setState({
        selectedGetterIndex: -1,
        selectedGetterValueIndex: -1,

        selectedSetterIndex: -1,
        selectedSetterValueIndex: -1
      });
    }
  }

  onGetterValueSelected(evt) {
    if (evt.target.value) {
      const selectedGetterValueIndex = Number(evt.target.value);
      this.setState({ selectedGetterValueIndex });
    } else {
      this.setState({
        selectedGetterValueIndex: -1,

        selectedSetterIndex: -1,
        selectedSetterValueIndex: -1
      });
    }
  }

  onSetterSelected(evt) {
    if (evt.target.value) {
      const selectedSetterIndex = Number(evt.target.value);
      this.setState({ selectedSetterIndex });
    } else {
      this.setState({
        selectedSetterIndex: -1,
        selectedSetterValueIndex: -1
      });
    }
  }

  onSetterValueSelected(evt) {
    if (evt.target.value) {
      const selectedSetterValueIndex = Number(evt.target.value);
      this.setState({ selectedSetterValueIndex });
    } else {
      this.setState({
        selectedSetterValueIndex: -1
      });
    }
  }

  onSaveRecipe() {
    if (this.state.selectedSetterValueIndex < 0) {
      return;<commit_msg>In recipes, reset subsequent values when a field is updated. r=azasypkin (#100)<commit_after>import React from 'components/react';

import BaseView from 'js/views/base-view';

// @todo Validate input on select onChange:
//    * Check if integer
//    * Check if value is within boundaries
//    * Check if properties belong to selected service

export default class ThemesNew extends BaseView {
  constructor(props) {
    super(props);

    this.state = {
      getters: [],
      setters: [],

      selectedGetterIndex: -1,
      selectedGetterValueIndex: -1,

      selectedSetterIndex: -1,
      selectedSetterValueIndex: -1
    };

    this.foxbox = props.foxbox;

    this.updateServices = this.updateServices.bind(this);
    this.onGetterSelected = this.onGetterSelected.bind(this);
    this.onGetterValueSelected = this.onGetterValueSelected.bind(this);
    this.onSetterSelected = this.onSetterSelected.bind(this);
    this.onSetterValueSelected = this.onSetterValueSelected.bind(this);
    this.onSaveRecipe = this.onSaveRecipe.bind(this);
  }

  componentDidMount() {
    Promise.all([
      this.foxbox.recipes.getGetters(),
      this.foxbox.recipes.getSetters()
    ])
    .then(services => this.updateServices(services))
    .catch(console.error.bind(console));
  }

  updateServices([getters, setters] = [[], []]) {
    this.setState({ getters, setters });
  }

  onGetterSelected(evt) {
    let selectedGetterIndex = -1;

    if (evt.target.value) {
      selectedGetterIndex = Number(evt.target.value);
    }

    this.setState({
      selectedGetterIndex,
      selectedGetterValueIndex: -1,

      selectedSetterIndex: -1,
      selectedSetterValueIndex: -1
    });
  }

  onGetterValueSelected(evt) {
    let selectedGetterValueIndex = -1;

    if (evt.target.value) {
      selectedGetterValueIndex = Number(evt.target.value);
    }

    this.setState({
      selectedGetterValueIndex,

      selectedSetterIndex: -1,
      selectedSetterValueIndex: -1
    });
  }

  onSetterSelected(evt) {
    let selectedSetterIndex = -1;

    if (evt.target.value) {
      selectedSetterIndex = Number(evt.target.value);
    }

    this.setState({
      selectedSetterIndex,
      selectedSetterValueIndex: -1
    });
  }

  onSetterValueSelected(evt) {
    let selectedSetterValueIndex = -1;

    if (evt.target.value) {
      selectedSetterValueIndex = Number(evt.target.value);
    }

    this.setState({
      selectedSetterValueIndex
    });
  }

  onSaveRecipe() {
    if (this.state.selectedSetterValueIndex < 0) {
      return;
{'fraction_non_alphanumeric': 0.11825885978428351, 'fraction_numerical': 0.006355932203389831, 'mean_word_length': 2.9074492099322797, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '212138', 'n_tokens_mistral': 1614, 'n_tokens_neox': 1602, 'n_words': 282}