<commit_before>/* @flow weak */
import _ from 'lodash';
import React, { Component, PropTypes } from 'react';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import cx from 'classnames';
import ContextMenu from '../ContextMenu';
import * as FileTreeActions from './actions';
import FileTreeContextMenuItems from './contextMenuItems';
import subscribeToFileChange from './subscribeToFileChange'


class FileTree extends Component {
  constructor(props) {
    super(props)
  }

  state = {
    isContextMenuActive: false,
    contextMenuPos: {x:0, y:0},
    contextNode: null
  }

  componentDidMount() {
    subscribeToFileChange()
    this.props.initializeFileTree();
  }

  render() {
    const {FileTreeState, ...actionProps} = this.props;
    const {isContextMenuActive, contextMenuPos} = this.state;
    return (
      <div className='filetree-container'>
        <FileTreeNode node={FileTreeState.rootNode}
          onContextMenu={this.onContextMenu} {...actionProps} />
        <ContextMenu items={FileTreeContextMenuItems}
          isActive={isContextMenuActive}
          pos={contextMenuPos}
          context={this.state.contextNode}
          deactivate={this.setState.bind(this, {isContextMenuActive: false})} />
      </div>
    );
  }

  onContextMenu = (e, node) => {
    e.stopPropagation()
    e.preventDefault()
    this.setState({
      isContextMenuActive: true,
      contextMenuPos: {x:e.clientX, y:e.clientY},
      contextNode: node
    })
  }
}

FileTree = connect(
  state => {
    return {FileTreeState: state.FileTreeState}
  }, dispatch => {
    return bindActionCreators(FileTreeActions, dispatch);
  }
)(FileTree);


class FileTreeNode extends Component {
  constructor(props) {
    super(props);
  }

  render() {
    const {node, ...actionProps} = this.props;
    const {openNode, selectNode, onContextMenu} = actionProps;
    return (
      <div className='filetree-node-container'
        onContextMenu={e => {selectNode(node);onContextMenu(e, node)} }>
        <div
          className={cx('filetree-node', {'focus':node.isFocused})}
          onDoubleClick={e => openNode(node)}
          onClick={e => selectNode(node)} >
          <span className='filetree-node-arrow'
            onClick={e => openNode(node, null, e.altKey)} >
            <i className={cx({
              'fa fa-angle-right': node.isFolded,
              'fa fa-angle-down': !node.isFolded,
              'hidden': !node.isDir || node.childrenCount === 0
            })}></i>
          </span>
          <span className='filetree-node-icon'>
            <i className={cx({
              'fa fa-briefcase': node.isRoot,
              'fa fa-folder-o': node.isDir && !node.isRoot,
              'fa fa-file-o': !node.isDir
            })}></i>
          </span>
          <span className='filetree-node-label'>
            {node.name || 'Project'}
          </span>
          <div className='filetree-node-bg'></div>
        </div>

        { node.isDir ?
          <div className={cx('filetree-node-children', {
            isFolded: node.isFolded
          })}>
            {node.children.map( childNode =>
              <FileTreeNode key={childNode.path} node={childNode} {...actionProps} />
            )}
          </div>
          : null }

      </div>
    );
  }
}

export default FileTree;<commit_msg>strip semicolons<commit_after>/* @flow weak */
import _ from 'lodash'
import React, { Component, PropTypes } from 'react'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import cx from 'classnames'
import ContextMenu from '../ContextMenu'
import * as FileTreeActions from './actions'
import FileTreeContextMenuItems from './contextMenuItems'
import subscribeToFileChange from './subscribeToFileChange'


class FileTree extends Component {
  constructor(props) {
    super(props)
  }

  state = {
    isContextMenuActive: false,
    contextMenuPos: {x:0, y:0},
    contextNode: null
  }

  componentDidMount() {
    subscribeToFileChange()
    this.props.initializeFileTree()
  }

  render() {
    const {FileTreeState, ...actionProps} = this.props
    const {isContextMenuActive, contextMenuPos} = this.state
    return (
      <div className='filetree-container'>
        <FileTreeNode node={FileTreeState.rootNode}
          onContextMenu={this.onContextMenu} {...actionProps} />
        <ContextMenu items={FileTreeContextMenuItems}
          isActive={isContextMenuActive}
          pos={contextMenuPos}
          context={this.state.contextNode}
          deactivate={this.setState.bind(this, {isContextMenuActive: false})} />
      </div>
    )
  }

  onContextMenu = (e, node) => {
    e.stopPropagation()
    e.preventDefault()
    this.setState({
      isContextMenuActive: true,
      contextMenuPos: {x:e.clientX, y:e.clientY},
      contextNode: node
    })
  }
}

FileTree = connect(
  state => {
    return {FileTreeState: state.FileTreeState}
  }, dispatch => {
    return bindActionCreators(FileTreeActions, dispatch)
  }
)(FileTree)


class FileTreeNode extends Component {
  constructor(props) {
    super(props)
  }

  render() {
    const {node, ...actionProps} = this.props
    const {openNode, selectNode, onContextMenu} = actionProps
    return (
      <div className='filetree-node-container'
        onContextMenu={e => {selectNode(node); onContextMenu(e, node)} }>
        <div
          className={cx('filetree-node', {'focus':node.isFocused})}
          onDoubleClick={e => openNode(node)}
          onClick={e => selectNode(node)} >
          <span className='filetree-node-arrow'
            onClick={e => openNode(node, null, e.altKey)} >
            <i className={cx({
              'fa fa-angle-right': node.isFolded,
              'fa fa-angle-down': !node.isFolded,
              'hidden': !node.isDir || node.childrenCount === 0
            })}></i>
          </span>
          <span className='filetree-node-icon'>
            <i className={cx({
              'fa fa-briefcase': node.isRoot,
              'fa fa-folder-o': node.isDir && !node.isRoot,
              'fa fa-file-o': !node.isDir
            })}></i>
          </span>
          <span className='filetree-node-label'>
            {node.name || 'Project'}
          </span>
          <div className='filetree-node-bg'></div>
        </div>

        { node.isDir ?
          <div className={cx('filetree-node-children', {
            isFolded: node.isFolded
          })}>
            {node.children.map( childNode =>
              <FileTreeNode key={childNode.path} node={childNode} {...actionProps} />
            )}
          </div>
          : null }

      </div>
    )
  }
}

export default FileTree
{'fraction_non_alphanumeric': 0.14097772462251457, 'fraction_numerical': 0.0008969950665271341, 'mean_word_length': 2.4290107637109175, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 65, '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': '4870929', 'n_tokens_mistral': 2019, 'n_tokens_neox': 1989, 'n_words': 395}