Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [DHIS2-18310] enable non-Gregorian calendars in views & lists & forms #3900

Open
wants to merge 35 commits into
base: master
Choose a base branch
from

Conversation

alaa-yahia
Copy link
Member

@alaa-yahia alaa-yahia commented Dec 5, 2024

Implements DHIS2-18310 & DHIS2-18311 & DHIS2-18309 & DHIS2-18868

  • Modified clientToList, clientToForm and clientToView converters to handle local format conversions (DHIS2-18310)
  • Modified FormToClient converter to handle ISO format (DHIS2-18309)
  • Ensure that all “Last updated” calculations are working when local calendar is used
  • Ensure all date pickers (form and working list) are using local calendar.
  • Enable non-Gregorian calendars in working list filters DHIS2-18311
  • Fix search for a trackedEntity by a DATETIME & AGE attributes DHIS2-18868

@alaa-yahia alaa-yahia requested a review from a team as a code owner December 5, 2024 00:21
@alaa-yahia alaa-yahia force-pushed the DHIS2-18310-enable-non-gregorian-calendars-in-views-and-lists branch from 8983fd7 to 0294f8d Compare December 5, 2024 11:00
@simonadomnisoru
Copy link
Contributor

Hi @alaa-yahia,
I noticed two issues with the Age field:

  1. When selecting a date from the calendar, the year, months, and days are filled with incorrect values. (i.e. In the video below, I selected today's date from the Ethiopian calendar, so the year, months, and day should have been filled with 0).
  2. When typing a value into the days field, the calendar is filled with the gregorian value of the date.
Screen.Recording.2024-12-12.at.16.51.40.mov

In the video above I used the Ethiopian calendar. Can you have a look? Thank you!

Copy link
Member

@JoakimSM JoakimSM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good start, but some things we will have to work a bit more on.

In addition to the individual comments we should convert the "last updated" tooltips from ISO to local calendar (I saw this in both the stages and events Widget and the enrollment Widget). Had a very quick look at the stages and events Widget and for now I think you can use something like moment(fromServerDate(updatedAt)).toISOString() and put the result into the clientToView converter of type DATETIME (we should probably also use the serverToClient converter, but this will be checked and resolved in separate ticket)

@alaa-yahia alaa-yahia force-pushed the DHIS2-18310-enable-non-gregorian-calendars-in-views-and-lists branch from da9bf63 to 013db2c Compare January 6, 2025 11:22
Copy link
Member

@JoakimSM JoakimSM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to other comments:

  • We should fix the logic in getDateRangeValidator and getDateTimeRangeValidator. These validators are being used in the search form when using tracked entity attributes of value type date and dateTime. We should replace the parseDate logic and leverage the validation done in the ui library component.
  • Don't use parseDate on local dates. I think this means that we should remove parseDate from the codebase in its entirety (I didn't see any valid reason to use it anymore, but let me know if I missed something)

src/core_modules/capture-ui/AgeField/AgeField.component.js Outdated Show resolved Hide resolved
src/core_modules/capture-ui/AgeField/AgeField.component.js Outdated Show resolved Hide resolved
src/core_modules/capture-core/converters/formToClient.js Outdated Show resolved Hide resolved
const parseData = dateValue && onParseDate(dateValue);

function getCalculatedValues(dateValue: ?string): AgeValues {
const parseData = dateValue && parseDate(dateValue);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't use the parseDate function as is because it is using moment internally (and we are passing in a date from a local calendar type). Let's use the following approach here:

  1. In handleDateBlur in this file, let's make sure we check the validation that is passed in from the component and only invoke getCalculatedVaules if the date is valid (currently, the app crashing sometimes with invalid dates). The validation executed in the component is the source of truth for whether the date is valid or not.
  2. Don't use parseDate here. After point .1, the value passed in to getCalculatedValues should always be valid and you should be able to use convertStringToTemporal directly.

In general, we should replace parseDate in our codebase if it is being used on dates of local calendar types.

Copy link
Contributor

@simonadomnisoru simonadomnisoru left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @alaa-yahia, I found a few bugs that I hope you can look into. I tested with the Ethiopian and Nepalese calendars. Thank you!

src/core_modules/capture-ui/AgeField/AgeField.component.js Outdated Show resolved Hide resolved
@@ -5,21 +5,20 @@ import i18n from '@dhis2/d2-i18n';
import { Tag } from '@dhis2/ui';
import { PreviewImage } from 'capture-ui';
import { dataElementTypes, type DataElement } from '../metaData';
import { convertMomentToDateFormatString } from '../utils/converters/date';
import { convertIsoToLocalCalendar } from '../utils/converters/date';
import { stringifyNumber } from './common/stringifyNumber';
import { MinimalCoordinates } from '../components/MinimalCoordinates';
import { TooltipOrgUnit } from '../components/Tooltips/TooltipOrgUnit';

function convertDateForListDisplay(rawValue: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the search page, the currentSearchTerms are not converted correctly. I think the problem arises when using the clientToList converter in the SearchResultsHeader.component. In the screenshot bellow, the label Birth date: 05-05-2017 -> 07-05-2017 should be displayed.

Screenshot 2025-01-14 at 10 12 47

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • DATE the issue is fixed now ✅
  • DATETIME I was unable to test because the search does not work for this attribute type. I created a separate bug ticket because this issue is occurring on master DHIS2-18868.
  • AGE the currentSearchTerms are not being converted correctly. Could you have a look at it?
Screenshot 2025-01-20 at 12 01 04

Copy link
Member Author

@alaa-yahia alaa-yahia Jan 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JoakimSM @simonadomnisoru Both AGE and DATETIME searches don't work in master. I can add a converter for AGE that returns the same value passed (as it is getting the local value instead of the ISO one), but it doesn't seem right. Also, DATE is receiving the client value, its converter is being used in working list filters, while DATE_RANGE is receiving the local value.

@alaa-yahia
Copy link
Member Author

@simonadomnisoru I've pushed bug fixes addressing your feedbacks. Could you take another look when you have a time?
Thank you

@@ -5,21 +5,20 @@ import i18n from '@dhis2/d2-i18n';
import { Tag } from '@dhis2/ui';
import { PreviewImage } from 'capture-ui';
import { dataElementTypes, type DataElement } from '../metaData';
import { convertMomentToDateFormatString } from '../utils/converters/date';
import { convertIsoToLocalCalendar } from '../utils/converters/date';
import { stringifyNumber } from './common/stringifyNumber';
import { MinimalCoordinates } from '../components/MinimalCoordinates';
import { TooltipOrgUnit } from '../components/Tooltips/TooltipOrgUnit';

function convertDateForListDisplay(rawValue: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • DATE the issue is fixed now ✅
  • DATETIME I was unable to test because the search does not work for this attribute type. I created a separate bug ticket because this issue is occurring on master DHIS2-18868.
  • AGE the currentSearchTerms are not being converted correctly. Could you have a look at it?
Screenshot 2025-01-20 at 12 01 04

Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
10 New issues
10 New Code Smells (required ≤ 0)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants