<commit_before>/**
 * Editable form element component - currency
 */

import { Map as map } from 'immutable';
import React from 'react';
import PropTypes from 'prop-types';
import Editable from './Editable';
import { aEditableActivated, aEditableChanged } from '../../actions/EditActions';
import { formatCurrency } from '../../misc/format';

export class EditableCost extends Editable {
  editChange(value) {
    this.dispatchAction(aEditableChanged(Math.round(parseFloat(value, 10) * 100)));
  }
  activate() {
    this.dispatchAction(aEditableActivated(map({
      row: this.props.row,
      col: this.props.col,
      page: this.props.page,
      item: this.props.item,
      value: this.props.value
    })));
  }
  format() {
    // format the current value
    return formatCurrency(this.props.value);
  }
  render() {
    if (this.props.active) {
      return (
        <input className='editable-input' type='number' step='0.01'
          defaultValue={this.props.value / 100}
          ref={input => {
            this.input = input;
          }}
          onChange={evt => this.editChange(evt.target.value)} />
      );
    }
    return (<commit_msg>Focus edit inputs after activating them<commit_after>/**
 * Editable form element component - currency
 */

import { Map as map } from 'immutable';
import React from 'react';
import PropTypes from 'prop-types';
import Editable from './Editable';
import { aEditableActivated, aEditableChanged } from '../../actions/EditActions';
import { formatCurrency } from '../../misc/format';

export class EditableCost extends Editable {
  editChange(value) {
    this.dispatchAction(aEditableChanged(Math.round(parseFloat(value, 10) * 100)));
  }
  activate() {
    this.dispatchAction(aEditableActivated(map({
      row: this.props.row,
      col: this.props.col,
      page: this.props.page,
      item: this.props.item,
      value: this.props.value
    })));
  }
  format() {
    // format the current value
    return formatCurrency(this.props.value);
  }
  componentDidUpdate(prevProps) {
    if (!prevProps.active && this.props.active) {
      window.setTimeout(() => {
        this.input.focus();
      }, 0);
    }
  }
  render() {
    if (this.props.active) {
      return (
        <input className='editable-input' type='number' step='0.01'
          defaultValue={this.props.value / 100}
          ref={input => {
            this.input = input;
          }}
          onChange={evt => this.editChange(evt.target.value)} />
      );
    }
    return (
{'fraction_non_alphanumeric': 0.14484679665738162, 'fraction_numerical': 0.00915240748109829, 'mean_word_length': 2.7134416543574593, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 10, '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': '5004533', 'n_tokens_mistral': 766, 'n_tokens_neox': 760, 'n_words': 166}