<commit_before>import Webiny from 'Webiny';
import BaseContainer from './BaseContainer';

class ApiContainer extends BaseContainer {

    constructor(props) {
        super(props);

        Webiny.Mixins.ApiComponent.extend(this);
    }

    componentWillMount() {
        super.componentWillMount();
        this.prepare(_.clone(this.props));
        if (this.props.autoLoad) {
            this.loadData();
        }
    }

    componentDidMount() {
        super.componentDidMount();
        if (this.props.autoRefresh && _.isNumber(this.props.autoRefresh)) {
            this.autoRefresh = setInterval(this.loadData, 1000 * this.props.autoRefresh);
        }
    }

    componentWillUnmount() {
        super.componentWillUnmount();
        clearInterval(this.autoRefresh);
        if (this.request) {
            this.request.abort();
        }
    }

    componentWillReceiveProps(props) {
        super.componentWillReceiveProps(props);
        const checkParams = ['sorters', 'filters', 'page', 'perPage', 'searchQuery', 'searchOperator', 'searchFields'];
        const prevQueryParams = _.pick(this.state, checkParams);
        const newQueryParams = _.pick(this.prepare(_.clone(props)), checkParams);
        const queryParamsChanged = !_.isEqual(prevQueryParams, newQueryParams);
        // Need to do this explicit check because 'query' prop can contain data coming from anywhere and it is not processed in 'prepare'
        const queryPropsChanged = !_.isEqual(props.query, this.props.query);
        if (this.props.autoLoad && (queryParamsChanged || queryPropsChanged)) {
            this.loadData(props);
        }
    }

    loadData(props = null) {
        if (!props) {
            props = this.props;
        }
        const selectedRows = this.state.selectedRows;
        selectedRows.clear();
        this.setState({selectedRows});
        const query = _.assign({}, props.query, this.state.filters, {
            _sort: Webiny.Router.sortersToString(this.state.sorters),
            _perPage: this.state.perPage,
            _page: this.state.page,
            _searchQuery: this.state.searchQuery,
            _searchFields: this.state.searchFields,
            _searchOperator: this.state.searchOperator
        });

        this.showLoading();
        this.request = this.api.setQuery(query).execute().then(apiResponse => {
            const data = {loading: false};
            if (!apiResponse.isError() && !apiResponse.isAborted()) {
                _.merge(data, apiResponse.getData());
                if (this.props.prepareLoadedData) {
                    data.list = this.props.prepareLoadedData(data.list);
                }
            }
            this.setState(data);

            return data;
        });

        return this.request;
    }

    getContainerActions() {
        const actions = super.getContainerActions();
        actions.api = this.api;
        return actions;
    }<commit_msg>Autorefresh of lists will not show loader.<commit_after>import Webiny from 'Webiny';
import BaseContainer from './BaseContainer';

class ApiContainer extends BaseContainer {

    constructor(props) {
        super(props);

        Webiny.Mixins.ApiComponent.extend(this);
    }

    componentWillMount() {
        super.componentWillMount();
        this.prepare(_.clone(this.props));
        if (this.props.autoLoad) {
            this.loadData();
        }
    }

    componentDidMount() {
        super.componentDidMount();
        if (this.props.autoRefresh && _.isNumber(this.props.autoRefresh)) {
            this.autoRefresh = setInterval(() => this.loadData(null, false), 1000 * this.props.autoRefresh);
        }
    }

    componentWillUnmount() {
        super.componentWillUnmount();
        clearInterval(this.autoRefresh);
        if (this.request) {
            this.request.abort();
        }
    }

    componentWillReceiveProps(props) {
        super.componentWillReceiveProps(props);
        const checkParams = ['sorters', 'filters', 'page', 'perPage', 'searchQuery', 'searchOperator', 'searchFields'];
        const prevQueryParams = _.pick(this.state, checkParams);
        const newQueryParams = _.pick(this.prepare(_.clone(props)), checkParams);
        const queryParamsChanged = !_.isEqual(prevQueryParams, newQueryParams);
        // Need to do this explicit check because 'query' prop can contain data coming from anywhere and it is not processed in 'prepare'
        const queryPropsChanged = !_.isEqual(props.query, this.props.query);
        if (this.props.autoLoad && (queryParamsChanged || queryPropsChanged)) {
            this.loadData(props);
        }
    }

    loadData(props = null, showLoading = true) {
        if (!props) {
            props = this.props;
        }
        const selectedRows = this.state.selectedRows;
        selectedRows.clear();
        this.setState({selectedRows});
        const query = _.assign({}, props.query, this.state.filters, {
            _sort: Webiny.Router.sortersToString(this.state.sorters),
            _perPage: this.state.perPage,
            _page: this.state.page,
            _searchQuery: this.state.searchQuery,
            _searchFields: this.state.searchFields,
            _searchOperator: this.state.searchOperator
        });

        if (showLoading) {
            this.showLoading();
        }

        this.request = this.api.setQuery(query).execute().then(apiResponse => {
            const data = {loading: false};
            if (!apiResponse.isError() && !apiResponse.isAborted()) {
                _.merge(data, apiResponse.getData());
                if (this.props.prepareLoadedData) {
                    data.list = this.props.prepareLoadedData(data.list);
                }
            }
            this.setState(data);

            return data;
        });

        return this.request;
    }

    getContainerActions() {
        const actions = super.getContainerActions();
        actions.api = this.api;
        return actions;
    }
{'fraction_non_alphanumeric': 0.11809969889595183, 'fraction_numerical': 0.0013382402141184342, 'mean_word_length': 2.23714131023281, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '5520360', 'n_tokens_mistral': 1612, 'n_tokens_neox': 1584, 'n_words': 306}