import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { injectIntl, FormattedMessage } from 'react-intl'; import Toggle from 'react-toggle'; import AsyncSelect from 'react-select/lib/Async'; @injectIntl export default class ColumnSettings extends React.PureComponent { static propTypes = { settings: ImmutablePropTypes.map.isRequired, onChange: PropTypes.func.isRequired, onLoad: PropTypes.func.isRequired, intl: PropTypes.object.isRequired, }; state = { open: this.hasTags(), }; hasTags () { return ['all', 'any', 'none'].map(mode => this.tags(mode).length > 0).includes(true); } tags (mode) { let tags = this.props.settings.getIn(['tags', mode]) || []; if (tags.toJSON) { return tags.toJSON(); } else { return tags; } }; onSelect = (mode) => { return (value) => { this.props.onChange(['tags', mode], value); }; }; onToggle = () => { if (this.state.open && this.hasTags()) { this.props.onChange('tags', {}); } this.setState({ open: !this.state.open }); }; modeSelect (mode) { return (
{this.modeLabel(mode)}
); } modeLabel (mode) { switch(mode) { case 'any': return ; case 'all': return ; case 'none': return ; } return ''; }; render () { return (
{this.state.open &&
{this.modeSelect('any')} {this.modeSelect('all')} {this.modeSelect('none')}
}
); } }