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

(refactor) Refactor usePatientPrograms hook to use SWR #447

Merged
merged 1 commit into from
Dec 18, 2024

Conversation

denniskigen
Copy link
Member

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

Refactors the usePatientProgram hook to leverage an SWR hook for fetching patient programs. With this, we get:

  • Automatic caching and revalidation
  • Conditional fetching based on the patientUuid and the formJson.meta.programs.hasProgramFields property of the form
  • Built-in error and loading states
  • Better handling of race conditions

Screenshots

Related Issue

Other

What's a good test plan for this, @samuelmale? I've tweaked @CynthiaKamau's sample schema from this PR and amended to include a truthy meta.programs.hasProgramFields value to get the hook to run. I get active enrollments back as evidenced by the console.log in this screenshot:

CleanShot 2024-12-11 at 2  09 01@2x

Is there a more thorough way to test this?

@denniskigen denniskigen force-pushed the refactor/use-patient-programs-hook branch from c255b13 to e9e89b7 Compare December 11, 2024 11:21
Copy link

github-actions bot commented Dec 11, 2024

Size Change: -200 kB (-13.64%) 👏

Total Size: 1.27 MB

Filename Size Change
dist/277.js 11.9 kB +10 kB (+542.85%) 🆘
dist/289.js 0 B -88.9 kB (removed) 🏆
dist/585.js 0 B -112 kB (removed) 🏆
dist/690.js 0 B -11.5 kB (removed) 🏆
ℹ️ View Unchanged
Filename Size Change
dist/151.js 382 kB 0 B
dist/219.js 264 kB +46 B (+0.02%)
dist/225.js 2.58 kB +4 B (+0.16%)
dist/260.js 114 kB 0 B
dist/300.js 645 B 0 B
dist/335.js 968 B 0 B
dist/353.js 3.02 kB 0 B
dist/41.js 3.37 kB +3 B (+0.09%)
dist/422.js 3.05 kB 0 B
dist/499.js 2.51 kB 0 B
dist/540.js 2.63 kB 0 B
dist/55.js 758 B 0 B
dist/606.js 2.24 kB 0 B
dist/635.js 14.4 kB 0 B
dist/658.js 1.85 kB 0 B
dist/70.js 0 B -483 B (removed) 🏆
dist/876.js 86.7 kB 0 B
dist/979.js 6.87 kB 0 B
dist/99.js 691 B 0 B
dist/993.js 3.09 kB 0 B
dist/main.js 357 kB +2.25 kB (+0.63%)
dist/openmrs-esm-form-engine-lib.js 3.8 kB +1 B (+0.03%)

compressed-size-action

Refactors the usePatientProgram hook to leverage an SWR hook for fetching patient programs. With this, we get:

- Automatic caching and revalidation
- Conditional fetching based on the patientUuid and the `formJson.meta.programs.hasProgramFields` property of the form
- Built-in error and loading states
- Better handling of race conditions
@denniskigen denniskigen force-pushed the refactor/use-patient-programs-hook branch from e9e89b7 to b020b22 Compare December 11, 2024 17:51
Copy link
Member

@samuelmale samuelmale left a comment

Choose a reason for hiding this comment

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

Nice one @denniskigen! We need to refactor all data fetching hooks to use SWR.

@samuelmale samuelmale merged commit 3e4e2fa into main Dec 18, 2024
6 checks passed
@samuelmale samuelmale deleted the refactor/use-patient-programs-hook branch December 18, 2024 18:36
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.

2 participants