<commit_before>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { setCollectionSelection, setCollectionAndQuery } from '../../minimongo/actions';
import { setTabIndex } from '../../../common/actions';
import { MINIMONGO_TAB_INDEX } from '../../../common/constants';

class JSONTreeItem extends Component {
  
  _printValue () {
    // if data is an array, 
    // check the first item to get collection name
    let data = this.props.data;
    if(Array.isArray(this.props.data) && this.props.data.length){
      data = this.props.data[0];
    } 
    if((data.msg === 'added' || data.msg === 'changed') &&
      (this.props.label === 'id' || this.props.label === 'collection')) {
      return (
        <span onClick={this.props.setMinimongoState}>
          "<span className="collection-link">{this.props.raw}</span>"
        </span>);
    } else {
      return (<span>{this.props.value}</span>);
    }
  }

  render () {
    return (<span>{this._printValue()}</span>);
  }
};

JSONTreeItem.propTypes = {
  value: PropTypes.string.isRequired,
  label: PropTypes.string.isRequired,
  data: React.PropTypes.oneOfType([
            React.PropTypes.object,
            React.PropTypes.array
        ]).isRequired,
  raw: PropTypes.string.isRequired,
  setMinimongoState: PropTypes.func.isRequired
};

const mapDispatchToProps = (dispatch, ownProps) => {
  const query = ['{ query : {',
    '"_id":"', ownProps.raw,
    '"}, fields: {}, sort: {} }'
  ].join('');
  return {
    setMinimongoState: () => {
      // if data is an array, 
      // check the first item to get collection name
      let data = ownProps.data;
      if(Array.isArray(ownProps.data) && ownProps.data.length){
        data = ownProps.data[0];
      } 
      if(ownProps.label === 'id'){
        dispatch(setCollectionAndQuery(data.collection, query));
      }
      if(ownProps.label === 'collection'){
        dispatch(setCollectionSelection(data.collection));
      }
    }
  };
};

export default connect(null, mapDispatchToProps)(JSONTreeItem);<commit_msg>make query more expressive<commit_after>import React, { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import { setCollectionSelection, setCollectionAndQuery } from '../../minimongo/actions';
import { setTabIndex } from '../../../common/actions';
import { MINIMONGO_TAB_INDEX } from '../../../common/constants';

class JSONTreeItem extends Component {
  
  _printValue () {
    // if data is an array, 
    // check the first item to get collection name
    let data = this.props.data;
    if(Array.isArray(this.props.data) && this.props.data.length){
      data = this.props.data[0];
    } 
    if((data.msg === 'added' || data.msg === 'changed') &&
      (this.props.label === 'id' || this.props.label === 'collection')) {
      return (
        <span onClick={this.props.setMinimongoState}>
          "<span className="collection-link">{this.props.raw}</span>"
        </span>);
    } else {
      return (<span>{this.props.value}</span>);
    }
  }

  render () {
    return (<span>{this._printValue()}</span>);
  }
};

JSONTreeItem.propTypes = {
  value: PropTypes.string.isRequired,
  label: PropTypes.string.isRequired,
  data: React.PropTypes.oneOfType([
            React.PropTypes.object,
            React.PropTypes.array
        ]).isRequired,
  raw: PropTypes.string.isRequired,
  setMinimongoState: PropTypes.func.isRequired
};

const mapDispatchToProps = (dispatch, ownProps) => {
  const query = `{ query : {"_id":"${ownProps.raw}"}, fields: {}, sort: {} }`;
  return {
    setMinimongoState: () => {
      // if data is an array, 
      // check the first item to get collection name
      let data = ownProps.data;
      if(Array.isArray(ownProps.data) && ownProps.data.length){
        data = ownProps.data[0];
      } 
      if(ownProps.label === 'id'){
        dispatch(setCollectionAndQuery(data.collection, query));
      }
      if(ownProps.label === 'collection'){
        dispatch(setCollectionSelection(data.collection));
      }
    }
  };
};

export default connect(null, mapDispatchToProps)(JSONTreeItem);
{'fraction_non_alphanumeric': 0.1652992277992278, 'fraction_numerical': 0.0009652509652509653, 'mean_word_length': 2.9140698772426816, 'pattern_counts': {'":': 2, '<': 19, '<?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': '5822264', 'n_tokens_mistral': 1263, 'n_tokens_neox': 1273, 'n_words': 254}