Skip to content

Commit

Permalink
fix: working list filters to use gregorian
Browse files Browse the repository at this point in the history
  • Loading branch information
alaa-yahia committed Dec 5, 2024
1 parent e56436f commit 8983fd7
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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: {
Expand Down Expand Up @@ -257,12 +259,28 @@ class DateFilterPlain extends Component<Props, State> 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;

Expand Down Expand Up @@ -358,7 +376,7 @@ class DateFilterPlain extends Component<Props, State> implements UpdatableFilter
{/* $FlowSuppress: Flow not working 100% with HOCs */}
{/* $FlowFixMe[prop-missing] automated comment */}
<FromDateFilter
value={fromValue?.value}
value={convertIsoToLocalCalendar(fromValue?.value)}
onBlur={this.handleFieldBlur}
onEnterKey={this.handleEnterKeyInFrom}
onDateSelectedFromCalendar={this.handleDateSelectedFromCalendarInFrom}
Expand All @@ -371,7 +389,7 @@ class DateFilterPlain extends Component<Props, State> implements UpdatableFilter
{/* $FlowSuppress: Flow not working 100% with HOCs */}
{/* $FlowFixMe[prop-missing] automated comment */}
<ToDateFilter
value={toValue?.value}
value={convertIsoToLocalCalendar(toValue?.value)}
onBlur={this.handleFieldBlur}
textFieldRef={this.setToD2DateTextFieldInstance}
onFocusUpdateButton={onFocusUpdateButton}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { padWithZeros } from './padWithZeros';
* @returns {string}
*/

export function convertIsoToLocalCalendar(isoDate: string): string {
export function convertIsoToLocalCalendar(isoDate: ?string): string {
if (!isoDate) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { padWithZeros } from './padWithZeros';
* @param {string} localDate - date in local calendar format
* @returns {string}
*/
export function convertLocalToIsoCalendar(localDate: string): string {
export function convertLocalToIsoCalendar(localDate: ?string): string {
if (!localDate) {
return '';
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { convertIsoToLocalCalendar } from './convertIsoToLocalCalendar';
* @param {Date} dateValue: the date instance
* @returns {string}
*/
export function convertDateObjectToDateFormatString(dateValue: Date | moment$Moment) {
export function convertDateObjectToDateFormatString(dateValue: Date | moment$Moment) {
const momentDate = moment(dateValue);
const dateString = momentDate.format('YYYY-MM-DD');
return convertIsoToLocalCalendar(dateString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ type State = {
calendarError: ?Validation,
};

const formatDate = (date: any, dateFormat: string): ?string =>
(dateFormat === 'dd-MM-yyyy' ? date?.format('DD-MM-YYYY') : date?.format('YYYY-MM-DD'));

export class DateField extends React.Component<Props, State> {
handleDateSelected: (value: {calendarDateString: string}) => void;

Expand Down

0 comments on commit 8983fd7

Please sign in to comment.