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

import OnClickOutside from 'react-onclickoutside'

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

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

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

  handleInputBlur = reset => e => {
    const {onRename, organization} = this.props

    if (!reset && organization.name !== e.target.value) {
      onRename(organization, e.target.value)
    }

    this.setState({reset: false, isEditing: false})
  }

  handleKeyDown = e => {
    if (e.key === 'Enter') {
      this.inputRef.blur()
    }
    if (e.key === 'Escape') {
      this.setState(
        {reset: true, workingName: this.props.organization.name},
        () => this.inputRef.blur()
      )
    }
  }

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

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

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

  handleDeleteOrg = () => {
    const {onDelete, organization} = this.props
    this.setState({isDeleting: false})
    onDelete(organization)
  }

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

    return (
      <div className="manage-orgs-form--org">
        <div className="manage-orgs-form--id">
          {organization.id}
        </div>
        {isEditing
          ? <input
              type="text"
              className="form-control input-sm manage-orgs-form--input"
              defaultValue={workingName}
              onBlur={this.handleInputBlur(reset)}
              onKeyDown={this.handleKeyDown}
              placeholder="Name this Organization..."
              autoFocus={true}
              onFocus={this.handleFocus}
              ref={r => (this.inputRef = r)}
            />
          : <div
              className="manage-orgs-form--name"
              onClick={this.handleNameClick}
            >
              {workingName}
              <span className="icon pencil" />
            </div>}
        {isDeleting
          ? <div className="btn btn-sm btn-default btn-square manage-orgs-form--delete active">
              <span className="icon trash" />
              <ConfirmDeleteOrg
                onDelete={this.handleDeleteOrg}
                handleClickOutside={this.handleDismissDeleteConfirmation}
              />
            </div>
          : <button
              className="btn btn-sm btn-default btn-square manage-orgs-form--delete"
              onClick={this.handleDeleteClick}
            ><commit_msg>Disable trash icon if default org to prevent delete<commit_after>import React, {Component, PropTypes} from 'react'

import OnClickOutside from 'react-onclickoutside'

import {DEFAULT_ORG_ID} from 'src/admin/constants/dummyUsers'

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

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

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

  handleInputBlur = reset => e => {
    const {onRename, organization} = this.props

    if (!reset && organization.name !== e.target.value) {
      onRename(organization, e.target.value)
    }

    this.setState({reset: false, isEditing: false})
  }

  handleKeyDown = e => {
    if (e.key === 'Enter') {
      this.inputRef.blur()
    }
    if (e.key === 'Escape') {
      this.setState(
        {reset: true, workingName: this.props.organization.name},
        () => this.inputRef.blur()
      )
    }
  }

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

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

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

  handleDeleteOrg = () => {
    const {onDelete, organization} = this.props
    this.setState({isDeleting: false})
    onDelete(organization)
  }

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

    const isDefaultOrg = organization.id === DEFAULT_ORG_ID

    return (
      <div className="manage-orgs-form--org">
        <div className="manage-orgs-form--id">
          {organization.id}
        </div>
        {isEditing
          ? <input
              type="text"
              className="form-control input-sm manage-orgs-form--input"
              defaultValue={workingName}
              onBlur={this.handleInputBlur(reset)}
              onKeyDown={this.handleKeyDown}
              placeholder="Name this Organization..."
              autoFocus={true}
              onFocus={this.handleFocus}
              ref={r => (this.inputRef = r)}
            />
          : <div
              className="manage-orgs-form--name"
              onClick={this.handleNameClick}
            >
              {workingName}
              <span className="icon pencil" />
            </div>}
        {isDeleting
          ? <div className="btn btn-sm btn-default btn-square manage-orgs-form--delete active">
              <span className="icon trash" />
              <ConfirmDeleteOrg
                onDelete={this.handleDeleteOrg}
                handleClickOutside={this.handleDismissDeleteConfirmation}
              />
            </div>
          : <button
              className="btn btn-sm btn-default btn-square manage-orgs-form--delete"
              onClick={this.handleDeleteClick}
              disabled={isDefaultOrg}
            >
{'fraction_non_alphanumeric': 0.12749213011542498, 'fraction_numerical': 0.0, 'mean_word_length': 2.0355626326963905, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 47, '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': '5825381', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1647, 'n_words': 299}