<commit_before>import React from 'react';
import {IPropsSelectUser, IUser} from 'superdesk-api';
import {Select2} from './select2';
import {keyBy} from 'lodash';
import {gettext} from 'core/utils';
import {dataApi} from 'core/helpers/CrudManager';
import {ListItem, ListItemColumn, ListItemRow} from 'core/components/ListItem';
import {UserAvatar} from 'apps/users/components/UserAvatar';

interface IState {
    fetchedUsers?: Array<IUser>;
    selectedUser?: IUser;
    loading: boolean;
}

export class SelectUser extends React.Component<IPropsSelectUser, IState> {
    constructor(props: IPropsSelectUser) {
        super(props);

        this.state = {
            loading: false,
        };

        this.queryUsers = this.queryUsers.bind(this);
    }

    queryUsers(_searchString: string = '') {
        const searchString = _searchString.trim();

        this.setState({loading: true, fetchedUsers: null});

        return dataApi.query<IUser>(
            'users',
            1,
            {field: 'display_name', direction: 'ascending'},
            (
                searchString.length > 0
                    ? {
                        $or: [
                            {
                                display_name: {
                                    $regex: searchString,
                                    $options: '-i',
                                },
                            },
                            {
                                username: {
                                    $regex: searchString,
                                    $options: '-i',
                                },
                            },
                        ],
                    }
                    : {}
            ),
            50,
        )
            .then((res) => {
                this.setState({
                    fetchedUsers: res._items,
                    loading: false,
                });
            });
    }

    componentDidMount() {
        this.queryUsers();
    }

    render() {
        const keyedUsers = keyBy(this.state.fetchedUsers, (user) => user._id);
<commit_msg>don't call setState after the component is unmounted (#3584)<commit_after>import React from 'react';
import {IPropsSelectUser, IUser} from 'superdesk-api';
import {Select2} from './select2';
import {keyBy} from 'lodash';
import {gettext} from 'core/utils';
import {dataApi} from 'core/helpers/CrudManager';
import {ListItem, ListItemColumn, ListItemRow} from 'core/components/ListItem';
import {UserAvatar} from 'apps/users/components/UserAvatar';

interface IState {
    fetchedUsers?: Array<IUser>;
    selectedUser?: IUser;
    loading: boolean;
}

export class SelectUser extends React.Component<IPropsSelectUser, IState> {
    _mounted: boolean;

    constructor(props: IPropsSelectUser) {
        super(props);

        this.state = {
            loading: false,
        };

        this.queryUsers = this.queryUsers.bind(this);

        this._mounted = false;
    }

    queryUsers(_searchString: string = '') {
        const searchString = _searchString.trim();

        this.setState({loading: true, fetchedUsers: null});

        return dataApi.query<IUser>(
            'users',
            1,
            {field: 'display_name', direction: 'ascending'},
            (
                searchString.length > 0
                    ? {
                        $or: [
                            {
                                display_name: {
                                    $regex: searchString,
                                    $options: '-i',
                                },
                            },
                            {
                                username: {
                                    $regex: searchString,
                                    $options: '-i',
                                },
                            },
                        ],
                    }
                    : {}
            ),
            50,
        )
            .then((res) => {
                if (this._mounted === true) {
                    this.setState({
                        fetchedUsers: res._items,
                        loading: false,
                    });
                }
            });
    }

    componentDidMount() {
        this._mounted = true;

        this.queryUsers();
    }

    componentWillUnmount() {
        this._mounted = false;
    }

    render() {
        const keyedUsers = keyBy(this.state.fetchedUsers, (user) => user._id);

{'fraction_non_alphanumeric': 0.10631741140215717, 'fraction_numerical': 0.0035219018269865726, 'mean_word_length': 1.162779628748215, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1356610', 'n_tokens_mistral': 1167, 'n_tokens_neox': 1097, 'n_words': 224}