<commit_before>import React, { Component, PropTypes } from 'react'
import { isEqual } from 'lodash'
import {
  Icon,
  LoaderText,
  TableCell,
  TableRow,
  Row
} from 'zanata-ui'
import EntryModal from './EntryModal'
import DeleteEntryModal from './DeleteEntryModal'
import { EditableText } from '../../components'
import { Button } from 'react-bootstrap'
/**
 * Component to display a GlossaryEntry
 */
class Entry extends Component {
  constructor () {
    super()
    this.state = {
      showEntryModal: false,
      showDeleteModal: false
    }
  }

  setShowingEntryModal (showing) {
    this.setState({
      showEntryModal: showing
    })
  }

  setShowingDeleteEntryModal (showing) {
    this.setState({
      showDeleteModal: showing
    })
  }

  shouldComponentUpdate (nextProps, nextState) {
    return !isEqual(this.props, nextProps) || !isEqual(this.state, nextState)
  }

  render () {
    const {
      entry,
      handleSelectTerm,
      handleTermFieldUpdate,
      handleDeleteTerm,
      handleResetTerm,
      handleUpdateTerm,
      isSaving,
      isDeleting,
      permission,
      selectedTransLocale,
      selected,
      termsLoading
    } = this.props

    const transContent = entry && entry.transTerm
      ? entry.transTerm.content : ''
    const transSelected = !!selectedTransLocale

    if (!entry) {
      return (
        <TableRow>
          <TableCell>
            <div className='LineClamp(1,24px) Px(rq)'>Loading…</div>
          </TableCell>
        </TableRow>
      )
    }

    const isTermModified = transSelected
      ? (entry.status && entry.status.isTransModified)
      : (entry.status && entry.status.isSrcModified)
    const displayUpdateButton = permission.canUpdateEntry &&
      ((isTermModified && selected) || isSaving)
    const editable = permission.canUpdateEntry && !isSaving

    /* eslint-disable react/jsx-no-bind */
    const updateButton = displayUpdateButton && (
      <Button bsStyle='primary'
        type='primary'
        disabled={isSaving}
        onClick={() => handleUpdateTerm(entry, transSelected)}>
        <LoaderText loading={isSaving} loadingText='Updating'>
          Update
        </LoaderText>
      </Button>
    )

    const loadingDiv = (
      <div className='LineClamp(1,24px) Px(rq)'>Loading…</div>
    )

    let secondColumnContent
    if (termsLoading) {
      secondColumnContent = loadingDiv
    } else if (transSelected) {
      secondColumnContent =
        <EditableText
          title={transContent}
          editable={transSelected && editable}
          editing={selected}
          onChange={(e) => handleTermFieldUpdate('locale', e)}
          placeholder='Add a translation…'
          emptyReadOnlyText='No translation'>
          {transContent}
        </EditableText>
    } else {
      secondColumnContent =
        <div className='LineClamp(1,24px) Px(rq)'>
          {entry.termsCount}
        </div>
    }

    return (
      <div className='H(100%)--sm'>
        <TableRow highlight
          className='editable'
          selected={selected}
          onClick={() => handleSelectTerm(entry.id)}>
          <TableCell size='3' tight>
            {termsLoading
              ? loadingDiv
              : (<EditableText
                title={entry.srcTerm.content}
                editable={false}
                editing={selected}>
                {entry.srcTerm.content}
              </EditableText>)
            }
          </TableCell>
          <TableCell size='3' tight={transSelected}>
            {secondColumnContent}
          </TableCell>
          <TableCell hideSmall>
          {termsLoading
            ? loadingDiv
            : (<EditableText
              className='textStateClasses'
              title={entry.pos}
              editable={!transSelected && editable}
              editing={selected}
              onChange={(e) => handleTermFieldUpdate('pos', e)}
              placeholder='Add part of speech…'
              emptyReadOnlyText='No part of speech'>
              {entry.pos}
            </EditableText>)
          }
          </TableCell>
          <TableCell size='2'>
            {termsLoading
              ? loadingDiv
              : (<Row>
                <Button bsStyle='link' atomic={{m: 'Mend(rq)'}}
                  disabled={isDeleting}
                  onClick={() => this.setShowingEntryModal(true)}>
                  <Icon name='info' />
                </Button>
                <EntryModal entry={entry}
                  show={this.state.showEntryModal}
                  isSaving={isSaving}<commit_msg>fix: removed code that was making the 'Add part of speech' box display outside of Glossary table<commit_after>import React, { Component, PropTypes } from 'react'
import { isEqual } from 'lodash'
import {
  Icon,
  LoaderText,
  TableCell,
  TableRow,
  Row
} from 'zanata-ui'
import EntryModal from './EntryModal'
import DeleteEntryModal from './DeleteEntryModal'
import { EditableText } from '../../components'
import { Button } from 'react-bootstrap'
/**
 * Component to display a GlossaryEntry
 */
class Entry extends Component {
  constructor () {
    super()
    this.state = {
      showEntryModal: false,
      showDeleteModal: false
    }
  }

  setShowingEntryModal (showing) {
    this.setState({
      showEntryModal: showing
    })
  }

  setShowingDeleteEntryModal (showing) {
    this.setState({
      showDeleteModal: showing
    })
  }

  shouldComponentUpdate (nextProps, nextState) {
    return !isEqual(this.props, nextProps) || !isEqual(this.state, nextState)
  }

  render () {
    const {
      entry,
      handleSelectTerm,
      handleTermFieldUpdate,
      handleDeleteTerm,
      handleResetTerm,
      handleUpdateTerm,
      isSaving,
      isDeleting,
      permission,
      selectedTransLocale,
      selected,
      termsLoading
    } = this.props

    const transContent = entry && entry.transTerm
      ? entry.transTerm.content : ''
    const transSelected = !!selectedTransLocale

    if (!entry) {
      return (
        <TableRow>
          <TableCell>
            <div className='LineClamp(1,24px) Px(rq)'>Loading…</div>
          </TableCell>
        </TableRow>
      )
    }

    const isTermModified = transSelected
      ? (entry.status && entry.status.isTransModified)
      : (entry.status && entry.status.isSrcModified)
    const displayUpdateButton = permission.canUpdateEntry &&
      ((isTermModified && selected) || isSaving)
    const editable = permission.canUpdateEntry && !isSaving

    /* eslint-disable react/jsx-no-bind */
    const updateButton = displayUpdateButton && (
      <Button bsStyle='primary'
        type='primary'
        disabled={isSaving}
        onClick={() => handleUpdateTerm(entry, transSelected)}>
        <LoaderText loading={isSaving} loadingText='Updating'>
          Update
        </LoaderText>
      </Button>
    )

    const loadingDiv = (
      <div className='LineClamp(1,24px) Px(rq)'>Loading…</div>
    )

    let secondColumnContent
    if (termsLoading) {
      secondColumnContent = loadingDiv
    } else if (transSelected) {
      secondColumnContent =
        <EditableText
          title={transContent}
          editable={transSelected && editable}
          editing={selected}
          onChange={(e) => handleTermFieldUpdate('locale', e)}
          placeholder='Add a translation…'
          emptyReadOnlyText='No translation'>
          {transContent}
        </EditableText>
    } else {
      secondColumnContent =
        <div className='LineClamp(1,24px) Px(rq)'>
          {entry.termsCount}
        </div>
    }

    return (
      <div className='H(100%)--sm'>
        <TableRow highlight
          className='editable'
          selected={selected}
          onClick={() => handleSelectTerm(entry.id)}>
          <TableCell size='3' tight>
            {termsLoading
              ? loadingDiv
              : (<EditableText
                title={entry.srcTerm.content}
                editable={false}
                editing={selected}>
                {entry.srcTerm.content}
              </EditableText>)
            }
          </TableCell>
          <TableCell size='3' tight={transSelected}>
            {secondColumnContent}
          </TableCell>
          <TableCell hideSmall>
          {termsLoading
            ? loadingDiv
            : (<EditableText
              className='textStateClasses'
              title={entry.pos}
              editable={!transSelected && editable}
              editing={selected}
              onChange={(e) => handleTermFieldUpdate('pos', e)}
              placeholder='Add part of speech'
              emptyReadOnlyText='No part of speech'>
              {entry.pos}
            </EditableText>)
          }
          </TableCell>
          <TableCell size='2'>
            {termsLoading
              ? loadingDiv
              : (<Row>
                <Button bsStyle='link' atomic={{m: 'Mend(rq)'}}
                  disabled={isDeleting}
                  onClick={() => this.setShowingEntryModal(true)}>
                  <Icon name='info' />
                </Button>
                <EntryModal entry={entry}
                  show={this.state.showEntryModal}
                  isSaving={isSaving}
{'fraction_non_alphanumeric': 0.11243243243243244, 'fraction_numerical': 0.003243243243243243, 'mean_word_length': 2.0084552845528454, 'pattern_counts': {'":': 0, '<': 71, '<?xml version=': 0, '>': 79, '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': '375947', 'n_tokens_mistral': 2551, 'n_tokens_neox': 2503, 'n_words': 499}