import React from 'react'; import {IArticle} from 'superdesk-api'; import {IMultiSelectOptions} from './MultiSelectHoc'; import {SelectBoxWithoutMutation} from 'apps/search/components/SelectBox'; import {TypeIcon} from 'apps/search/components'; import {OrderedMap} from 'immutable'; import {generateTrackByIdentifier} from 'apps/search/services/SearchService'; interface IProps { item: IArticle; allItems: OrderedMap; options: IMultiSelectOptions; } /** * This component is meant to work with IMultiSelectNew interface. * Multi-selection in angular based lists works differently and uses ILegacyMultiSelect interface. */ export class MultiSelect extends React.Component { render() { const {item, allItems, options} = this.props; const checkbox = ( { if (multiSelectMode) { const lastMultiselected = options.selected.last(); const itemsSeq = allItems.valueSeq(); const lastSelectedIndex = itemsSeq.indexOf(lastMultiselected); const currentIndex = itemsSeq.indexOf(item); const from = Math.min(lastSelectedIndex, currentIndex); const to = Math.max(lastSelectedIndex, currentIndex) + 1; options.selectMultiple( allItems.slice(from, to).toOrderedMap(), ); } else { options.toggle(item); } }} selected={options.selected.has(generateTrackByIdentifier(item))} className="hover-AB--B" data-test-id="multi-select-checkbox" /> ); return (
{ options.selected.has(generateTrackByIdentifier(item)) ? checkbox : (
{checkbox}
) }
); } }