<commit_before>import './input.scss';
import React, { Component } from 'react';
import { string, func } from 'prop-types';
import {
    InputAddress,
    InputButton,
    InputCheckbox,
    InputNumbers,
    InputDate,
    InputDatePicker,
    InputDropdown,
    InputEmail,
    InputSlider,
    InputText,
    InputTextarea,
    InputTime,
    InputUpload,
    InputUploadPhoto,

} from 'views/components';

class Input extends Component {

    static defaultProps = {
        className: '',
        type: '',
        value: '',
    }

    static propTypes = {
        className: string,
        type: string,
        value: string,
        onValidation: func,
        onValidationFailure: func,
    }

    state = {
        validationStatus: null,
        value: this.props.value || '',
    }

    componentDidMount() {
        this._ismounted = true;
    }

    shouldComponentUpdate() {
        return true;
    }

    isValid = () => {

        const { validationList } = this.props;
        const { value } = this.state;

        let isValid = false;
        if (validationList.length > 0) {
            isValid = validationList.every( validation => new RegExp(validation.regex).test( value ));
        }
        else {
            isValid = new RegExp(/.*/).test( value );
        }

        if(isValid) {
            this.validationStyle('success');
        }
        else {
            this.validationStyle('error');
        }

        return isValid;
    }

    componentWillReceiveProps(newProps) {

        if(this._ismounted) {

            this.setState({
                value: newProps.value
            })
        }
    }

    handleOnChange = (newValue) => {
        this.setState({
            value: newValue
        });
    }

    validateInput = (value, identifier, validationList) => {

        if(value == this.props.value) return;

        if ( validationList.length > 0) {

            const valResult = validationList.every( validation => new RegExp(validation.regex).test( value ));
            this.validateValue(valResult, value);

        }
        else {

            const valResult = new RegExp(/.*/).test( value );
            this.validateValue(valResult, value);

        }
    }

    validateValue = ( valResult, value ) => {

        if ( valResult ){

            this.validationStyle('success');
            if(this.props.onValidation) this.props.onValidation(value, this.props.data, this.props.mandatory);
        }
        else {

            this.validationStyle('error');
            if(this.props.onValidationFailure) this.props.onValidationFailure(this.props.data, this.props.mandatory);
        }
    }

    validationStyle = (resultString) => {

        if(this._ismounted) {
            this.setState({
                validationStatus: resultString,
            });
        }
    }

    renderInput() {

        const { onClick, onClickEvent, ...rest } = this.props;
        const { validationStatus } = this.state;

        let items = this.props.options;

        switch(this.props.type) {

            // socials
            case 'Facebook':
            return (
                <InputButton
                    {...rest}
                    onClick={this.props.onClickEvent}
                    className="facebook"
                    name=""
                    type="facebook"
                />
            );
            case 'java.time.LocalDate':
            return (
                <InputDatePicker
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}
                />
            );
            case 'TextArea':
            return (
                <InputTextarea
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}
                />
            );
            case 'Boolean':
            return (
                <InputCheckbox
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}<commit_msg>input date time<commit_after>import './input.scss';
import React, { Component } from 'react';
import { string, func } from 'prop-types';
import {
    InputAddress,
    InputButton,
    InputCheckbox,
    InputNumbers,
    InputDate,
    InputDatePicker,
    InputDropdown,
    InputEmail,
    InputSlider,
    InputText,
    InputTextarea,
    InputTime,
    InputUpload,
    InputUploadPhoto,

} from 'views/components';

class Input extends Component {

    static defaultProps = {
        className: '',
        type: '',
        value: '',
    }

    static propTypes = {
        className: string,
        type: string,
        value: string,
        onValidation: func,
        onValidationFailure: func,
    }

    state = {
        validationStatus: null,
        value: this.props.value || '',
    }

    componentDidMount() {
        this._ismounted = true;
    }

    shouldComponentUpdate() {
        return true;
    }

    isValid = () => {

        const { validationList } = this.props;
        const { value } = this.state;

        let isValid = false;
        if (validationList.length > 0) {
            isValid = validationList.every( validation => new RegExp(validation.regex).test( value ));
        }
        else {
            isValid = new RegExp(/.*/).test( value );
        }

        if(isValid) {
            this.validationStyle('success');
        }
        else {
            this.validationStyle('error');
        }

        return isValid;
    }

    componentWillReceiveProps(newProps) {

        if(this._ismounted) {

            this.setState({
                value: newProps.value
            })
        }
    }

    handleOnChange = (newValue) => {
        this.setState({
            value: newValue
        });
    }

    validateInput = (value, identifier, validationList) => {

        if(value == this.props.value) return;

        if ( validationList.length > 0) {

            const valResult = validationList.every( validation => new RegExp(validation.regex).test( value ));
            this.validateValue(valResult, value);

        }
        else {

            const valResult = new RegExp(/.*/).test( value );
            this.validateValue(valResult, value);

        }
    }

    validateValue = ( valResult, value ) => {

        if ( valResult ){

            this.validationStyle('success');
            if(this.props.onValidation) this.props.onValidation(value, this.props.data, this.props.mandatory);
        }
        else {

            this.validationStyle('error');
            if(this.props.onValidationFailure) this.props.onValidationFailure(this.props.data, this.props.mandatory);
        }
    }

    validationStyle = (resultString) => {

        if(this._ismounted) {
            this.setState({
                validationStatus: resultString,
            });
        }
    }

    renderInput() {

        const { onClick, onClickEvent, ...rest } = this.props;
        const { validationStatus } = this.state;

        let items = this.props.options;

        switch(this.props.type) {

            // socials
            case 'Facebook':
            return (
                <InputButton
                    {...rest}
                    onClick={this.props.onClickEvent}
                    className="facebook"
                    name=""
                    type="facebook"
                />
            );
            case 'java.time.LocalDateTime':
            return (
                <InputDatePicker
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}
                />
            );
            case 'TextArea':
            return (
                <InputTextarea
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}
                />
            );
            case 'Boolean':
            return (
                <InputCheckbox
                    {...rest}
                    validation={this.validateInput}
                    validationStatus={validationStatus}
{'fraction_non_alphanumeric': 0.10849514563106796, 'fraction_numerical': 0.0004854368932038835, 'mean_word_length': 1.4288240495137048, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '521104', 'n_tokens_mistral': 2159, 'n_tokens_neox': 2049, 'n_words': 387}