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) Propagate Form Context State Changes to the Form Factory Provider #402

Merged
merged 1 commit into from
Sep 26, 2024

Conversation

samuelmale
Copy link
Member

@samuelmale samuelmale commented Sep 25, 2024

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

During initialization, the form renderer registers the associated form context with the form-factory provider, which can be either a root form or a subform. This context is stored as an object reference in memory. As the user interacts with the form, the context undergoes mutations as a side-effect. In most cases, these mutations do not cause issues because they occur at deeper levels within the object tree, and most state updates perform shallow clones. However, problems arise when state mutations happen at higher levels, such as with the formFields state.

This has caused to a bug with repeating fields, where newly cloned fields do not exist in the factory provider during submission.


This fix ensures that state updates are properly propagated, addressing the issue and maintaining consistency across the form context.

Screenshots

N/A

Related Issue

N/A

Other

@samuelmale
Copy link
Member Author

@CynthiaKamau this fixes the issue you reported earlier today about test orders.

Copy link

Size Change: -4 B (0%)

Total Size: 1.15 MB

ℹ️ View Unchanged
Filename Size Change
dist/151.js 300 kB 0 B
dist/225.js 2.57 kB 0 B
dist/277.js 1.84 kB 0 B
dist/300.js 642 B 0 B
dist/335.js 968 B 0 B
dist/353.js 3.02 kB 0 B
dist/41.js 3.37 kB 0 B
dist/422.js 6.8 kB 0 B
dist/501.js 108 kB 0 B
dist/540.js 2.63 kB 0 B
dist/55.js 758 B 0 B
dist/572.js 252 kB -4 B (0%)
dist/617.js 86.9 kB 0 B
dist/635.js 14.3 kB 0 B
dist/70.js 483 B 0 B
dist/901.js 11.8 kB 0 B
dist/99.js 691 B 0 B
dist/993.js 3.09 kB 0 B
dist/main.js 342 kB 0 B
dist/openmrs-esm-form-engine-lib.js 3.67 kB 0 B

compressed-size-action

@CynthiaKamau CynthiaKamau merged commit d1a9a16 into main Sep 26, 2024
4 checks passed
@CynthiaKamau CynthiaKamau deleted the fix/form-context-update-propagation branch September 26, 2024 06:28
Copy link
Member

@pirupius pirupius left a comment

Choose a reason for hiding this comment

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

@samuelmale does this change fix propagating the changes downstream as well? from the section level to the question level? for example the issue with readonly in section level not propagating to the form fields?

Or was the main focus of this for subforms?

@CynthiaKamau
Copy link
Contributor

@samuelmale , try testing this out on edit mode , it looks like the field values are not populated

@samuelmale
Copy link
Member Author

samuelmale commented Sep 26, 2024

does this change fix propagating the changes downstream as well?

No, it's not related to that.

try testing this out on edit mode , it looks like the field values are not populated

I just tested it out and it works as expected for me. @CynthiaKamau Can you provide more details?

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