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: [DHIS-11419] display assigned users on events in enrollment overview page #3453

Merged
merged 11 commits into from
Dec 18, 2023

Conversation

superskip
Copy link
Contributor

Jira issue description:

Stages and events Widget: If the option "Allow user assignment of events" is set for the program stage we should display the assignee in the table.

The program Malaria focus registration can be used for testing.

@superskip superskip requested a review from a team as a code owner October 30, 2023 15:12
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.

LGTM! 👏

@@ -92,7 +92,7 @@ const valueConvertersForType = {
[dataElementTypes.FILE_RESOURCE]: convertResourceForDisplay,
[dataElementTypes.IMAGE]: convertResourceForDisplay,
[dataElementTypes.ORGANISATION_UNIT]: (rawValue: Object) => rawValue.name,
[dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name} (${rawValue.username})`,
[dataElementTypes.ASSIGNEE]: (rawValue: Object) => `${rawValue.name || rawValue.displayName} (${rawValue.username})`,
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT: There is an edge case where displayName is undefined. To reproduce, create a new enrollment event, you will be redirected to the enrollment overview and the undefined (undefined) text will appear in the program stage table. You must refresh the page to see the correct value of displayName.

Screenshot 2023-11-01 at 15 58 47

This happens because only the uid property is stored in Redux (within enrollmentDomain) when the event is created. The solution is quite straightforward and I already needed to fix it in one of the other related tickets in the epic DHIS2-15480.

Thanks!

Copy link
Contributor Author

@superskip superskip Nov 2, 2023

Choose a reason for hiding this comment

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

Thanks @simonadomnisoru! Implemented the fix so that it won't come up as an issue during testing. I tried undoing the change I did on this line, but that didn't work. Seems like removing rawValue.name works, though. But it also seems like a risky thing to do. Do you think it would break something?

Copy link
Contributor

@simonadomnisoru simonadomnisoru Nov 3, 2023

Choose a reason for hiding this comment

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

To undo the change, you can add a converter for dataElementTypes.ASSIGNEE inside serverToClient. Something like this should work:

    [dataElementTypes.ASSIGNEE]: (serverValue: ApiAssignedUser) => ({
        id: serverValue.uid,
        name: serverValue.displayName,
        username: serverValue.username,
        firstName: serverValue.firstName,
        surname: serverValue.surname,
    }),

This ensures that when the assignedUser value reaches the clientToList converter, it is in the correct format. Thanks!

Copy link

github-actions bot commented Nov 10, 2023

@superskip superskip added testing and removed testing labels Nov 13, 2023
@@ -8,7 +8,7 @@ const query = {
id: ({ id }) => id,
params: {
fields:
['programStages[id,repeatable,hideDueDate,programStageDataElements[displayInReports,dataElement[id,valueType,displayName,displayFormName,optionSet[options[code,name]]]'],
['programStages[id,repeatable,hideDueDate,enableUserAssignment,programStageDataElements[displayInReports,dataElement[id,valueType,displayName,displayFormName,optionSet[options[code,name]]]'],
Copy link
Member

Choose a reason for hiding this comment

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

Do you know the reason why useProgramMetadata is retrieving data from the api instead of using the IndexedDB cache? If not, can you change it to use useIndexedDBQuery?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, but it could perhaps be related to translations, i.e. displayName needs to come from the server?

Copy link
Member

Choose a reason for hiding this comment

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

We have a ticket to fix the displayName cache problem. Great if you change this one to use useIndexedDBQuery

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@JoakimSM programStageDataElements in IndexedDB doesn't contain the dataelement subvalues like valueType and optionSet. Do you think we can solve that with local data as well?

Copy link
Member

Choose a reason for hiding this comment

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

If I understand you correctly, there is a separate store/table for data elements. Should be retrieved from there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the metadata source in this case from the server to IndexedDB. The code got rather complicated the way I did it though. Got any suggestions for making it less complicated?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think it looks too bad. But, what is the advantage of using your custom useQueryStyleEvaluation instead of useIndexedDBQuery like we do in useProgramFromIndexedDB?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's just how the caching is done. I think useIndexedDBQuery generally uses time to determine when to clear out a cache entry, which in this case doesn't feel very natural to me. useQueryStyleEvaluation does the caching like useMemo would.

Copy link
Member

Choose a reason for hiding this comment

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

It would be beneficial to have one approach for this and currently that is useIndexedDBQuery. If we don't like the approach there, we can look into what we don't like and change it for all queries to IndexedDB. But let's start by using useIndexedDBQuery.

@superskip superskip requested a review from JoakimSM November 24, 2023 16:11
@superskip superskip removed the testing label Dec 15, 2023
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.

Looks good @superskip! 🎉

Copy link

@geethaalwan geethaalwan left a comment

Choose a reason for hiding this comment

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

Tested successfully on 2.41,2.40.3,2.39.5,2.38.6 versions

@superskip superskip merged commit 44fb2be into master Dec 18, 2023
37 checks passed
@superskip superskip deleted the DHIS2-11419 branch December 18, 2023 14:22
dhis2-bot added a commit that referenced this pull request Dec 18, 2023
# [100.50.0](v100.49.0...v100.50.0) (2023-12-18)

### Features

* [DHIS-11419] display assigned users on events in enrollment overview page ([#3453](#3453)) ([44fb2be](44fb2be))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 100.50.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.

5 participants