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

import SlideToggle from 'shared/components/SlideToggle'
import ConfirmButtons from 'shared/components/ConfirmButtons'
import Dropdown from 'shared/components/Dropdown'

import {meChangeOrganizationAsync} from 'shared/actions/auth'

import {DEFAULT_ORG_ID} from 'src/admin/constants/chronografAdmin'
import {USER_ROLES} from 'src/admin/constants/chronografAdmin'

const OrganizationsTableRowDeleteButton = ({organization, onClickDelete}) =>
  organization.id === DEFAULT_ORG_ID
    ? <button
        className="btn btn-sm btn-default btn-square orgs-table--delete"
        disabled={true}
      >
        <span className="icon trash" />
      </button>
    : <button
        className="btn btn-sm btn-default btn-square"
        onClick={onClickDelete}
      >
        <span className="icon trash" />
      </button>

class OrganizationsTableRow extends Component {
  constructor(props) {
    super(props)

    this.state = {
      isEditing: false,
      isDeleting: false,
      workingName: this.props.organization.name,
    }
  }

  handleChangeCurrentOrganization = () => async () => {
    const {router, links, meChangeOrganization, organization} = this.props

    await meChangeOrganization(links.me, {organization: organization.id})
    router.push('')
  }

  handleNameClick = () => {
    this.setState({isEditing: true})
  }

  handleConfirmRename = () => {
    const {onRename, organization} = this.props
    const {workingName} = this.state

    onRename(organization, workingName)
    this.setState({workingName, isEditing: false})
  }

  handleCancelRename = () => {
    const {organization} = this.props

    this.setState({
      workingName: organization.name,
      isEditing: false,
    })
  }

  handleInputChange = e => {
    this.setState({workingName: e.target.value})
  }

  handleInputBlur = () => {
    const {organization} = this.props
    const {workingName} = this.state

    if (organization.name === workingName) {
      this.handleCancelRename()
    } else {
      this.handleConfirmRename()
    }
  }

  handleKeyDown = e => {
    if (e.key === 'Enter') {
      this.handleInputBlur()
    } else if (e.key === 'Escape') {
      this.handleCancelRename()
    }
  }

  handleFocus = e => {
    e.target.select()
  }

  handleDeleteClick = () => {
    this.setState({isDeleting: true})
  }

  handleDismissDeleteConfirmation = () => {
    this.setState({isDeleting: false})
  }

  handleDeleteOrg = organization => {
    const {onDelete} = this.props
    onDelete(organization)
  }

  handleTogglePublic = () => {
    const {organization, onTogglePublic} = this.props
    onTogglePublic(organization)
  }

  handleChooseDefaultRole = role => {
    const {organization, onChooseDefaultRole} = this.props
    onChooseDefaultRole(organization, role.name)
  }

  render() {
    const {workingName, isEditing, isDeleting} = this.state
    const {organization, currentOrganization} = this.props

    const dropdownRolesItems = USER_ROLES.map(role => ({
      ...role,
      text: role.name,
    }))

    const defaultRoleClassName = isDeleting
      ? 'orgs-table--default-role editing'
      : 'orgs-table--default-role'

    return (
      <div className="orgs-table--org">
        <div className="orgs-table--active">
          {organization.id === currentOrganization.id
            ? <button className="btn btn-sm btn-success">
                <span className="icon checkmark" /> Current
              </button>
            : <button
                className="btn btn-sm btn-default"
                onClick={this.handleChangeCurrentOrganization()}
              >
                <span className="icon shuffle" /> Switch to
              </button>}
        </div>
        {isEditing
          ? <input
              type="text"
              className="form-control input-sm orgs-table--input"
              defaultValue={workingName}
              onChange={this.handleInputChange}
              onBlur={this.handleInputBlur}
              onKeyDown={this.handleKeyDown}
              placeholder="Name this Organization..."
              autoFocus={true}
              onFocus={this.handleFocus}
              ref={r => (this.inputRef = r)}
            />
          : <div className="orgs-table--name" onClick={this.handleNameClick}>
              {workingName}
              <span className="icon pencil" />
            </div>}
        {organization.id === DEFAULT_ORG_ID
          ? <div className="orgs-table--public">
              <SlideToggle
                size="xs"
                active={organization.public}
                onToggle={this.handleTogglePublic}
              /><commit_msg>Remove function call and closure<commit_after>import React, {Component, PropTypes} from 'react'
import {connect} from 'react-redux'
import {bindActionCreators} from 'redux'
import {withRouter} from 'react-router'

import SlideToggle from 'shared/components/SlideToggle'
import ConfirmButtons from 'shared/components/ConfirmButtons'
import Dropdown from 'shared/components/Dropdown'

import {meChangeOrganizationAsync} from 'shared/actions/auth'

import {DEFAULT_ORG_ID} from 'src/admin/constants/chronografAdmin'
import {USER_ROLES} from 'src/admin/constants/chronografAdmin'

const OrganizationsTableRowDeleteButton = ({organization, onClickDelete}) =>
  organization.id === DEFAULT_ORG_ID
    ? <button
        className="btn btn-sm btn-default btn-square orgs-table--delete"
        disabled={true}
      >
        <span className="icon trash" />
      </button>
    : <button
        className="btn btn-sm btn-default btn-square"
        onClick={onClickDelete}
      >
        <span className="icon trash" />
      </button>

class OrganizationsTableRow extends Component {
  constructor(props) {
    super(props)

    this.state = {
      isEditing: false,
      isDeleting: false,
      workingName: this.props.organization.name,
    }
  }

  handleChangeCurrentOrganization = async () => {
    const {router, links, meChangeOrganization, organization} = this.props

    await meChangeOrganization(links.me, {organization: organization.id})
    router.push('')
  }

  handleNameClick = () => {
    this.setState({isEditing: true})
  }

  handleConfirmRename = () => {
    const {onRename, organization} = this.props
    const {workingName} = this.state

    onRename(organization, workingName)
    this.setState({workingName, isEditing: false})
  }

  handleCancelRename = () => {
    const {organization} = this.props

    this.setState({
      workingName: organization.name,
      isEditing: false,
    })
  }

  handleInputChange = e => {
    this.setState({workingName: e.target.value})
  }

  handleInputBlur = () => {
    const {organization} = this.props
    const {workingName} = this.state

    if (organization.name === workingName) {
      this.handleCancelRename()
    } else {
      this.handleConfirmRename()
    }
  }

  handleKeyDown = e => {
    if (e.key === 'Enter') {
      this.handleInputBlur()
    } else if (e.key === 'Escape') {
      this.handleCancelRename()
    }
  }

  handleFocus = e => {
    e.target.select()
  }

  handleDeleteClick = () => {
    this.setState({isDeleting: true})
  }

  handleDismissDeleteConfirmation = () => {
    this.setState({isDeleting: false})
  }

  handleDeleteOrg = organization => {
    const {onDelete} = this.props
    onDelete(organization)
  }

  handleTogglePublic = () => {
    const {organization, onTogglePublic} = this.props
    onTogglePublic(organization)
  }

  handleChooseDefaultRole = role => {
    const {organization, onChooseDefaultRole} = this.props
    onChooseDefaultRole(organization, role.name)
  }

  render() {
    const {workingName, isEditing, isDeleting} = this.state
    const {organization, currentOrganization} = this.props

    const dropdownRolesItems = USER_ROLES.map(role => ({
      ...role,
      text: role.name,
    }))

    const defaultRoleClassName = isDeleting
      ? 'orgs-table--default-role editing'
      : 'orgs-table--default-role'

    return (
      <div className="orgs-table--org">
        <div className="orgs-table--active">
          {organization.id === currentOrganization.id
            ? <button className="btn btn-sm btn-success">
                <span className="icon checkmark" /> Current
              </button>
            : <button
                className="btn btn-sm btn-default"
                onClick={this.handleChangeCurrentOrganization}
              >
                <span className="icon shuffle" /> Switch to
              </button>}
        </div>
        {isEditing
          ? <input
              type="text"
              className="form-control input-sm orgs-table--input"
              defaultValue={workingName}
              onChange={this.handleInputChange}
              onBlur={this.handleInputBlur}
              onKeyDown={this.handleKeyDown}
              placeholder="Name this Organization..."
              autoFocus={true}
              onFocus={this.handleFocus}
              ref={r => (this.inputRef = r)}
            />
          : <div className="orgs-table--name" onClick={this.handleNameClick}>
              {workingName}
              <span className="icon pencil" />
            </div>}
        {organization.id === DEFAULT_ORG_ID
          ? <div className="orgs-table--public">
              <SlideToggle
                size="xs"
                active={organization.public}
                onToggle={this.handleTogglePublic}
              />
{'fraction_non_alphanumeric': 0.12200435729847495, 'fraction_numerical': 0.0, 'mean_word_length': 2.483917600289122, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 78, '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': '4821688', 'n_tokens_mistral': 2813, 'n_tokens_neox': 2741, 'n_words': 526}