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: add support for multi calendar dates #385

Merged
merged 2 commits into from
Jul 29, 2024

Conversation

d-rita
Copy link
Contributor

@d-rita d-rita commented Jun 6, 2024

Fixes DHIS2-17446


Description:

  • Using the Calendar Input component from the UI library that has support for multi calendars.

Tasks

  • Create new date input component using CalendarInput
  • Set calendar and user locale based on system and user settings

Screenshot

  1. iso8601
gregorian

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Jun 6, 2024

🚀 Deployed on https://pr-385--dhis2-data-entry.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify June 6, 2024 16:02 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify June 7, 2024 11:46 Inactive
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from 025fd7f to 2033e7d Compare June 7, 2024 11:56
@dhis2-bot dhis2-bot temporarily deployed to netlify June 7, 2024 11:57 Inactive
@d-rita d-rita self-assigned this Jun 11, 2024
@dhis2-bot dhis2-bot temporarily deployed to netlify June 11, 2024 11:33 Inactive
@d-rita d-rita requested review from kabaros and KaiVandivier June 11, 2024 11:34
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from e069847 to e966d20 Compare June 11, 2024 11:42
@dhis2-bot dhis2-bot temporarily deployed to netlify June 11, 2024 11:44 Inactive
@tomzemp tomzemp requested review from a team and tomzemp and removed request for kabaros and KaiVandivier June 18, 2024 10:13
Copy link
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

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

Looking good! 😎. Some things I noticed below:

Persistence
I am seeing that the date does not persist consistently to the backend (see gif). I assume there's some kind of race condition between the input.onChange completing and the handleBlur being called.

de_dates

I think it would be better if we just posted to the backend (and updated the input value) on the CalendarInput's onDateSelect. We have the update onBlur in the general input cells because we want to be sure that people's changes are final before we commit them, but I think we can judge that the changes are "final" once a date is selected here (this by the way, is consistent with the boolean-radio component). Doing to update onDateSelect should simplify this as we can just pass the date value to both the mutation and the input's onChange method.

Focus

The CalendarInput component has its own onFocus definition (https://github.com/dhis2/ui/blob/master/components/calendar/src/calendar-input/calendar-input.js#L65-L67)m so the one you're passing here isn't having an effect. As a result, the cell does not come into focus and hence you cannot get the details for this cell / the styling for active cell is not applied.

You could put the focus logic on a parent div here to solve this issue (see also the boolean-radio component for an idea).

data: {
settings: { keyUiLocale },
},
} = useUserInfo()
Copy link
Member

Choose a reason for hiding this comment

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

I feel like it might be good to have some protection against the situation where things like this are undefined (e.g. `const {data: userInfo} = useUserInfo(); const keyUiLocale = userInfo?.settings?.keyUiLocale), but this seems to be consistent with how we've done it elsewhere in the app, so I guess we're generally choosing to trust that the backend will reply consistently.


afterEach(jest.clearAllMocks)

it('renders date input component', async () => {
Copy link
Member

Choose a reason for hiding this comment

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

Great with the test 🎉

It might be nice to have a test that checks that mutation (mocked) fires with correct date value when you select date / clear date. That might be a bit tricky to implement, but I guess that would also help with some of the logic for testing the other calendars. Could be good to add a separate ticket for adding tests if you think it's too much for the first implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a few test cases that show the mutate function being called with the correct date value on dateSelect and an empty string on clear. Doing this for gregorian, nepali and ethiopian calendars

- use UI library's CalendarInput component for date type form inputs
- specify calendar type from system settings
- add tests
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from e966d20 to a9a65e9 Compare July 11, 2024 23:46
@dhis2-bot dhis2-bot temporarily deployed to netlify July 11, 2024 23:48 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify July 25, 2024 04:50 Inactive
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from bc1ae7f to a028f75 Compare July 25, 2024 04:51
@dhis2-bot dhis2-bot temporarily deployed to netlify July 25, 2024 04:52 Inactive
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from a028f75 to 5a4a7fc Compare July 25, 2024 21:02
@dhis2-bot dhis2-bot temporarily deployed to netlify July 25, 2024 21:03 Inactive
@d-rita d-rita force-pushed the DHIS2-17446/support-multi-calendar-dates branch from 5a4a7fc to ad759a3 Compare July 25, 2024 21:06
@dhis2-bot dhis2-bot temporarily deployed to netlify July 25, 2024 21:08 Inactive
@d-rita d-rita requested a review from tomzemp July 25, 2024 21:17
Copy link
Member

@tomzemp tomzemp left a comment

Choose a reason for hiding this comment

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

Nice! Looks great 🤩

Will also be good to update again when the improvements are made on the CalendarInput component so that we don't get the [object Object] if a user types something in the field. But I think it makes sense to merge this PR now and then just update the ui dependency later.

@d-rita
Copy link
Contributor Author

d-rita commented Jul 29, 2024

Awesome! Thanks for the review.

Will also be good to update again when the improvements are made on the CalendarInput component so that we don't get the [object Object] if a user types something in the field

I will work on this once the editable calendar input PR is merged.

@d-rita d-rita merged commit 55dbcd8 into master Jul 29, 2024
15 checks passed
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 100.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants