<commit_before>// @flow
import * as React from 'react'
const { Component, Fragment } = React
import { connect } from 'react-redux'
import { compose } from 'recompose'

import { withStyles } from '@material-ui/core/styles'
import ButtonBase from '@material-ui/core/ButtonBase'
import Menu from '@material-ui/core/Menu'
import MenuItem from '@material-ui/core/MenuItem'

import { updateCharacter, updateQc } from 'ducks/actions.js'
import { canIEditCharacter, canIEditQc } from 'selectors'
import { prettyAnimaLevel } from 'utils/calculated'
import type { withMotePool } from 'utils/flow-types'

const styles = theme => ({
  wrap: {
    marginRight: theme.spacing.unit,
    minWidth: '8em',
    textAlign: 'left',
  },
  animaLabel: {
    ...theme.typography.body1,
    fontSize: '0.75rem',
    fontWeight: 500,
    opacity: 0.7,
    textAlign: 'left',
    paddingLeft: '0.25rem',
  },
  valueWrap: {
    textAlign: 'left',
  },
  animaCurrent: {
    ...theme.typography.display1,
    display: 'inline-block',
    fontSize: '1.75rem',
    verticalAlign: 'top',
  },
  animaValue: {
    ...theme.typography.caption,
    display: 'inline-block',
    verticalAlign: 'top',
    marginTop: '0.25em',
  },
})

type Props = {
  character: withMotePool & { id: number },
  qc: boolean,
  canEdit: boolean,
  update: Function,
  classes: Object,
}
type State = {
  anchor: any,
}
class AnimaDisplay extends Component<Props, State> {
  constructor(props) {
    super(props)
    this.state = {
      anchor: null,
    }
  }

  handleOpen = e => {
    if (this.props.canEdit) this.setState({ anchor: e.currentTarget })
  }

  handleClose = () => {
    this.setState({ anchor: null })
  }

  handleChange = anima => {
    this.props.update(this.props.character.id, anima)
    this.setState({ anchor: null })
  }

  render() {
    const { anchor } = this.state
    const { handleOpen, handleClose, handleChange } = this
    const { character, qc, classes, canEdit } = this.props

    if (qc && character.motes_personal_total === 0) return null

    return (
      <Fragment>
        <ButtonBase onClick={handleOpen} disabled={!canEdit}>
          <div className={classes.wrap}><commit_msg>Hide anima display for mortal characters<commit_after>// @flow
import * as React from 'react'
const { Component, Fragment } = React
import { connect } from 'react-redux'
import { compose } from 'recompose'

import { withStyles } from '@material-ui/core/styles'
import ButtonBase from '@material-ui/core/ButtonBase'
import Menu from '@material-ui/core/Menu'
import MenuItem from '@material-ui/core/MenuItem'

import { updateCharacter, updateQc } from 'ducks/actions.js'
import { canIEditCharacter, canIEditQc } from 'selectors'
import { prettyAnimaLevel } from 'utils/calculated'
import type { withMotePool } from 'utils/flow-types'

const styles = theme => ({
  wrap: {
    marginRight: theme.spacing.unit,
    minWidth: '8em',
    textAlign: 'left',
  },
  animaLabel: {
    ...theme.typography.body1,
    fontSize: '0.75rem',
    fontWeight: 500,
    opacity: 0.7,
    textAlign: 'left',
    paddingLeft: '0.25rem',
  },
  valueWrap: {
    textAlign: 'left',
  },
  animaCurrent: {
    ...theme.typography.display1,
    display: 'inline-block',
    fontSize: '1.75rem',
    verticalAlign: 'top',
  },
  animaValue: {
    ...theme.typography.caption,
    display: 'inline-block',
    verticalAlign: 'top',
    marginTop: '0.25em',
  },
})

type Props = {
  character: withMotePool & { id: number },
  qc: boolean,
  canEdit: boolean,
  update: Function,
  classes: Object,
}
type State = {
  anchor: any,
}
class AnimaDisplay extends Component<Props, State> {
  constructor(props) {
    super(props)
    this.state = {
      anchor: null,
    }
  }

  handleOpen = e => {
    if (this.props.canEdit) this.setState({ anchor: e.currentTarget })
  }

  handleClose = () => {
    this.setState({ anchor: null })
  }

  handleChange = anima => {
    this.props.update(this.props.character.id, anima)
    this.setState({ anchor: null })
  }

  render() {
    const { anchor } = this.state
    const { handleOpen, handleClose, handleChange } = this
    const { character, qc, classes, canEdit } = this.props

    if (
      (qc && character.motes_personal_total === 0) ||
      character.type === 'Character'
    )
      return null

    return (
      <Fragment>
        <ButtonBase onClick={handleOpen} disabled={!canEdit}>
          <div className={classes.wrap}>
{'fraction_non_alphanumeric': 0.14211594856756146, 'fraction_numerical': 0.009474396571170765, 'mean_word_length': 3.171213546566322, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '2887184', 'n_tokens_mistral': 1490, 'n_tokens_neox': 1454, 'n_words': 344}