<commit_before>import Webiny from 'Webiny';
const Ui = Webiny.Ui.Components;

class ChangeConfirm extends Webiny.Ui.Component {
    constructor(props) {
        super(props);

        const input = this.getInput(props);
        this.state = {
            value: input.props.valueLink ? input.props.valueLink.value : input.props.value
        };

        this.hasValueLink = _.has(input.props, 'valueLink');
        this.message = null;

        this.bindMethods('onChange,onConfirm,onCancel');
    }

    componentWillReceiveProps(props) {
        super.componentWillReceiveProps(props);
        const input = this.getInput(props);
        this.setState({value: input.props.valueLink ? input.props.valueLink.value : input.props.value});
    }

    shouldComponentUpdate(nextProps) {
        return !_.isEqual(nextProps, this.props);
    }

    onChange(value) {
        const input = this.getInput(this.props);
        let component = null;
        if (input.props.form) {
            component = input.props.form.getInput(input.props.name);
        }

        let msg = this.props.message;
        if (_.isFunction(msg)) {
            msg = msg(value, this.hasValueLink ? this.realValueLink.value : input.props.value, component);
        }

        if (!msg) {
            if (this.hasValueLink) {
                this.realValueLink.requestChange(value);
            } else {
                this.realOnChange(value);
            }
            return;
        }

        this.message = msg;
        this.value = value;
        this.refs.dialog.show();
    }

    getInput(props) {
        return React.Children.toArray(props.children)[0];
    }

    onCancel() {
        const cancelValue = this.props.onCancel && this.props.onCancel(this.getInput(this.props).props.form) || undefined;
        if (!_.isUndefined(cancelValue)) {
            if (this.hasValueLink) {
                this.realValueLink.requestChange(cancelValue);
            } else {
                this.realOnChange(cancelValue);
            }
        } else {
            if (this.hasValueLink) {
                this.realValueLink.requestChange(this.realValueLink.value);
            }
        }
        this.refs.dialog.hide();
    }

    onConfirm() {
        if (this.hasValueLink) {
            this.realValueLink.requestChange(this.value);
        } else {
            this.realOnChange(this.value);
        }
        this.refs.dialog.hide();
    }
}

ChangeConfirm.defaultProps = {
    renderer() {
        // Input
        const input = this.getInput(this.props);
        let props = null;
        if (this.hasValueLink) {
            this.realValueLink = input.props.valueLink;
            props = _.omit(input.props, ['valueLink']);
            props.valueLink = this.bindTo('value', this.onChange);
        } else if (input.props.onChange) {
            this.realOnChange = input.props.onChange;
            props = _.omit(input.props, ['onChange']);
            props.onChange = this.onChange;
        } else {
            return input;
        }

        return (
            <webiny-change-confirm>
                {React.cloneElement(input, props)}
                <Ui.Modal.Confirmation ref="dialog" message={() => this.message} onConfirm={this.onConfirm} onCancel={this.onCancel}/>
            </webiny-change-confirm>
        );
    }
};

export default ChangeConfirm;<commit_msg>Added full list of props and onComplete callback.<commit_after>import Webiny from 'Webiny';
const Ui = Webiny.Ui.Components;

class ChangeConfirm extends Webiny.Ui.Component {
    constructor(props) {
        super(props);

        const input = this.getInput(props);
        this.state = {
            value: input.props.valueLink ? input.props.valueLink.value : input.props.value
        };

        this.hasValueLink = _.has(input.props, 'valueLink');
        this.message = null;

        this.bindMethods('onChange,onConfirm,onCancel');
    }

    componentWillReceiveProps(props) {
        super.componentWillReceiveProps(props);
        const input = this.getInput(props);
        this.setState({value: input.props.valueLink ? input.props.valueLink.value : input.props.value});
    }

    shouldComponentUpdate(nextProps) {
        return !_.isEqual(nextProps, this.props);
    }

    onChange(value) {
        const input = this.getInput(this.props);
        let component = null;
        if (input.props.form) {
            component = input.props.form.getInput(input.props.name);
        }

        let msg = this.props.message;
        if (_.isFunction(msg)) {
            msg = msg(value, this.hasValueLink ? this.realValueLink.value : input.props.value, component);
        }

        if (!msg) {
            if (this.hasValueLink) {
                this.realValueLink.requestChange(value);
            } else {
                this.realOnChange(value);
            }
            return;
        }

        this.message = msg;
        this.value = value;
        this.refs.dialog.show();
    }

    getInput(props) {
        return React.Children.toArray(props.children)[0];
    }

    onCancel() {
        const cancelValue = this.props.onCancel(this.getInput(this.props).props.form);
        const callback = this.hasValueLink ? this.realValueLink.requestChange : this.realOnChange;
        if (!_.isUndefined(cancelValue)) {
            callback(cancelValue);
        } else {
            if (this.hasValueLink) {
                this.realValueLink.requestChange(this.realValueLink.value);
            }
        }
        this.refs.dialog.hide();
    }

    onConfirm() {
        const callback = this.hasValueLink ? this.realValueLink.requestChange : this.realOnChange;
        return callback(this.value);
    }
}

ChangeConfirm.defaultProps = {
    onComplete: _.noop,
    onCancel: _.noop,
    renderDialog: null,
    renderer() {
        // Input
        const input = this.getInput(this.props);
        let props = null;
        if (this.hasValueLink) {
            this.realValueLink = input.props.valueLink;
            props = _.omit(input.props, ['valueLink']);
            props.valueLink = this.bindTo('value', this.onChange);
        } else if (input.props.onChange) {
            this.realOnChange = input.props.onChange;
            props = _.omit(input.props, ['onChange']);
            props.onChange = this.onChange;
        } else {
            return input;
        }

        const dialogProps = {
            ref: 'dialog',
            message: () => this.message,
            onConfirm: this.onConfirm,
            onCancel: this.onCancel,
            onComplete: this.props.onComplete
        };

        if (_.isFunction(this.props.renderDialog)) {
            dialogProps['renderDialog'] = this.props.renderDialog;
        }

        return (
            <webiny-change-confirm>
                {React.cloneElement(input, props)}
                <Ui.Modal.Confirmation {...dialogProps}/>
            </webiny-change-confirm>
        );
    }
};

export default ChangeConfirm;
{'fraction_non_alphanumeric': 0.12068718682891912, 'fraction_numerical': 0.0002863278453829635, 'mean_word_length': 1.9205685618729098, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 11, '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': '1454023', 'n_tokens_mistral': 2008, 'n_tokens_neox': 1970, 'n_words': 322}