From 8983fd79aa05647b16f814fcbe895b60dcb72a90 Mon Sep 17 00:00:00 2001 From: alaa-yahia Date: Thu, 5 Dec 2024 01:36:14 +0200 Subject: [PATCH] fix: working list filters to use gregorian --- .../Date/DateFilter.component.js | 28 +++++++++++++++---- .../date/convertIsoToLocalCalendar.js | 2 +- .../date/convertLocalToIsoCalendar.js | 2 +- .../date/dateObjectToDateFormatString.js | 2 +- .../DateField/Date.component.js | 3 -- 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/src/core_modules/capture-core/components/FiltersForTypes/Date/DateFilter.component.js b/src/core_modules/capture-core/components/FiltersForTypes/Date/DateFilter.component.js index c326e4477b..5c995df0d1 100644 --- a/src/core_modules/capture-core/components/FiltersForTypes/Date/DateFilter.component.js +++ b/src/core_modules/capture-core/components/FiltersForTypes/Date/DateFilter.component.js @@ -1,6 +1,7 @@ // @flow import React, { Component } from 'react'; import classNames from 'classnames'; +import moment from 'moment'; import { withStyles } from '@material-ui/core/styles'; import i18n from '@dhis2/d2-i18n'; import { isValidZeroOrPositiveInteger } from 'capture-core-utils/validators/form'; @@ -16,7 +17,8 @@ import './calendarFilterStyles.css'; import { mainOptionKeys, mainOptionTranslatedTexts } from './options'; import { getDateFilterData } from './dateFilterDataGetter'; import { RangeFilter } from './RangeFilter.component'; -import { parseDate } from '../../../utils/converters/date'; +import { parseDate, convertLocalToIsoCalendar, convertIsoToLocalCalendar } from '../../../utils/converters/date'; +import { systemSettingsStore } from '../../../metaDataMemoryStores'; const getStyles = (theme: Theme) => ({ fromToContainer: { @@ -257,12 +259,28 @@ class DateFilterPlain extends Component implements UpdatableFilter return !values || DateFilter.isFilterValid(values.main, values.from, values.to, values.start, values.end); } - getUpdatedValue(valuePart: { [key: string]: string }) { - // $FlowFixMe[cannot-spread-indexer] automated comment + // eslint-disable-next-line complexity + getUpdatedValue(valuePart: Object) { const valueObject = { ...this.props.value, ...valuePart, }; + const dateFormat = systemSettingsStore.get().dateFormat; + + if (valuePart.from && valueObject?.from?.value) { + valueObject.from = { + ...valueObject.from, + value: moment(convertLocalToIsoCalendar(valueObject.from.value)).format(dateFormat), + }; + } + + if (valuePart.to && valueObject?.to?.value) { + valueObject.to = { + ...valueObject.to, + value: moment(convertLocalToIsoCalendar(valueObject.to.value)).format(dateFormat), + }; + } + const isRelativeRangeValue = () => valueObject?.start || valuePart?.start || valuePart?.end; const isAbsoluteRangevalue = () => valueObject?.from || valuePart?.from || valuePart?.to; @@ -358,7 +376,7 @@ class DateFilterPlain extends Component implements UpdatableFilter {/* $FlowSuppress: Flow not working 100% with HOCs */} {/* $FlowFixMe[prop-missing] automated comment */} implements UpdatableFilter {/* $FlowSuppress: Flow not working 100% with HOCs */} {/* $FlowFixMe[prop-missing] automated comment */} - (dateFormat === 'dd-MM-yyyy' ? date?.format('DD-MM-YYYY') : date?.format('YYYY-MM-DD')); - export class DateField extends React.Component { handleDateSelected: (value: {calendarDateString: string}) => void;