import React from 'react'; import _ from 'lodash'; import PropTypes from 'prop-types'; import AssociationPickerResults from './AssociationPickerResults'; class AssociationPickerWindow extends React.Component { constructor(props) { super(props); this.state = { ...props, selectedItems: [] }; this.selectItem = this.selectItem.bind(this); } selectItem(item) { const operation = this.updateSelectedItems(item); if ('onSelectItem' in this.props) { this.props.onSelectItem(item, operation); } } updateSelectedItems(item) { let operation, newItems; if (item._selected) { newItems = _.filter(this.state.selectedItems, r => r.id !== item.id); operation = 'removed'; } else { newItems = [...this.state.selectedItems, item]; operation = 'added'; } this.setState(...this.state, { selectedItems: newItems }); return operation; } render() { const { q, results } = this.props; return (