<commit_before>import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { dispatchCommand } from '../../commands'
import cx from 'classnames'
import { connect } from 'react-redux'

import * as GitActions from './actions'
import Menu from '../Menu'

// add withRef to deliver ref to the wrapperedcomponent
@connect(state => state.GitState.branches,
  dispatch => bindActionCreators(GitActions, dispatch), null, { withRef: true })
export default class GitBranchWidget extends Component {
  constructor (props) {
    super(props)
    this.state = {
      isActive: false
    }
  }

  componentWillMount () {
    this.props.getCurrentBranch()
  }

  render () {
    const { current: currentBranch, local: localBranches, remote: remoteBranches } = this.props
    return (
      <div className='status-bar-menu-item'
        onClick={e => { e.stopPropagation(); this.toggleActive(true, true) }}
      >
        <span>
          <span className='fa fa-code-fork' style={{ fontWeight: 800, marginRight: '5px' }} />
          {currentBranch}
        </span>
        {this.state.isActive ?
          <div className='git-branch-widget'>
            <div className='widget-header'>
              <h2>Git Branches</h2>
            </div>
            <Menu className={cx('bottom-up to-left', { active: this.state.isActive })}
              style={{
                position: 'relative',
                border: 0,
                borderTopRightRadius: 0,
                borderTopLeftRadius: 0,
              }}
              items={this.makeBrancheMenuItems(localBranches, remoteBranches)}
              deactivate={this.toggleActive.bind(this, false)}
            />
          </div>
        : null}
      </div>
    )
  }

  toggleActive (isActive, isTogglingEnabled) {
    if (isTogglingEnabled) { isActive = !this.state.isActive }
    if (isActive) {
      this.props.getBranches()
    }
    this.setState({ isActive })
  }

  makeBrancheMenuItems (localBranches, remoteBranches) {
    if (!localBranches && !remoteBranches) {
      return [{ name: 'Fetching Branches...', isDisabled: true }]
    }

    const localBranchItems = localBranches.map(branch => ({
      name: branch,
      items: [{
        name: 'Checkout',
        command: () => { this.props.checkoutBranch(branch) }
      }, {
        name: 'Checkout as new branch',
        command: () => dispatchCommand('git:checkout_new_branch', {
          fromBranch: branch
        })
      }, {
        name: 'Delete',
        command: () => { this.props.gitDeleteBranch(branch) }
      }]
    }))

    const remoteBranchItems = remoteBranches.map(remoteBranch => {
      const localBranch = remoteBranch.split('/').slice(1).join('/')
      return {
        name: remoteBranch,
        items: [{
          name: 'Checkout as new branch',
          // @todo: should prompt to input local branch name
          command: () => dispatchCommand('git:checkout_new_branch', {
            fromBranch: remoteBranch,
            toBranch: localBranch
          })
        }, {
          name: 'Delete',
          command: () => { this.props.gitDeleteBranch(remoteBranch) }
        }]
      }
    })
    return [
      { name: 'New Branch', command: () => dispatchCommand('git:new_branch'),
        iconElement: (<span style={{ marginRight: '0.3em' }}>+</span>) },
      { name: 'Synchronize', command: () => this.props.getFetch() },
      { name: '-', isDisabled: true },
      { name: 'Local Branches', isDisabled: true },
      ...localBranchItems,
      { name: '-', isDisabled: true },
      { name: 'Remote Branches', isDisabled: true },
      ...remoteBranchItems
    ]
  }
}<commit_msg>:bug: fix GitBranchWidget menu item's config<commit_after>import React, { Component } from 'react'
import { bindActionCreators } from 'redux'
import { dispatchCommand } from '../../commands'
import cx from 'classnames'
import { connect } from 'react-redux'

import * as GitActions from './actions'
import Menu from '../Menu'

// add withRef to deliver ref to the wrapperedcomponent
@connect(state => state.GitState.branches,
  dispatch => bindActionCreators(GitActions, dispatch), null, { withRef: true })
export default class GitBranchWidget extends Component {
  constructor (props) {
    super(props)
    this.state = {
      isActive: false
    }
  }

  componentWillMount () {
    this.props.getCurrentBranch()
  }

  render () {
    const { current: currentBranch, local: localBranches, remote: remoteBranches } = this.props
    return (
      <div className='status-bar-menu-item'
        onClick={e => { e.stopPropagation(); this.toggleActive(true, true) }}
      >
        <span>
          <span className='fa fa-code-fork' style={{ fontWeight: 800, marginRight: '5px' }} />
          {currentBranch}
        </span>
        {this.state.isActive ?
          <div className='git-branch-widget'>
            <div className='widget-header'>
              <h2>Git Branches</h2>
            </div>
            <Menu className={cx('bottom-up to-left', { active: this.state.isActive })}
              style={{
                position: 'relative',
                border: 0,
                borderTopRightRadius: 0,
                borderTopLeftRadius: 0,
              }}
              items={this.makeBrancheMenuItems(localBranches, remoteBranches)}
              deactivate={this.toggleActive.bind(this, false)}
            />
          </div>
        : null}
      </div>
    )
  }

  toggleActive (isActive, isTogglingEnabled) {
    if (isTogglingEnabled) { isActive = !this.state.isActive }
    if (isActive) {
      this.props.getBranches()
    }
    this.setState({ isActive })
  }

  makeBrancheMenuItems (localBranches, remoteBranches) {
    if (!localBranches && !remoteBranches) {
      return [{ name: 'Fetching Branches...', isDisabled: true }]
    }

    const localBranchItems = localBranches.map(branch => ({
      name: branch,
      items: [{
        name: 'Checkout',
        command: () => { this.props.checkoutBranch(branch) }
      }, {
        name: 'Checkout as new branch',
        command: () => dispatchCommand('git:checkout_new_branch', {
          fromBranch: branch
        })
      }, {
        name: 'Delete',
        command: () => { this.props.gitDeleteBranch(branch) }
      }]
    }))

    const remoteBranchItems = remoteBranches.map(remoteBranch => {
      const localBranch = remoteBranch.split('/').slice(1).join('/')
      return {
        name: remoteBranch,
        items: [{
          name: 'Checkout as new branch',
          // @todo: should prompt to input local branch name
          command: () => dispatchCommand('git:checkout_new_branch', {
            fromBranch: remoteBranch,
            toBranch: localBranch
          })
        }, {
          name: 'Delete',
          command: () => { this.props.gitDeleteBranch(remoteBranch) }
        }]
      }
    })
    return [
      { name: 'New Branch', command: () => dispatchCommand('git:new_branch'),
        iconElement: (<span style={{ marginRight: '0.3em' }}>+</span>) },
      { name: 'Synchronize', command: () => this.props.getFetch() },
      { name: '-', isDivider: true },
      { name: 'Local Branches', isDisabled: true },
      ...localBranchItems,
      { name: '-', isDivider: true },
      { name: 'Remote Branches', isDisabled: true },
      ...remoteBranchItems
    ]
  }
}
{'fraction_non_alphanumeric': 0.1406058959380519, 'fraction_numerical': 0.0032604265724765656, 'mean_word_length': 2.2749110320284696, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 55, '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': '5884969', 'n_tokens_mistral': 2137, 'n_tokens_neox': 2147, 'n_words': 465}