<commit_before>import React from 'react'
import reject from 'lodash/collection/reject'
import Group from './Group'
import stringify from '../stringify'
import styles from '../styles'


function toPropValue(x) {
  if (typeof x === 'string') {
    return stringify(x)
  }
  return `{${stringify(x)}}`
}

function upFirst(str) {
  return str.slice(0, 1).toUpperCase() + str.slice(1)
}

export default React.createClass({

  displayName: 'Demo.Controls.RenderCode',

  propTypes: {
    name: React.PropTypes.string.isRequired,
    props: React.PropTypes.object.isRequired,
    callbacks: React.PropTypes.object.isRequired
  },

  getPropCode(key) {
    return `${key}=${toPropValue(this.props.props[key])}`
  },

  getPropsCode() {
    const keys = reject(Object.keys(this.props.props), x => x === 'children')
    if (keys.length === 0) {
      return ''
    }
    return '\n  ' + keys.map(this.getPropCode).join('\n  ')
  },

  getLogsCode() {
    const keys = this.props.logs
    if (keys.length === 0) {
      return ''
    }
    return '\n  ' + keys.map(key => `${key}={log${upFirst(key)}}`).join('\n  ')
  },

  getChildrenCode() {
    const {children} = this.props.props
    if (!children) {
      return '\n/>'
    }
    const str = (typeof children === 'string') ? children : '<Children ... />'
    return `\n>\n  ${str}\n</${this.props.name}>`
  },

  getCode() {
    return '<' + this.props.name + this.getPropsCode() + this.getLogsCode() + this.getChildrenCode()
  },

  render() {
    return (
      <div style={styles.controls.renderCode}>
        {this.getCode()}
      </div><commit_msg>fix propTypes<commit_after>import React from 'react'
import reject from 'lodash/collection/reject'
import stringify from '../stringify'
import styles from '../styles'


function toPropValue(x) {
  if (typeof x === 'string') {
    return stringify(x)
  }
  return `{${stringify(x)}}`
}

function upFirst(str) {
  return str.slice(0, 1).toUpperCase() + str.slice(1)
}

export default React.createClass({

  displayName: 'Demo.Controls.RenderCode',

  propTypes: {
    name: React.PropTypes.string.isRequired,
    props: React.PropTypes.object.isRequired,
    logs: React.PropTypes.arrayOf(React.PropTypes.string).isRequired
  },

  getPropCode(key) {
    return `${key}=${toPropValue(this.props.props[key])}`
  },

  getPropsCode() {
    const keys = reject(Object.keys(this.props.props), x => x === 'children')
    if (keys.length === 0) {
      return ''
    }
    return '\n  ' + keys.map(this.getPropCode).join('\n  ')
  },

  getLogsCode() {
    const keys = this.props.logs
    if (keys.length === 0) {
      return ''
    }
    return '\n  ' + keys.map(key => `${key}={log${upFirst(key)}}`).join('\n  ')
  },

  getChildrenCode() {
    const {children} = this.props.props // eslint-disable-line react/prop-types
    if (!children) {
      return '\n/>'
    }
    const str = (typeof children === 'string') ? children : '<Children ... />'
    return `\n>\n  ${str}\n</${this.props.name}>`
  },

  getCode() {
    return '<' + this.props.name + this.getPropsCode() + this.getLogsCode() + this.getChildrenCode()
  },

  render() {
    return (
      <div style={styles.controls.renderCode}>
        {this.getCode()}
      </div>
{'fraction_non_alphanumeric': 0.18587360594795538, 'fraction_numerical': 0.0030978934324659233, 'mean_word_length': 3.021170610211706, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 19, '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': '328840', 'n_tokens_mistral': 1112, 'n_tokens_neox': 1096, 'n_words': 212}