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) O3-4424: Fix Context Provider State Merge for Obs Group Questions #387

Closed
wants to merge 1 commit into from

Conversation

Bharath-K-Shetty
Copy link
Contributor

@Bharath-K-Shetty Bharath-K-Shetty commented Feb 3, 2025

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

This PR addresses an issue with editing obs group questions where changes to the Unique ID and Question Type fields were not persisting. The problem was traced to the context provider, which did not merge updates properly into both the top-level form field state and its nested questions array.

In this update, the FormFieldContext provider is modified so that when a subquestion is updated, its changes are merged into the main form field as well as into the corresponding entry in the questions array. This ensures that users can successfully edit the Unique ID and Question Type fields without the input resetting or only accepting a single character.

Screenshots

Before

Screen.Recording.2025-02-02.165111.mp4

After

After.mp4

Related Issue

https://openmrs.atlassian.net/browse/O3-4424

Other

@Bharath-K-Shetty
Copy link
Contributor Author

@NethmiRodrigo review needed..!

@NethmiRodrigo NethmiRodrigo self-requested a review February 3, 2025 16:26
Copy link
Collaborator

@NethmiRodrigo NethmiRodrigo left a comment

Choose a reason for hiding this comment

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

@Bharath-K-Shetty Thanks for the attempt! Unfortunately, this doesn't resolve the core issue.

The main problem is that the context providers are nested inside the QuestionModal. My initial mistake was assuming that the nested provider would have access to the entire formField object, but in reality, it only receives the specific child question it is relevant to.

For example, given this formField structure:

const formField = {
  id: 'id',
  questions: [{ id: 'child question' }]
};

Currently, the child question's context only receives formField.questions[0], meaning it lacks access to the full formField object. However, when the child question is updated, we need to ensure that the parent context’s state is also updated accordingly with the child being updated in the parent state's correct element in the questions array. Basically, we need to push the updates to the parent context. If you test out your code and check the JSON schema, you'll see that the questions array will always be empty values :
{ "type": "obsGroup", "questionOptions": { "rendering": "group" }, "id": "contactedSuccessfully", "label": "Contacted Successfully", "questions": [ { "type": "", "id": "" } ], "required": true }

@NethmiRodrigo NethmiRodrigo changed the title (fix)O3-4424:Fix Context Provider State Merge for Obs Group Questions (fix) O3-4424: Fix Context Provider State Merge for Obs Group Questions Feb 3, 2025
@UNCANNY69
Copy link
Contributor

@Bharath-K-Shetty Thanks for the attempt! Unfortunately, this doesn't resolve the core issue.

The main problem is that the context providers are nested inside the QuestionModal. My initial mistake was assuming that the nested provider would have access to the entire formField object, but in reality, it only receives the specific child question it is relevant to.

For example, given this formField structure:

const formField = {
  id: 'id',
  questions: [{ id: 'child question' }]
};

Currently, the child question's context only receives formField.questions[0], meaning it lacks access to the full formField object. However, when the child question is updated, we need to ensure that the parent context’s state is also updated accordingly with the child being updated in the parent state's correct element in the questions array. Basically, we need to push the updates to the parent context. If you test out your code and check the JSON schema, you'll see that the questions array will always be empty values : { "type": "obsGroup", "questionOptions": { "rendering": "group" }, "id": "contactedSuccessfully", "label": "Contacted Successfully", "questions": [ { "type": "", "id": "" } ], "required": true }

Fixed the addressed issue here

O3-4424: Fixing the missing context questions in the obsGrouped type by UNCANNY69 · Pull Request #388 · openmrs/openmrs-esm-form-builder

@Bharath-K-Shetty Bharath-K-Shetty deleted the fix/O3-4424 branch February 4, 2025 10:52
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