<commit_before>import _, {get} from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {Item} from './index';
import {isCheckAllowed, closeActionsMenu, bindMarkItemShortcut} from '../helpers';
import {querySelectorParent} from 'core/helpers/dom/querySelectorParent';
import {isMediaEditable} from 'core/config';
import {gettext} from 'core/utils';
import {IArticle} from 'superdesk-api';
import {AuthoringWorkspaceService} from 'apps/authoring/authoring/services/AuthoringWorkspaceService';
import {CHECKBOX_PARENT_CLASS} from './constants';

interface IState {
    narrow: boolean;
    view: 'compact' | 'mgrid' | 'photogrid';
    itemsList: Array<string>;
    itemsById: any;
    selected: string;
    bindedShortcuts: Array<any>;
    swimlane: any;
    actioning: {};
}

/**
 * Item list component
 */
export class ItemList extends React.Component<any, IState> {
    static propTypes: any;
    static defaultProps: any;

    closeActionsMenu: any;
    updateTimeout: any;
    selectedCom: any;

    constructor(props) {
        super(props);

        this.state = {
            itemsList: [],
            itemsById: {},
            selected: null,
            view: 'compact',
            narrow: false,
            bindedShortcuts: [],
            swimlane: null,
            actioning: {},
        };

        this.multiSelect = this.multiSelect.bind(this);
        this.select = this.select.bind(this);
        this.selectItem = this.selectItem.bind(this);
        this.selectMultipleItems = this.selectMultipleItems.bind(this);
        this.dbClick = this.dbClick.bind(this);
        this.edit = this.edit.bind(this);
        this.deselectAll = this.deselectAll.bind(this);
        this.updateAllItems = this.updateAllItems.bind(this);
        this.findItemByPrefix = this.findItemByPrefix.bind(this);
        this.setSelectedItem = this.setSelectedItem.bind(this);
        this.getSelectedItem = this.getSelectedItem.bind(this);
        this.updateItem = this.updateItem.bind(this);
        this.handleKey = this.handleKey.bind(this);
        this.closeActionsMenu = closeActionsMenu.bind(this);
        this.setSelectedComponent = this.setSelectedComponent.bind(this);
        this.modifiedUserName = this.modifiedUserName.bind(this);
        this.setNarrowView = this.setNarrowView.bind(this);
        this.multiSelectCurrentItem = this.multiSelectCurrentItem.bind(this);
        this.bindActionKeyShortcuts = this.bindActionKeyShortcuts.bind(this);
        this.unbindActionKeyShortcuts = this.unbindActionKeyShortcuts.bind(this);
    }

    multiSelect(items, selected) {
        const {search, multi} = this.props.svc;
        const {scope} = this.props;

        const itemsById = angular.extend({}, this.state.itemsById);

        items.forEach((item) => {
            const itemId = search.generateTrackByIdentifier(item);

            itemsById[itemId] = angular.extend({}, item, {selected: selected});
            scope.$applyAsync(() => {
                multi.toggle(itemsById[itemId]);
            });
        });

        this.setState({itemsById: itemsById});
    }

    // Method to check the selectBox of the selected item
    multiSelectCurrentItem() {
        const selectedItem = this.getSelectedItem();
<commit_msg>Fix multiselect on authoring (#3333)<commit_after>import _, {get} from 'lodash';
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import {Item} from './index';
import {isCheckAllowed, closeActionsMenu, bindMarkItemShortcut} from '../helpers';
import {querySelectorParent} from 'core/helpers/dom/querySelectorParent';
import {isMediaEditable} from 'core/config';
import {gettext} from 'core/utils';
import {IArticle} from 'superdesk-api';
import {AuthoringWorkspaceService} from 'apps/authoring/authoring/services/AuthoringWorkspaceService';
import {CHECKBOX_PARENT_CLASS} from './constants';

interface IState {
    narrow: boolean;
    view: 'compact' | 'mgrid' | 'photogrid';
    itemsList: Array<string>;
    itemsById: any;
    selected: string;
    bindedShortcuts: Array<any>;
    swimlane: any;
    actioning: {};
}

/**
 * Item list component
 */
export class ItemList extends React.Component<any, IState> {
    static propTypes: any;
    static defaultProps: any;

    closeActionsMenu: any;
    updateTimeout: any;
    selectedCom: any;

    constructor(props) {
        super(props);

        this.state = {
            itemsList: [],
            itemsById: {},
            selected: null,
            view: 'compact',
            narrow: false,
            bindedShortcuts: [],
            swimlane: null,
            actioning: {},
        };

        this.multiSelect = this.multiSelect.bind(this);
        this.select = this.select.bind(this);
        this.selectItem = this.selectItem.bind(this);
        this.selectMultipleItems = this.selectMultipleItems.bind(this);
        this.dbClick = this.dbClick.bind(this);
        this.edit = this.edit.bind(this);
        this.deselectAll = this.deselectAll.bind(this);
        this.updateAllItems = this.updateAllItems.bind(this);
        this.findItemByPrefix = this.findItemByPrefix.bind(this);
        this.setSelectedItem = this.setSelectedItem.bind(this);
        this.getSelectedItem = this.getSelectedItem.bind(this);
        this.updateItem = this.updateItem.bind(this);
        this.handleKey = this.handleKey.bind(this);
        this.closeActionsMenu = closeActionsMenu.bind(this);
        this.setSelectedComponent = this.setSelectedComponent.bind(this);
        this.modifiedUserName = this.modifiedUserName.bind(this);
        this.setNarrowView = this.setNarrowView.bind(this);
        this.multiSelectCurrentItem = this.multiSelectCurrentItem.bind(this);
        this.bindActionKeyShortcuts = this.bindActionKeyShortcuts.bind(this);
        this.unbindActionKeyShortcuts = this.unbindActionKeyShortcuts.bind(this);
    }

    multiSelect(items: Array<IArticle>, selected: boolean) {
        const {search, multi} = this.props.svc;
        const {scope} = this.props;
        let {selected: selectedId} = this.state;

        const itemsById = angular.extend({}, this.state.itemsById);

        items.forEach((item, i) => {
            const itemId = search.generateTrackByIdentifier(item);

            if (selected && i === items.length - 1) {
                // Mark last item as selected
                selectedId = itemId;
            }
            itemsById[itemId] = angular.extend({}, item, {selected: selected});
            scope.$applyAsync(() => {
                multi.toggle(itemsById[itemId]);
            });
        });

        this.setState({itemsById, selected: selectedId});
    }

    // Method to check the selectBox of the selected item
    multiSelectCurrentItem() {
        const selectedItem = this.getSelectedItem();

{'fraction_non_alphanumeric': 0.1200058114194392, 'fraction_numerical': 0.000726427429899753, 'mean_word_length': 2.9292237442922375, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 14, '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': '4729223', 'n_tokens_mistral': 1971, 'n_tokens_neox': 1944, 'n_words': 392}