From b96b48fdd5ce452783e0887c36231971a1822173 Mon Sep 17 00:00:00 2001 From: Ashish Baravaliya <49753983+AshishBarvaliya@users.noreply.github.com> Date: Sat, 27 May 2023 07:39:29 -0400 Subject: [PATCH] fix: Incorrect date picker position in data browser filter dialog (#2425) --- .../BrowserFilter/BrowserFilter.react.js | 9 ++- .../BrowserFilter/FilterRow.react.js | 56 ++++++++++--------- 2 files changed, 36 insertions(+), 29 deletions(-) diff --git a/src/components/BrowserFilter/BrowserFilter.react.js b/src/components/BrowserFilter/BrowserFilter.react.js index 17de624df6..20446a3654 100644 --- a/src/components/BrowserFilter/BrowserFilter.react.js +++ b/src/components/BrowserFilter/BrowserFilter.react.js @@ -24,6 +24,7 @@ export default class BrowserFilter extends React.Component { this.state = { open: false, + editMode: true, filters: new List(), blacklistedFilters: Filters.BLACKLISTED_FILTERS.concat(props.blacklistedFilters) }; @@ -48,7 +49,8 @@ export default class BrowserFilter extends React.Component { } this.setState(prevState => ({ open: !prevState.open, - filters: filters + filters: filters, + editMode: this.props.filters.size === 0 })); this.props.setCurrent(null); } @@ -59,7 +61,8 @@ export default class BrowserFilter extends React.Component { this.setState(({ filters }) => ({ filters: filters.push( new Map({ field: field, constraint: available[field][0] }) - ) + ), + editMode: true })); } @@ -116,7 +119,7 @@ export default class BrowserFilter extends React.Component { onChange={filters => this.setState({ filters: filters })} onSearch={this.apply.bind(this)} renderRow={props => ( - 0} parentContentId={POPOVER_CONTENT_ID} /> + 0} editMode={this.state.editMode} parentContentId={POPOVER_CONTENT_ID} /> )} />
diff --git a/src/components/BrowserFilter/FilterRow.react.js b/src/components/BrowserFilter/FilterRow.react.js index 80cf0e0ba3..cf8cc5a90d 100644 --- a/src/components/BrowserFilter/FilterRow.react.js +++ b/src/components/BrowserFilter/FilterRow.react.js @@ -11,7 +11,7 @@ import DateTimeEntry from 'components/DateTimeEntry/DateTimeEntry.react'; import Icon from 'components/Icon/Icon.react'; import Parse from 'parse'; import PropTypes from 'lib/PropTypes'; -import React from 'react'; +import React, { useCallback } from 'react'; import styles from 'components/BrowserFilter/BrowserFilter.scss'; import validateNumeric from 'lib/validateNumeric'; @@ -20,13 +20,7 @@ for (let c in Constraints) { constraintLookup[Constraints[c].name] = c; } -let setFocus = (input) => { - if (input !== null) { - input.focus(); - } -} - -function compareValue(info, value, onChangeCompareTo, onKeyDown, active, parentContentId) { +function compareValue(info, value, onChangeCompareTo, onKeyDown, active, parentContentId, setFocus) { switch (info.type) { case null: return null; @@ -91,25 +85,35 @@ let FilterRow = ({ onDeleteRow, active, parentContentId, - }) => ( -
- - Constraints[c].name)} - onChange={(c) => onChangeConstraint(constraintLookup[c], compareTo)} /> - {compareValue(compareInfo, compareTo, onChangeCompareTo, onKeyDown, active, parentContentId)} - -
-); + editMode + }) => { + + let setFocus = useCallback((input) => { + if (input !== null && editMode) { + input.focus(); + } + }, []) + + return ( +
+ + Constraints[c].name)} + onChange={(c) => onChangeConstraint(constraintLookup[c], compareTo)} /> + {compareValue(compareInfo, compareTo, onChangeCompareTo, onKeyDown, active, parentContentId, setFocus)} + +
+ ); +} -export default FilterRow; +export default React.memo(FilterRow); FilterRow.propTypes = { fields: PropTypes.arrayOf(PropTypes.string).isRequired,