<commit_before>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import { PERSON_RELATION, LOCATION_RELATION } from '../constants/relationTypes';
import { convertToInputValue, createInputValue } from '../utils/createInputValue';
import PersonFinderData from './PersonFinderData';

export default class PersonFinder extends Component {
    static propTypes = {
        onChange: PropTypes.func,
        showPersons: PropTypes.bool,
        showSites: PropTypes.bool,
        className: PropTypes.string,
        defaultValue: PropTypes.oneOfType([
            PropTypes.shape({
                name: PropTypes.string,
                firstName: PropTypes.string,
                lastName: PropTypes.string,
                siteId: PropTypes.string,
                personId: PropTypes.string,
            }),
            PropTypes.string,
        ]),
    };

    static defaultProps = {
        onChange: null,
        showPersons: true,
        showSites: true,
        defaultValue: null,
        className: null,
    };

    static PERSON = PERSON_RELATION;

    static LOCATION = LOCATION_RELATION;

    constructor(props) {
        super(props);

        this.state = {
            value: createInputValue(props.defaultValue) || '',
            selectedValue: !!props.defaultValue,
        };

        this.handleSelect = this.handleSelect.bind(this);
        this.handleOnChange = this.handleOnChange.bind(this);
    }

    handleOnChange(value) {
        this.setState({
            value,
            selectedValue: false,
        });
    }

    handleSelect(type, value) {
        const { onChange } = this.props;
        const name = convertToInputValue(value);

        this.setState({
            value: name,
            selectedValue: true
        });

        if (onChange) {
            onChange({
                type,
                name: value.name,
                firstName: value.firstName,
                lastName: value.lastName,
                personId: value.personId,
                userId: value.userId,
                siteId: value.siteId,
                locationId: value.locationId,
            });
        }
    }

    clear() {
        this.setState({
            value: '',
        });
    }

    render() {
        const {
            showPersons,
            showSites,
            className,
            value: propValue, /* eslint-disable-line react/prop-types */
            defaultValue,
            ...props
        } = this.props;
        const { value, selectedValue } = this.state;

        return (
            <div className={classnames('cc__person-finder', className)}>
                <PersonFinderData
                    {...props}
                    value={value}
                    selectedValue={selectedValue}
                    onChange={this.handleOnChange}
                    onSelect={this.handleSelect}
                    persons={showPersons}
                    sites={showSites}
                />
            </div>
        );
    }
}
<commit_msg>Make clear() api-compatible<commit_after>import React, { Component } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';

import { PERSON_RELATION, LOCATION_RELATION } from '../constants/relationTypes';
import { convertToInputValue, createInputValue } from '../utils/createInputValue';
import PersonFinderData from './PersonFinderData';

export default class PersonFinder extends Component {
    static propTypes = {
        onChange: PropTypes.func,
        showPersons: PropTypes.bool,
        showSites: PropTypes.bool,
        className: PropTypes.string,
        defaultValue: PropTypes.oneOfType([
            PropTypes.shape({
                name: PropTypes.string,
                firstName: PropTypes.string,
                lastName: PropTypes.string,
                siteId: PropTypes.string,
                personId: PropTypes.string,
            }),
            PropTypes.string,
        ]),
    };

    static defaultProps = {
        onChange: null,
        showPersons: true,
        showSites: true,
        defaultValue: null,
        className: null,
    };

    static PERSON = PERSON_RELATION;

    static LOCATION = LOCATION_RELATION;

    constructor(props) {
        super(props);

        this.state = {
            value: createInputValue(props.defaultValue) || '',
            selectedValue: !!props.defaultValue,
        };

        this.clear = this.clear.bind(this);
        this.handleSelect = this.handleSelect.bind(this);
        this.handleOnChange = this.handleOnChange.bind(this);
    }

    handleOnChange(value) {
        this.setState({
            value,
            selectedValue: false,
        });
    }

    handleSelect(type, value) {
        const { onChange } = this.props;
        const name = convertToInputValue(value);

        this.setState({
            value: name,
            selectedValue: true
        });

        if (onChange) {
            onChange({
                type,
                name: value.name,
                firstName: value.firstName,
                lastName: value.lastName,
                personId: value.personId,
                userId: value.userId,
                siteId: value.siteId,
                locationId: value.locationId,
            });
        }
    }

    clear() {
        const { onChange } = this.props;

        this.setState({
            value: '',
        });

        if (onChange) {
            onChange(null);
        }
    }

    render() {
        const {
            showPersons,
            showSites,
            className,
            value: propValue, /* eslint-disable-line react/prop-types */
            defaultValue,
            ...props
        } = this.props;
        const { value, selectedValue } = this.state;

        return (
            <div className={classnames('cc__person-finder', className)}>
                <PersonFinderData
                    {...props}
                    value={value}
                    selectedValue={selectedValue}
                    onChange={this.handleOnChange}
                    onSelect={this.handleSelect}
                    persons={showPersons}
                    sites={showSites}
                />
            </div>
        );
    }
}

{'fraction_non_alphanumeric': 0.09976322020520915, 'fraction_numerical': 0.0, 'mean_word_length': 1.5263157894736843, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '4262029', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1607, 'n_words': 318}