@@ -11,7 +11,7 @@ import DateTimeEntry from 'components/DateTimeEntry/DateTimeEntry.react';
11
11
import Icon from 'components/Icon/Icon.react' ;
12
12
import Parse from 'parse' ;
13
13
import PropTypes from 'lib/PropTypes' ;
14
- import React from 'react' ;
14
+ import React , { useCallback } from 'react' ;
15
15
import styles from 'components/BrowserFilter/BrowserFilter.scss' ;
16
16
import validateNumeric from 'lib/validateNumeric' ;
17
17
@@ -20,13 +20,7 @@ for (let c in Constraints) {
20
20
constraintLookup [ Constraints [ c ] . name ] = c ;
21
21
}
22
22
23
- let setFocus = ( input ) => {
24
- if ( input !== null ) {
25
- input . focus ( ) ;
26
- }
27
- }
28
-
29
- function compareValue ( info , value , onChangeCompareTo , onKeyDown , active , parentContentId ) {
23
+ function compareValue ( info , value , onChangeCompareTo , onKeyDown , active , parentContentId , setFocus ) {
30
24
switch ( info . type ) {
31
25
case null :
32
26
return null ;
@@ -91,25 +85,35 @@ let FilterRow = ({
91
85
onDeleteRow,
92
86
active,
93
87
parentContentId,
94
- } ) => (
95
- < div className = { styles . row } >
96
- < ChromeDropdown
97
- color = { active ? 'blue' : 'purple' }
98
- value = { currentField }
99
- options = { fields }
100
- onChange = { onChangeField } />
101
- < ChromeDropdown
102
- width = { compareInfo . type ? '175' : '325' }
103
- color = { active ? 'blue' : 'purple' }
104
- value = { Constraints [ currentConstraint ] . name }
105
- options = { constraints . map ( ( c ) => Constraints [ c ] . name ) }
106
- onChange = { ( c ) => onChangeConstraint ( constraintLookup [ c ] , compareTo ) } />
107
- { compareValue ( compareInfo , compareTo , onChangeCompareTo , onKeyDown , active , parentContentId ) }
108
- < button type = 'button' className = { styles . remove } onClick = { onDeleteRow } > < Icon name = 'minus-solid' width = { 14 } height = { 14 } fill = 'rgba(0,0,0,0.4)' /> </ button >
109
- </ div >
110
- ) ;
88
+ editMode
89
+ } ) => {
90
+
91
+ let setFocus = useCallback ( ( input ) => {
92
+ if ( input !== null && editMode ) {
93
+ input . focus ( ) ;
94
+ }
95
+ } , [ ] )
96
+
97
+ return (
98
+ < div className = { styles . row } >
99
+ < ChromeDropdown
100
+ color = { active ? 'blue' : 'purple' }
101
+ value = { currentField }
102
+ options = { fields }
103
+ onChange = { onChangeField } />
104
+ < ChromeDropdown
105
+ width = { compareInfo . type ? '175' : '325' }
106
+ color = { active ? 'blue' : 'purple' }
107
+ value = { Constraints [ currentConstraint ] . name }
108
+ options = { constraints . map ( ( c ) => Constraints [ c ] . name ) }
109
+ onChange = { ( c ) => onChangeConstraint ( constraintLookup [ c ] , compareTo ) } />
110
+ { compareValue ( compareInfo , compareTo , onChangeCompareTo , onKeyDown , active , parentContentId , setFocus ) }
111
+ < button type = 'button' className = { styles . remove } onClick = { onDeleteRow } > < Icon name = 'minus-solid' width = { 14 } height = { 14 } fill = 'rgba(0,0,0,0.4)' /> </ button >
112
+ </ div >
113
+ ) ;
114
+ }
111
115
112
- export default FilterRow ;
116
+ export default React . memo ( FilterRow ) ;
113
117
114
118
FilterRow . propTypes = {
115
119
fields : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
0 commit comments