<commit_before>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';

import api from './../store/api';
import { addRelation } from './../actions/relations';

import CreateRelation from './../components/CreateRelation';
import ObjectSearch from './../components/ObjectSearch';

require('./../css/normalize.css');
require('./../css/skeleton.css');
require('./../css/style.css');

const MainView = React.createClass({
  propTypes: {
    from: PropTypes.object.isRequired,
    to: PropTypes.object.isRequired,
    dispatch: PropTypes.func.isRequired,
  },

  getInitialState() {
    return {
      from: null,
      to: null,
      type: '',
    };
  },

  render() {
    return (
      <div className="container">
        <div id="object1" className="col">
          <ObjectSearch
            title="1. Find first PIT"
            results={this.props.from}
            onSearch={this.onFromSearch}
            onSelect={this.onFromSelect}
          />
        </div>
        <div id="relation" className="col">
          <CreateRelation
            title="3. Create a relation"
            schema={this.props.relationSchema}
            relations={this.props.relations}
            type={this.state.type}
            onTypeChange={this.onTypeChange}
            onRelationAdd={this.onRelationAdd}
          />
        </div>
        <div id="object2" className="col">
          <ObjectSearch
            title="2. Find second PIT"
            results={this.props.to}
            onSearch={this.onToSearch}
            onSelect={this.onToSelect}
          />
        </div>
      </div>
    );
  },

  componentDidMount() {
    // Fetch relation types
    this.props.dispatch(api.actions.relationSchema());
  },

  onTypeChange(type) {
    this.setState({ type });
  },

  onRelationAdd() {
    const { from, to, type } = this.state;

    // if (!from) {
    //   return alert('Select first pit');
    // } else if (!to) {
    //   return alert('Select second pit');
    // } else if (!type) {
    //   return alert('Select relationship type');
    // }

    this.props.dispatch(addRelation({ from, to, type }));
  },

  onFromSearch(q) {
    this.props.dispatch(api.actions.from({ q }));
  },

  onToSearch(q) {
    this.props.dispatch(api.actions.to({ q }));
  },

  onFromSelect(from) {
    this.setState({ from });
  },

  onToSelect(to) {
    this.setState({ to });
  },
});
<commit_msg>Clear query store when input is empty<commit_after>import React, { PropTypes } from 'react';
import { connect } from 'react-redux';

import api from './../store/api';
import { addRelation } from './../actions/relations';

import CreateRelation from './../components/CreateRelation';
import ObjectSearch from './../components/ObjectSearch';

require('./../css/normalize.css');
require('./../css/skeleton.css');
require('./../css/style.css');

const MainView = React.createClass({
  propTypes: {
    from: PropTypes.object.isRequired,
    to: PropTypes.object.isRequired,
    dispatch: PropTypes.func.isRequired,
  },

  getInitialState() {
    return {
      from: null,
      to: null,
      type: '',
    };
  },

  render() {
    return (
      <div className="container">
        <div id="object1" className="col">
          <ObjectSearch
            title="1. Find first PIT"
            results={this.props.from}
            onSearch={this.onFromSearch}
            onSelect={this.onFromSelect}
          />
        </div>
        <div id="relation" className="col">
          <CreateRelation
            title="3. Create a relation"
            schema={this.props.relationSchema}
            relations={this.props.relations}
            type={this.state.type}
            onTypeChange={this.onTypeChange}
            onRelationAdd={this.onRelationAdd}
          />
        </div>
        <div id="object2" className="col">
          <ObjectSearch
            title="2. Find second PIT"
            results={this.props.to}
            onSearch={this.onToSearch}
            onSelect={this.onToSelect}
          />
        </div>
      </div>
    );
  },

  componentDidMount() {
    // Fetch relation types
    this.props.dispatch(api.actions.relationSchema());
  },

  onTypeChange(type) {
    this.setState({ type });
  },

  onRelationAdd() {
    const { from, to, type } = this.state;

    // if (!from) {
    //   return alert('Select first pit');
    // } else if (!to) {
    //   return alert('Select second pit');
    // } else if (!type) {
    //   return alert('Select relationship type');
    // }

    this.props.dispatch(addRelation({ from, to, type }));
  },

  onFromSearch(q) {
    if (q) {
      this.props.dispatch(api.actions.from({ q }));
    } else {
      this.props.dispatch(api.actions.from.reset());
    }
  },

  onToSearch(q) {
    if (q) {
      this.props.dispatch(api.actions.to({ q }));
    } else {
      this.props.dispatch(api.actions.to.reset());
    }
  },

  onFromSelect(from) {
    this.setState({ from });
  },

  onToSelect(to) {
    this.setState({ to });
  },
});

{'fraction_non_alphanumeric': 0.16348448687350836, 'fraction_numerical': 0.001988862370723946, 'mean_word_length': 2.121663563004345, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '1175565', 'n_tokens_mistral': 1537, 'n_tokens_neox': 1530, 'n_words': 290}