From ad2ff6f122f24f552f298e98c78f084dc809fb68 Mon Sep 17 00:00:00 2001 From: mahmoudadel54 Date: Thu, 18 Jan 2024 18:29:18 +0200 Subject: [PATCH] #9706: resolve reviewer comments Description: - Add placeholder for time picker - Add translations for the added time placeholder - Fix crash app bug due to entering invalid date in input texts of date/time Pickers --- .../filterRenderers/DateTimeFilter.jsx | 10 +++++- .../misc/datetimepicker/DateTimePicker.js | 31 ++++++++++++------- .../datetimepicker/RangedDateTimePicker.js | 14 ++++++--- web/client/translations/data.de-DE.json | 4 +++ web/client/translations/data.en-US.json | 4 +++ web/client/translations/data.es-ES.json | 4 +++ web/client/translations/data.fr-FR.json | 4 +++ web/client/translations/data.it-IT.json | 4 +++ 8 files changed, 58 insertions(+), 17 deletions(-) diff --git a/web/client/components/data/featuregrid/filterRenderers/DateTimeFilter.jsx b/web/client/components/data/featuregrid/filterRenderers/DateTimeFilter.jsx index 1da95d6a54..591245f0f7 100644 --- a/web/client/components/data/featuregrid/filterRenderers/DateTimeFilter.jsx +++ b/web/client/components/data/featuregrid/filterRenderers/DateTimeFilter.jsx @@ -33,7 +33,7 @@ export default compose( type: props.type, attribute }); - } else { + } else if (value && typeof value === 'object') { props.onValueChange(value); props.onChange({ value: { startDate: value?.startDate, endDate: value?.endDate, operator: inputOperator }, @@ -41,6 +41,14 @@ export default compose( type: props.type, attribute }); + } else if (!value) { + props.onValueChange(value); + props.onChange({ + value: { startDate: value, operator: inputOperator }, + operator: inputOperator, + type: props.type, + attribute + }); } } }), diff --git a/web/client/components/misc/datetimepicker/DateTimePicker.js b/web/client/components/misc/datetimepicker/DateTimePicker.js index 301b0c2add..d3db4eae61 100644 --- a/web/client/components/misc/datetimepicker/DateTimePicker.js +++ b/web/client/components/misc/datetimepicker/DateTimePicker.js @@ -17,6 +17,7 @@ import { isDate, isNil, omit } from 'lodash'; import OverlayTrigger from '../OverlayTrigger'; import Hours from './Hours'; import Popover from '../../styleeditor/Popover'; +import {getMessageById} from '../../../utils/LocaleUtils'; localizer(moment); @@ -70,7 +71,10 @@ class DateTimePicker extends Component { options: PropTypes.object, isWithinAttrTbl: PropTypes.bool } - + static contextTypes = { + messages: PropTypes.object, + locale: PropTypes.string + }; static defaultProps = { placeholder: 'Type date...', calendar: true, @@ -98,7 +102,7 @@ class DateTimePicker extends Component { if (prevProps.value !== this.props.value || prevProps.operator !== this.props.operator) { const { value, operator } = this.props; this.setDateFromValueProp(value, operator); - if (this.props.operator === 'isNull') this.setState({ inputValue: '' }); + if (this.props.operator === 'isNull') this.setState({ inputValue: '', date: null }); } } @@ -109,14 +113,15 @@ class DateTimePicker extends Component { } renderCustomDateTimePopup = () => { const { inputValue, operator, open } = this.state; - const { placeholder, tabIndex, type } = this.props; + const { tabIndex, type } = this.props; const timeVisible = open === 'time'; const props = omit(this.props, ['placeholder', 'calendar', 'time', 'onChange', 'value']); - let calendarVal; + let calendarVal = null; if ( this.props.value && typeof this.props.value === 'object') { - calendarVal = this.props.value?.startDate || this.props.value; + calendarVal = this.props.value?.startDate; } else if (this.props.value && typeof this.props.value === 'string') calendarVal = this.props.value; + let timePlaceholderMsgId = getMessageById(this.context.messages, "featuregrid.attributeFilter.placeholders.time"); return (
@@ -132,7 +137,7 @@ class DateTimePicker extends Component { />
- {this.renderInput(inputValue, operator, '', placeholder, tabIndex, false, true, {width: '90%'})} + {this.renderInput(inputValue, operator, '', timePlaceholderMsgId, tabIndex, false, true, {width: '90%'})}