@@ -11,7 +11,7 @@ import DateTimeEntry from 'components/DateTimeEntry/DateTimeEntry.react';
1111import Icon from 'components/Icon/Icon.react' ;
1212import Parse from 'parse' ;
1313import PropTypes from 'lib/PropTypes' ;
14- import React from 'react' ;
14+ import React , { useCallback } from 'react' ;
1515import styles from 'components/BrowserFilter/BrowserFilter.scss' ;
1616import validateNumeric from 'lib/validateNumeric' ;
1717
@@ -20,13 +20,7 @@ for (let c in Constraints) {
2020 constraintLookup [ Constraints [ c ] . name ] = c ;
2121}
2222
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 ) {
3024 switch ( info . type ) {
3125 case null :
3226 return null ;
@@ -91,25 +85,35 @@ let FilterRow = ({
9185 onDeleteRow,
9286 active,
9387 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+ }
111115
112- export default FilterRow ;
116+ export default React . memo ( FilterRow ) ;
113117
114118FilterRow . propTypes = {
115119 fields : PropTypes . arrayOf ( PropTypes . string ) . isRequired ,
0 commit comments