11import React from 'react' ;
22import PropTypes from 'prop-types' ;
33import ImmutablePropTypes from 'react-immutable-proptypes' ;
4- import { injectIntl , FormattedMessage } from 'react-intl' ;
4+ import { defineMessages , injectIntl , FormattedMessage } from 'react-intl' ;
55import Toggle from 'react-toggle' ;
66import AsyncSelect from 'react-select/lib/Async' ;
77
8+ const messages = defineMessages ( {
9+ placeholder : { id : 'hashtag.column_settings.select.placeholder' , defaultMessage : 'Enter hashtags…' } ,
10+ noOptions : { id : 'hashtag.column_settings.select.no_options_message' , defaultMessage : 'No suggestions found' } ,
11+ } ) ;
12+
813export default @injectIntl
914class ColumnSettings extends React . PureComponent {
1015
@@ -25,76 +30,82 @@ class ColumnSettings extends React.PureComponent {
2530
2631 tags ( mode ) {
2732 let tags = this . props . settings . getIn ( [ 'tags' , mode ] ) || [ ] ;
33+
2834 if ( tags . toJSON ) {
2935 return tags . toJSON ( ) ;
3036 } else {
3137 return tags ;
3238 }
3339 } ;
3440
35- onSelect = ( mode ) => {
36- return ( value ) => {
37- this . props . onChange ( [ 'tags' , mode ] , value ) ;
38- } ;
39- } ;
41+ onSelect = mode => value => this . props . onChange ( [ 'tags' , mode ] , value ) ;
4042
4143 onToggle = ( ) => {
4244 if ( this . state . open && this . hasTags ( ) ) {
4345 this . props . onChange ( 'tags' , { } ) ;
4446 }
47+
4548 this . setState ( { open : ! this . state . open } ) ;
4649 } ;
4750
51+ noOptionsMessage = ( ) => this . props . intl . formatMessage ( messages . noOptions ) ;
52+
4853 modeSelect ( mode ) {
4954 return (
50- < div className = 'column-settings__section' >
51- { this . modeLabel ( mode ) }
55+ < div className = 'column-settings__row' >
56+ < span className = 'column-settings__section' >
57+ { this . modeLabel ( mode ) }
58+ </ span >
59+
5260 < AsyncSelect
5361 isMulti
5462 autoFocus
5563 value = { this . tags ( mode ) }
56- settings = { this . props . settings }
57- settingPath = { [ 'tags' , mode ] }
5864 onChange = { this . onSelect ( mode ) }
5965 loadOptions = { this . props . onLoad }
60- classNamePrefix = 'column-settings__hashtag-select'
66+ className = 'column-select__container'
67+ classNamePrefix = 'column-select'
6168 name = 'tags'
69+ placeholder = { this . props . intl . formatMessage ( messages . placeholder ) }
70+ noOptionsMessage = { this . noOptionsMessage }
6271 />
6372 </ div >
6473 ) ;
6574 }
6675
6776 modeLabel ( mode ) {
6877 switch ( mode ) {
69- case 'any' : return < FormattedMessage id = 'hashtag.column_settings.tag_mode.any' defaultMessage = 'Any of these' /> ;
70- case 'all' : return < FormattedMessage id = 'hashtag.column_settings.tag_mode.all' defaultMessage = 'All of these' /> ;
71- case 'none' : return < FormattedMessage id = 'hashtag.column_settings.tag_mode.none' defaultMessage = 'None of these' /> ;
78+ case 'any' :
79+ return < FormattedMessage id = 'hashtag.column_settings.tag_mode.any' defaultMessage = 'Any of these' /> ;
80+ case 'all' :
81+ return < FormattedMessage id = 'hashtag.column_settings.tag_mode.all' defaultMessage = 'All of these' /> ;
82+ case 'none' :
83+ return < FormattedMessage id = 'hashtag.column_settings.tag_mode.none' defaultMessage = 'None of these' /> ;
84+ default :
85+ return '' ;
7286 }
73- return '' ;
7487 } ;
7588
7689 render ( ) {
7790 return (
7891 < div >
7992 < div className = 'column-settings__row' >
8093 < div className = 'setting-toggle' >
81- < Toggle
82- id = 'hashtag.column_settings.tag_toggle'
83- onChange = { this . onToggle }
84- checked = { this . state . open }
85- />
94+ < Toggle id = 'hashtag.column_settings.tag_toggle' onChange = { this . onToggle } checked = { this . state . open } />
95+
8696 < span className = 'setting-toggle__label' >
8797 < FormattedMessage id = 'hashtag.column_settings.tag_toggle' defaultMessage = 'Include additional tags in this column' />
8898 </ span >
8999 </ div >
90100 </ div >
91- { this . state . open &&
101+
102+ { this . state . open && (
92103 < div className = 'column-settings__hashtags' >
93104 { this . modeSelect ( 'any' ) }
94105 { this . modeSelect ( 'all' ) }
95106 { this . modeSelect ( 'none' ) }
96107 </ div >
97- }
108+ ) }
98109 </ div >
99110 ) ;
100111 }
0 commit comments