<commit_before>import classNames                from 'classnames';
import {
    observer,
    PropTypes as MobxPropTypes } from 'mobx-react';
import PropTypes                 from 'prop-types';
import React                     from 'react';
import Tooltip                   from '../Elements/tooltip.jsx';

const InputField = ({
    className,
    error_messages,
    helper,
    is_disabled,
    is_float,
    is_signed = false,
    label,
    max_length,
    name,
    onChange,
    placeholder,
    prefix,
    required,
    step = '0.01',
    type,
    value,
}) => {
    const has_error = error_messages && error_messages.length;

    const changeValue = (e) => {
        if (type === 'number') {
            const is_empty = !e.target.value || e.target.value === '';
            const signed_regex = is_signed ? '[\\+-]?' : '';

            const is_number = new RegExp(`^${signed_regex}(\\d*)?${is_float ? '(\\.\\d+)?' : ''}(?<=\\d)(?<!-0)$`)
                .test(e.target.value);

            const is_not_completed_number = is_float && new RegExp(`^${signed_regex}(\\.|\\d+\\.)?$`)
                .test(e.target.value);

            const is_zero = new RegExp(`^${signed_regex}(0)?\\.[0]*$`)
                .test(e.target.value);

            if (is_number || is_empty) {
                e.target.value = is_empty || is_signed || is_zero ? e.target.value : +e.target.value;
            } else if (!is_not_completed_number) {
                e.target.value = value;
                return;
            }
        }

        onChange(e);
    };

    const input =
        <input
            className={classNames({error: has_error})}
            disabled={is_disabled}
            data-for={`error_tooltip_${name}`}
            data-tip
            maxLength={max_length}
            name={name}
            onChange={changeValue}
            placeholder={placeholder || undefined}
            required={required || undefined}
            step={is_float ? step : undefined}
            type={type === 'number' ? 'text' : type}
            value={value}<commit_msg>Fixed the issue of entry multi zero in fraction part of a number<commit_after>import classNames                from 'classnames';
import {
    observer,
    PropTypes as MobxPropTypes } from 'mobx-react';
import PropTypes                 from 'prop-types';
import React                     from 'react';
import Tooltip                   from '../Elements/tooltip.jsx';

const InputField = ({
    className,
    error_messages,
    helper,
    is_disabled,
    is_float,
    is_signed = false,
    label,
    max_length,
    name,
    onChange,
    placeholder,
    prefix,
    required,
    step = '0.01',
    type,
    value,
}) => {
    const has_error = error_messages && error_messages.length;

    const changeValue = (e) => {
        if (type === 'number') {
            const is_empty = !e.target.value || e.target.value === '';
            const signed_regex = is_signed ? '[\\+-]?' : '';

            const is_number = new RegExp(`^${signed_regex}(\\d*)?${is_float ? '(\\.\\d+)?' : ''}(?<=\\d)(?<!-0)$`)
                .test(e.target.value);

            const is_not_completed_number = is_float && new RegExp(`^${signed_regex}(\\.|\\d+\\.)?$`)
                .test(e.target.value);

            // This regex check whether there is any zero at the end of fractional part or not.
            const has_zero_at_end = new RegExp(`^${signed_regex}(\\d+)?\\.(\\d+)?[0]+$`)
                .test(e.target.value);

            if (is_number || is_empty) {
                e.target.value = is_empty || is_signed || has_zero_at_end ? e.target.value : +e.target.value;
            } else if (!is_not_completed_number) {
                e.target.value = value;
                return;
            }
        }

        onChange(e);
    };

    const input =
        <input
            className={classNames({error: has_error})}
            disabled={is_disabled}
            data-for={`error_tooltip_${name}`}
            data-tip
            maxLength={max_length}
            name={name}
            onChange={changeValue}
            placeholder={placeholder || undefined}
            required={required || undefined}
            step={is_float ? step : undefined}
            type={type === 'number' ? 'text' : type}
            value={value}
{'fraction_non_alphanumeric': 0.14771937948599212, 'fraction_numerical': 0.002546885853206761, 'mean_word_length': 1.7639155470249521, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '7656884', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1247, 'n_words': 261}