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

import ReactDOM from 'react-dom'
import $ from 'jquery'

import {removeMetrics, changeMetric} from 'gModules/metrics/actions'
import {changeGuesstimate} from 'gModules/guesstimates/actions'

import MetricModal from 'gComponents/metrics/modal/index'
import DistributionEditor from 'gComponents/distributions/editor/index'
import MetricToolTip from './tooltip'
import ToolTip from 'gComponents/utility/tooltip/index'
import MetricCardViewSection from './MetricCardViewSection/index'
import SensitivitySection from './SensitivitySection/SensitivitySection'

import {hasMetricUpdated} from './updated'

import * as canvasStateProps from 'gModules/canvas_state/prop_type'
import {PTLocation} from 'lib/locationUtils'

import './style.css'

const INTERMEDIATE = 'INTERMEDIATE'
const OUTPUT = 'OUTPUT'
const INPUT = 'INPUT'
const NOEDGE = 'NOEDGE'

const relationshipClasses = {}
relationshipClasses[INTERMEDIATE] = 'intermediate'
relationshipClasses[OUTPUT] = 'output'
relationshipClasses[INPUT] = 'input'
relationshipClasses[NOEDGE] = 'noedge'

const relationshipType = (edges) => {
  if (edges.inputs.length && edges.outputs.length) { return INTERMEDIATE }
  if (edges.inputs.length) { return OUTPUT }
  if (edges.outputs.length) { return INPUT }
  return NOEDGE
}

class ScatterTip extends Component {
  render() {
    return (
      <ToolTip size='LARGE'>
        <SensitivitySection yMetric={this.props.yMetric} xMetric={this.props.xMetric} size={'LARGE'}/>
      </ToolTip>
    )
  }
}

const PT = PropTypes

@connect()
export default class MetricCard extends Component {
  displayName: 'MetricCard'

  static propTypes = {
    canvasState: canvasStateProps.canvasState,
    dispatch: PT.func.isRequired,
    gridKeyPress: PT.func.isRequired,
    inSelectedCell: PT.bool.isRequired,
    location: PTLocation,
    metric: PT.object.isRequired
  }

  state = {modalIsOpen: false};

  shouldComponentUpdate(nextProps, nextState) {
    return hasMetricUpdated(this.props, nextProps) || (this.state.modalIsOpen !== nextState.modalIsOpen)
  }

  componentDidUpdate(prevProps) {
    const hasContent = this.refs.MetricCardViewSection.hasContent()
    if (!this.props.inSelectedCell && this._isEmpty() && !hasContent && !this.state.modalIsOpen){
      this.handleRemoveMetric()
    }
    if (!prevProps.inSelectedCell && this.props.inSelectedCell && !!this.props.selectedFrom) {
      if (this.props.selectedFrom === 'UP' || this.props.selectedFrom === 'LEFT') {
        console.log("Focusing Name")
        this.refs.MetricCardViewSection.focusName()
      } else if (this.props.selectedFrom === 'DOWN' || this.props.selectedFrom === 'RIGHT') {
        console.log("Focusing Form")
        this._focusForm()
      }
    }
  }

  componentDidMount() {
    if (this.props.inSelectedCell && this._isEmpty()) {
      if (this.props.selectedFrom === 'UP' || this.props.selectedFrom === 'LEFT') {
        console.log("Focusing Name")
        this.refs.MetricCardViewSection.focusName()
      } else if (this.props.selectedFrom === 'DOWN' || this.props.selectedFrom === 'RIGHT') {
        console.log("Focusing Form")
        this._focusForm()
      } else {
        this.refs.MetricCardViewSection.focusName()
      }
    }
  }

  openModal() {
    this.setState({modalIsOpen: true});
  }

  closeModal() {
     this.setState({modalIsOpen: false});
  }

  _handleKeyDown(e) {
    if (e.target === ReactDOM.findDOMNode(this)) {
      if (e.keyCode == '13' && this.props.inSelectedCell) {
        e.preventDefault()<commit_msg>Code Cleanup.<commit_after>import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'

import ReactDOM from 'react-dom'
import $ from 'jquery'

import {removeMetrics, changeMetric} from 'gModules/metrics/actions'
import {changeGuesstimate} from 'gModules/guesstimates/actions'

import MetricModal from 'gComponents/metrics/modal/index'
import DistributionEditor from 'gComponents/distributions/editor/index'
import MetricToolTip from './tooltip'
import ToolTip from 'gComponents/utility/tooltip/index'
import MetricCardViewSection from './MetricCardViewSection/index'
import SensitivitySection from './SensitivitySection/SensitivitySection'

import {hasMetricUpdated} from './updated'

import * as canvasStateProps from 'gModules/canvas_state/prop_type'
import {PTLocation} from 'lib/locationUtils'

import './style.css'

const INTERMEDIATE = 'INTERMEDIATE'
const OUTPUT = 'OUTPUT'
const INPUT = 'INPUT'
const NOEDGE = 'NOEDGE'

const relationshipClasses = {}
relationshipClasses[INTERMEDIATE] = 'intermediate'
relationshipClasses[OUTPUT] = 'output'
relationshipClasses[INPUT] = 'input'
relationshipClasses[NOEDGE] = 'noedge'

const relationshipType = (edges) => {
  if (edges.inputs.length && edges.outputs.length) { return INTERMEDIATE }
  if (edges.inputs.length) { return OUTPUT }
  if (edges.outputs.length) { return INPUT }
  return NOEDGE
}

class ScatterTip extends Component {
  render() {
    return (
      <ToolTip size='LARGE'>
        <SensitivitySection yMetric={this.props.yMetric} xMetric={this.props.xMetric} size={'LARGE'}/>
      </ToolTip>
    )
  }
}

const PT = PropTypes

@connect()
export default class MetricCard extends Component {
  displayName: 'MetricCard'

  static propTypes = {
    canvasState: canvasStateProps.canvasState,
    dispatch: PT.func.isRequired,
    gridKeyPress: PT.func.isRequired,
    inSelectedCell: PT.bool.isRequired,
    location: PTLocation,
    metric: PT.object.isRequired
  }

  state = {modalIsOpen: false};

  shouldComponentUpdate(nextProps, nextState) {
    return hasMetricUpdated(this.props, nextProps) || (this.state.modalIsOpen !== nextState.modalIsOpen)
  }

  componentDidUpdate(prevProps) {
    const hasContent = this.refs.MetricCardViewSection.hasContent()
    if (!this.props.inSelectedCell && this._isEmpty() && !hasContent && !this.state.modalIsOpen){
      this.handleRemoveMetric()
    }
    if (!prevProps.inSelectedCell && this.props.inSelectedCell && !!this.props.selectedFrom) {
      if (this.props.selectedFrom === 'UP' || this.props.selectedFrom === 'LEFT') {
        this.refs.MetricCardViewSection.focusName()
      } else if (this.props.selectedFrom === 'DOWN' || this.props.selectedFrom === 'RIGHT') {
        this._focusForm()
      }
    }
  }

  componentDidMount() {
    if (this.props.inSelectedCell && this._isEmpty()) {
      if (this.props.selectedFrom === 'DOWN' || this.props.selectedFrom === 'RIGHT') {
        this._focusForm()
      } else {
        this.refs.MetricCardViewSection.focusName()
      }
    }
  }

  openModal() {
    this.setState({modalIsOpen: true});
  }

  closeModal() {
     this.setState({modalIsOpen: false});
  }

  _handleKeyDown(e) {
    if (e.target === ReactDOM.findDOMNode(this)) {
      if (e.keyCode == '13' && this.props.inSelectedCell) {
        e.preventDefault()
{'fraction_non_alphanumeric': 0.1300273893613954, 'fraction_numerical': 0.0005766181346403345, 'mean_word_length': 4.108983799705449, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '507924', 'n_tokens_mistral': 2134, 'n_tokens_neox': 2110, 'n_words': 431}