@@ -5,60 +5,38 @@ import DropdownWidget from '../widgets/Dropdown';
55import TextInput from '../widgets/TextInput' ;
66import { connectToContainer } from 'lib' ;
77
8- const operators = [
9- {
10- label : 'Inequality' ,
11- value : 'inequality' ,
12- } ,
13- {
14- label : 'Include Range' ,
15- value : 'inrange' ,
16- } ,
17- {
18- label : 'Exclude Range' ,
19- value : 'exrange' ,
20- } ,
21- {
22- label : 'Include Values' ,
23- value : 'inset' ,
24- } ,
25- {
26- label : 'Exclude Values' ,
27- value : 'exset' ,
28- } ,
29- ] ;
30-
31- const operations = {
8+ const operations = _ => ( {
329 inequality : [
33- { value : '!=' , label : 'Target ≠ Reference' } ,
34- { value : '<' , label : 'Target < Reference' } ,
35- { value : '<=' , label : 'Target ≤ Reference' } ,
36- { value : '=' , label : 'Target = Reference' } ,
37- { value : '>' , label : 'Target > Reference' } ,
38- { value : '>=' , label : 'Target ≥ Reference' } ,
10+ { value : '!=' , label : _ ( 'Target ≠ Reference' ) } ,
11+ { value : '<' , label : _ ( 'Target < Reference' ) } ,
12+ { value : '<=' , label : _ ( 'Target ≤ Reference' ) } ,
13+ { value : '=' , label : _ ( 'Target = Reference' ) } ,
14+ { value : '>' , label : _ ( 'Target > Reference' ) } ,
15+ { value : '>=' , label : _ ( 'Target ≥ Reference' ) } ,
3916 ] ,
4017 inrange : [
41- { value : '[]' , label : 'Lower ≤ Target ≤ Upper' } ,
42- { value : '()' , label : 'Lower < Target < Upper' } ,
43- { value : '[)' , label : 'Lower ≤ Target < Upper' } ,
44- { value : '(]' , label : 'Lower < Target ≤ Upper' } ,
18+ { value : '[]' , label : _ ( 'Lower ≤ Target ≤ Upper' ) } ,
19+ { value : '()' , label : _ ( 'Lower < Target < Upper' ) } ,
20+ { value : '[)' , label : _ ( 'Lower ≤ Target < Upper' ) } ,
21+ { value : '(]' , label : _ ( 'Lower < Target ≤ Upper' ) } ,
4522 ] ,
4623 exrange : [
47- { value : ')(' , label : 'Lower ≤ Target ≤ Upper' } ,
48- { value : '][' , label : 'Lower < Target < Upper' } ,
49- { value : ')[' , label : 'Lower ≤ Target < Upper' } ,
50- { value : '](' , label : 'Lower < Target ≤ Upper' } ,
24+ { value : ')(' , label : _ ( 'Lower ≤ Target ≤ Upper' ) } ,
25+ { value : '][' , label : _ ( 'Lower < Target < Upper' ) } ,
26+ { value : ')[' , label : _ ( 'Lower ≤ Target < Upper' ) } ,
27+ { value : '](' , label : _ ( 'Lower < Target ≤ Upper' ) } ,
5128 ] ,
52- inset : [ { value : '{}' , label : 'Include' } ] ,
53- exset : [ { value : '}{' , label : 'Exclude' } ] ,
54- } ;
29+ inset : [ { value : '{}' , label : _ ( 'Include' ) } ] ,
30+ exset : [ { value : '}{' , label : _ ( 'Exclude' ) } ] ,
31+ } ) ;
5532
56- const findOperation = operator => {
33+ const findOperation = ( operator , _ ) => {
5734 let op = 'inequality' ;
58- for ( const key in operations ) {
35+ const ops = operations ( _ ) ;
36+ for ( const key in ops ) {
5937 if (
60- operations . hasOwnProperty ( key ) &&
61- operations [ key ] . map ( o => o . value ) . indexOf ( operator ) !== - 1
38+ ops . hasOwnProperty ( key ) &&
39+ ops [ key ] . map ( o => o . value ) . indexOf ( operator ) !== - 1
6240 ) {
6341 op = key ;
6442 break ;
@@ -70,17 +48,19 @@ const findOperation = operator => {
7048class UnconnectedFilterOperation extends Component {
7149 constructor ( props , context ) {
7250 super ( props , context ) ;
51+ const { localize : _ } = context ;
7352
7453 this . state = {
75- operation : findOperation ( this . props . fullValue ) ,
76- operator : operations . inequality [ 0 ] . value ,
54+ operation : findOperation ( this . props . fullValue , _ ) ,
55+ operator : operations ( _ ) . inequality [ 0 ] . value ,
7756 } ;
7857
7958 this . setOperation = this . setOperation . bind ( this ) ;
8059 }
8160
8261 setOperation ( value ) {
83- const operator = operations [ value ] [ 0 ] . value ;
62+ const { localize : _ } = this . context ;
63+ const operator = operations ( _ ) [ value ] [ 0 ] . value ;
8464 this . setState ( { operation : value , operator : operator } ) ;
8565 this . props . updatePlot ( operator ) ;
8666 }
@@ -94,6 +74,30 @@ class UnconnectedFilterOperation extends Component {
9474 backgroundDark,
9575 attr,
9676 } = this . props ;
77+ const { localize : _ } = this . context ;
78+
79+ const operators = [
80+ {
81+ label : _ ( 'Inequality' ) ,
82+ value : 'inequality' ,
83+ } ,
84+ {
85+ label : _ ( 'Include Range' ) ,
86+ value : 'inrange' ,
87+ } ,
88+ {
89+ label : _ ( 'Exclude Range' ) ,
90+ value : 'exrange' ,
91+ } ,
92+ {
93+ label : _ ( 'Include Values' ) ,
94+ value : 'inset' ,
95+ } ,
96+ {
97+ label : _ ( 'Exclude Values' ) ,
98+ value : 'exset' ,
99+ } ,
100+ ] ;
97101
98102 const opValue =
99103 fullValue && fullValue . length > 0 ? fullValue : this . state . operator ;
@@ -103,7 +107,7 @@ class UnconnectedFilterOperation extends Component {
103107 < DropdownWidget
104108 backgroundDark = { backgroundDark }
105109 options = { operators }
106- value = { findOperation ( opValue ) }
110+ value = { findOperation ( opValue , _ ) }
107111 onChange = { this . setOperation }
108112 clearable = { false }
109113 optionRenderer = { optionRenderer }
@@ -113,7 +117,7 @@ class UnconnectedFilterOperation extends Component {
113117 this . state . operation === 'exset' ? null : (
114118 < DropdownWidget
115119 backgroundDark = { backgroundDark }
116- options = { operations [ this . state . operation ] }
120+ options = { operations ( _ ) [ this . state . operation ] }
117121 value = { opValue }
118122 onChange = { updatePlot }
119123 clearable = { false }
@@ -132,6 +136,9 @@ UnconnectedFilterOperation.propTypes = {
132136 updatePlot : PropTypes . func ,
133137 ...Field . propTypes ,
134138} ;
139+ UnconnectedFilterOperation . contextTypes = {
140+ localize : PropTypes . func ,
141+ } ;
135142
136143class UnconnectedFilterValue extends Component {
137144 constructor ( props , context ) {
@@ -144,7 +151,8 @@ class UnconnectedFilterValue extends Component {
144151 }
145152
146153 setValue ( v ) {
147- const op = findOperation ( this . context . container . operation ) ;
154+ const { localize : _ , container} = this . context ;
155+ const op = findOperation ( container . operation , _ ) ;
148156 this . setState ( { value : v } ) ;
149157 let val ;
150158 val = op === 'inrange' || op === 'exrange' ? [ v , this . state . valueMax ] : v ;
@@ -167,7 +175,7 @@ class UnconnectedFilterValue extends Component {
167175 container && container . operation ? container . operation : '=' ;
168176
169177 const { fullValue, attr, defaultValue} = this . props ;
170- const op = findOperation ( operation ) ;
178+ const op = findOperation ( operation , _ ) ;
171179
172180 let label1 = _ ( 'Reference' ) ;
173181 if ( op === 'inrange' || op === 'exrange' ) {
0 commit comments