import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; import { defineMessages, injectIntl, FormattedMessage } from 'react-intl'; import Toggle from 'react-toggle'; import AsyncSelect from 'react-select/async'; import { NonceProvider } from 'react-select'; import SettingToggle from '../../notifications/components/setting_toggle'; const messages = defineMessages({ placeholder: { id: 'hashtag.column_settings.select.placeholder', defaultMessage: 'Enter hashtags…' }, noOptions: { id: 'hashtag.column_settings.select.no_options_message', defaultMessage: 'No suggestions found' }, }); export default @injectIntl 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 => value => this.props.onChange(['tags', mode], value); onToggle = () => { if (this.state.open && this.hasTags()) { this.props.onChange('tags', {}); } this.setState({ open: !this.state.open }); }; noOptionsMessage = () => this.props.intl.formatMessage(messages.noOptions); modeSelect (mode) { return (
{this.modeLabel(mode)}
); } modeLabel (mode) { switch(mode) { case 'any': return ; case 'all': return ; case 'none': return ; default: return ''; } }; render () { const { settings, onChange } = this.props; return (
{this.state.open && (
{this.modeSelect('any')} {this.modeSelect('all')} {this.modeSelect('none')}
)}
} />
); } }