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

class Confirmation extends Webiny.Ui.ModalComponent {

    constructor(props) {
        super(props);

        this.state = {
            loading: false
        };

        this.data = [];
        this.bindMethods('showLoading,renderContent,renderLoader,renderDialog,onCancel,onConfirm');
    }

    show() {
        this.setState({time: new Date().getTime()});
        return super.show();
    }

    showLoading() {
        this.setState({loading: true});
    }

    hideLoading() {
        this.setState({loading: false});
    }

    onCancel() {
        if (!this.isAnimating()) {
            if (_.isFunction(this.props.onCancel)) {
                return this.props.onCancel(this);
            }
            return this.hide();
        }
    }

    onConfirm() {
        if (_.isFunction(this.props.onConfirm)) {
            const data = _.clone(this.data);
            data.push(this);
            this.showLoading();
            return Q(this.props.onConfirm(...data)).then(result => {
                this.hideLoading();
                if (this.props.autoHide) {
                    return this.hide().then(() => this.props.onComplete(result));
                }
            });
        }
    }

    renderLoader() {
        if (this.state.loading) {
            return this.props.renderLoader();
        }
        return null;
    }

    renderContent() {
        let content = this.props.message;
        if (!content) {
            content = this.props.children;
        }

        if (_.isFunction(content)) {
            content = content();
        }
        return content;
    }

    setData(...data) {
        this.data = data;
        return this;
    }

    renderDialog() {
        return this.props.renderDialog.call(this, this.onConfirm, this.onCancel, this);<commit_msg>Confirmation dialog now properly handles functions as a result of onConfirm functions, by hiding the dialog first, then calling onComplete.<commit_after>import Webiny from 'Webiny';
const Ui = Webiny.Ui.Components;

class Confirmation extends Webiny.Ui.ModalComponent {

    constructor(props) {
        super(props);

        this.state = {
            loading: false
        };

        this.data = [];
        this.bindMethods('showLoading,renderContent,renderLoader,renderDialog,onCancel,onConfirm');
    }

    show() {
        this.setState({time: new Date().getTime()});
        return super.show();
    }

    showLoading() {
        this.setState({loading: true});
    }

    hideLoading() {
        this.setState({loading: false});
    }

    onCancel() {
        if (!this.isAnimating()) {
            if (_.isFunction(this.props.onCancel)) {
                return this.props.onCancel(this);
            }
            return this.hide();
        }
    }

    onConfirm() {
        if (_.isFunction(this.props.onConfirm)) {
            const data = _.clone(this.data);
            data.push(this);
            this.showLoading();
            return Q(this.props.onConfirm(...data)).then(result => {
                if (this.isMounted()) {
                    this.hideLoading();
                }
                if (this.props.autoHide) {
                    return this.hide().then(() => {
                        // If the result of confirmation is a function, it means we need to hide the dialog before executing it.
                        // This is often necessary if the function will set a new state in the view - it will re-render itself and the modal
                        // animation will be aborted (most common case is delete confirmation).
                        if (_.isFunction(result)) {
                            // The result of the function will be passed to `onComplete` and not the function itself
                            result = result();
                        }
                        this.props.onComplete(result);
                    });
                }
            });
        }
    }

    renderLoader() {
        if (this.state.loading) {
            return this.props.renderLoader();
        }
        return null;
    }

    renderContent() {
        let content = this.props.message;
        if (!content) {
            content = this.props.children;
        }

        if (_.isFunction(content)) {
            content = content();
        }
        return content;
    }

    setData(...data) {
        this.data = data;
        return this;
    }

    renderDialog() {
        return this.props.renderDialog.call(this, this.onConfirm, this.onCancel, this);
{'fraction_non_alphanumeric': 0.11914615552167283, 'fraction_numerical': 0.0, 'mean_word_length': 1.5582172701949861, 'pattern_counts': {'":': 0, '<': 3, '<?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': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654093', 'n_tokens_mistral': 1230, 'n_tokens_neox': 1197, 'n_words': 264}