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(#8225): fix handling of inputs group with contact selector #9382

Merged
merged 6 commits into from
Sep 10, 2024

Conversation

jkuester
Copy link
Contributor

@jkuester jkuester commented Aug 27, 2024

Description

Closes #8225

This PR updates our patch for the Eneketo relevant logic to make it so that the inputs group never can get set to non-relevant (and so calculations and widgets and things involving inputs all work as expected even when the inputs fields are not shown in the form).

Testing considerations

I have expanded our db-object widget e2e tests to cover using the widget to load contact data inside the inputs group. Also, the other existing tests all work as expected. The risk here is that the new Enekto patch somehow breaks Enekto code in other unexpected ways. I have done some manual testing to try to shake out any issues, but everything has worked as expected.

It would be good, though, to perhaps do more manual testing of any workflows that involve passing inputs data to forms (e.g. forms triggered from tasks).

Code review checklist

  • Readable: Concise, well named, follows the style guide, documented if necessary.
  • Tested: Unit and/or e2e where appropriate
  • Backwards compatible: Works with existing data and configuration or includes a migration. Any breaking changes documented in the release notes.

Compose URLs

If Build CI hasn't passed, these may 404:

License

The software is provided under AGPL-3.0. Contributions to this project are accepted under the same license.

@@ -247,7 +247,7 @@ describe('Contact Delivery Form', () => {
source_id: '',
user: {
contact_id: offlineUser.contact._id,
name: offlineUser.username,
name: offlineUser.contact.name,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change actually demonstrates this fix in action! The regression scenario from the forum was doing the exact same thing as the delivery form where they are trying to load the user's contact document directly into the inputs/user group. The complication is that the inputs/user group already contains data from the users user-settings doc. So, when you use the contact selector to load the user's contact into the same group, it will override the data that is already there.

In this case, both the user's contact and the user-settings document contain a name field. For the user-settings it is the username. For the contact, it is just the normal contact name value. Because the contact-selector functionality in non-relevant inputs was broken before this PR, the user's contact data was not actually being loaded and so the name was just populated with the username from the user-settings document. Now that this PR has fixed the contact selector functionality, we see inputs/user/name getting overridden with the value from the user's contact (which is the proper behavior that we expect).

Comment on lines 24 to 31
- if (
+ // CHT-CORE PATCH
+ // /inputs is ALWAYS relevant #4875
+ if(!result && /^\/[^/]+\/inputs$/.test(path)) {
+ branchChange = this.enable(branchNode, path, options) || branchChange;
+ branchNode.classList.add('disabled');
+ }
+ else if (
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous patch here was attempting a much more surgical modification where the inputs group would actually still get set to be non-relevant, but we would not clear the data in the inputs group (as a part of this logic. It would remain available to other expressions in the form. Unfortunately, the side effect of this was that if any of the data in the non-relevant inputs changed, that change did not get stored/propagated to other expressions since technically the fields that changed were non-relevant. So, when the db-object widget was triggered inside the non-relevant inputs group, it would load the data as expected, but it would not get saved into the form data model.

This new patch takes a more heavy handed approach where we actually just never let the inputs group get set to be non-relevant (by hijacking this logic flow). The hope is that this will let us avoid any other kinds of weird side effects at the data-model level (especially since Enekto has some additional logic that gets trippy when some fields have never been relevant). Basically this lets is side-step all of that and as far as the rest of the form is concerned the inputs group is always relevant. The downside is that when the inputs relevant expression evaluates to false, _we do not want the user to actually see the inputs fields in the form. So, that is why we still slap the disabled class onto the inputs group to make sure it is not shown in the form.

Copy link
Contributor

@latin-panda latin-panda left a comment

Choose a reason for hiding this comment

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

Thanks for the great level of details in the ticket and in here, it's super clear and informative ✨

tests/e2e/default/enketo/forms/db_object_form.xlsx Outdated Show resolved Hide resolved
@mrjones-plip
Copy link
Contributor

Given this has been approved - should we move this to full PR instead of a Draft?

@jkuester jkuester marked this pull request as ready for review August 29, 2024 20:04
@jkuester
Copy link
Contributor Author

@mrjones-plip Done!

Copy link
Contributor

@tatilepizs tatilepizs left a comment

Choose a reason for hiding this comment

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

Thank you for all the details @jkuester

I manually tested and created a pregnancy with danger signs that triggered (all as tasks):

  • Pregnancy danger sign follow-up
  • Health facility ANC reminder
  • Delivery
  • Postnatal danger sign follow-up - mother
  • Postnatal danger sign follow-up - baby

And everything worked as expected 🚀

@jkuester
Copy link
Contributor Author

jkuester commented Sep 5, 2024

@tatilepizs @latin-panda could you have one more look through this?

I ended up making a change to the patch (to always set branchChange = true; when inputs gets set to be non-relevant). This helped to fix some behavior issues I found with the following workflow:

  • Open form where inputs in relevant (and so the user can see questions in the inputs group.
  • Change a value in the form such that inputs is no longer relevant.
    • In this case, the user should no longer be able to see the questions in the inputs group.

With my original patch in this PR, those non-relevant inputs questions would still be visible in to the user. Now, with this change, the are hidden from view as expected. (But the values in the inputs group are still available to other expressions and will be saved in the report as expected.)

@jkuester
Copy link
Contributor Author

jkuester commented Sep 5, 2024

Test form file name changes coming soon! 😅 Forgot to post those changes before requesting a review!

Copy link
Contributor

@tatilepizs tatilepizs left a comment

Choose a reason for hiding this comment

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

🚀
Thanks!

Copy link
Contributor

@latin-panda latin-panda 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! Thanks Josh!

@jkuester jkuester changed the title fix(#8225): update Enketo relevant patch to prevent inputs from ever being non-relevant fix(#8225): fix handling of inputs group with contact selector Sep 10, 2024
@jkuester jkuester merged commit 9d1314a into master Sep 10, 2024
48 checks passed
@jkuester jkuester deleted the 8225_update_relevant_patch branch September 10, 2024 18:06
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.

Cannot use db-object-widget to load contact data in non-relevant inputs group
4 participants