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

fix: handle options with non-unique codes across optionsets (DHIS2-15771) #426

Merged
merged 12 commits into from
Nov 23, 2023

Conversation

edoardo
Copy link
Member

@edoardo edoardo commented Sep 4, 2023

This requires a backend fix.

Fixes DHIS2-15771
Fixes DHIS2-16181

Requires DHIS2-15775


Key features

  1. lookup option set option labels correctly in the table rows
  2. show the correct name in the layout chip tooltips
  3. refactor how the metadata for option sets is stored in Redux

Description

Options for different option sets can use the same code, which is what is returned in the rows in the analytics response.
The previous way of looking up the label to display in the table simply tried to find a metadata object whom code matches the value for the option set in the response's rows.
This cause to display the wrong label when different option sets are displayed at the same time and happen to use the same code.

Refer to the screenshots below.
The 3 columns are 3 different option sets, but they all use the same code (1) for their option.
The first matching code found in metadata items (in the analytics response) was always used regardless of the option set.

The fix is to look in metadata first for the optionSet, and find the matching option by code within the listed options.
Then the option's id is used to lookup the option itself in metadata and from there the name is extracted and used in the table.

The same logic needs to be applied when looking up the name to display in the layout chip tooltip for dimensions with option set where there is a specific selection (not all values).

We also need to add the metadata for the options when loading a saved visualization.
The reason here is that the table might not have all the values there are selected for the option set, and in that case the metadata from the analytics response is partial.

While working on this I realised that we don't really need to store the metadata for the single options of an option set.
Since we need them in the options object in the option set metadata anyway for the lookup, we can have the name in there as well and skip one lookup.


TODO

  • Cypress tests
  • Update docs?
  • Manual testing

Known issues

  • a Cypress test in table.cy.js is now failing due to this change. This is not a regression, it should be working once the backend fix is available.

Screenshots

Table before:
Screenshot 2023-09-04 at 14 03 38

Table after:
Screenshot 2023-09-04 at 13 57 48

Tooltip before:
Notice the names for the selected options are wrong when a different dimension with option set has also a selection and the code used is the same:
Screenshot 2023-11-23 at 11 19 45

Screenshot 2023-11-23 at 11 19 51

In this example, this selection was made first:
Screenshot 2023-11-23 at 11 19 25

Tooltip after:
Notice the Pain medication dimension has 5 options selected, but the tooltip for pre-eclampsia is correct:
Screenshot 2023-11-23 at 11 23 08

@dhis2-bot
Copy link
Contributor

dhis2-bot commented Sep 6, 2023

🚀 Deployed on https://pr-426--dhis2-line-listing.netlify.app

@dhis2-bot dhis2-bot temporarily deployed to netlify September 6, 2023 14:44 Inactive
@cypress
Copy link

cypress bot commented Sep 6, 2023

Passing run #2004 ↗︎

0 499 0 0 Flakiness 0

Details:

Merge e32b1ac into 120910e...
Project: line-listing-app Commit: 3903e1245a ℹ️
Status: Passed Duration: 12:22 💡
Started: Nov 23, 2023 2:51 PM Ended: Nov 23, 2023 3:03 PM

Review all test suite changes for PR #426 ↗︎

@edoardo edoardo force-pushed the fix/option-set-labels-DHIS2-15771 branch from e4166aa to c49fb2e Compare September 11, 2023 11:37
@dhis2-bot dhis2-bot temporarily deployed to netlify September 11, 2023 11:40 Inactive
@edoardo edoardo added Analytics Team Testing Awaiting Core Release Should not be released / merged until a supported backend version has been released first labels Sep 15, 2023
@edoardo edoardo force-pushed the fix/option-set-labels-DHIS2-15771 branch from c49fb2e to 015d511 Compare September 26, 2023 08:19
@dhis2-bot dhis2-bot temporarily deployed to netlify September 26, 2023 08:22 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify September 26, 2023 14:25 Inactive
@martinkrulltott martinkrulltott self-requested a review October 9, 2023 08:24
@martinkrulltott martinkrulltott changed the title fix: lookup option set options labels correctly DHIS2-15771 fix: lookup option set options labels correctly (DHIS2-15771) Oct 9, 2023
@martinkrulltott martinkrulltott requested a review from a team as a code owner October 9, 2023 09:14
@dhis2-bot dhis2-bot temporarily deployed to netlify October 9, 2023 09:18 Inactive
Copy link
Contributor

@martinkrulltott martinkrulltott left a comment

Choose a reason for hiding this comment

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

findOptionSetItem could be written as a single line, but I see that splitting it up increases readability. However, I'd argue that some parts are a bit unnecessary/too explicit right now, which actually decreases readability.

src/components/Visualization/useAnalyticsData.js Outdated Show resolved Hide resolved
@martinkrulltott
Copy link
Contributor

Needs Cypress tests

@dhis2-bot dhis2-bot temporarily deployed to netlify October 9, 2023 10:05 Inactive
@edoardo
Copy link
Member Author

edoardo commented Oct 10, 2023

Needs Cypress tests

Added.

@dhis2-bot dhis2-bot temporarily deployed to netlify October 10, 2023 10:03 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify November 21, 2023 14:59 Inactive
@edoardo edoardo force-pushed the fix/option-set-labels-DHIS2-15771 branch from 5375f65 to de978ee Compare November 23, 2023 10:02
@dhis2-bot dhis2-bot temporarily deployed to netlify November 23, 2023 10:04 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify November 23, 2023 13:25 Inactive
@dhis2-bot dhis2-bot temporarily deployed to netlify November 23, 2023 14:47 Inactive
@janhenrikoverland janhenrikoverland changed the title fix: lookup option set options labels correctly (DHIS2-15771) fix: handle options with non-unique codes across optionsets (DHIS2-15771) Nov 23, 2023
@janhenrikoverland janhenrikoverland enabled auto-merge (squash) November 23, 2023 14:52
@janhenrikoverland janhenrikoverland merged commit 37e3e69 into master Nov 23, 2023
50 checks passed
@janhenrikoverland janhenrikoverland deleted the fix/option-set-labels-DHIS2-15771 branch November 23, 2023 15:09
dhis2-bot added a commit that referenced this pull request Nov 23, 2023
## [100.10.5](v100.10.4...v100.10.5) (2023-11-23)

### Bug Fixes

* handle options with non-unique codes across optionsets (DHIS2-15771) ([#426](#426)) ([37e3e69](37e3e69))
@dhis2-bot
Copy link
Contributor

🎉 This PR is included in version 100.10.5 🎉

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
Labels
Analytics Team Testing Awaiting Core Release Should not be released / merged until a supported backend version has been released first on hold released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants