-
Notifications
You must be signed in to change notification settings - Fork 249
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
(feat) Automatically revalidate order data after form submission #796
Conversation
This PR is a follow-up to #774. It adds a call to SWR's `mutate` function to the orders form submission handler so that when the form gets submitted successfully, a revalidation request gets broadcasted to SWR hooks using the same key. This means that the user does not need to reload the patient chart to see newly created orders. Additionally, this PR also wraps an empty state `Tile` in the OrderBasketItemList component with the `Layer` component. This brings its look and feel in line with the rest of the app.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks it will be useful. I'm curious if you can think of a way to add a test to cover this functionality?
packages/esm-patient-medications-app/src/order-basket/order-basket.component.tsx
Outdated
Show resolved
Hide resolved
We use this pattern in multiple places, and those usages are backed up with tests that assert that a success notification gets rendered when the form gets submitted successfully. Adding a test for this shouldn't be difficult, though I'd prefer to do it in a separate PR. |
It's good that tests check for the notification popup on endpoint success. I was specifically wondering about the |
That's a valid concern. There's a pattern we could leverage to guard against the wrong keys being inadvertently revalidated. This logic would go through the SWR cache and make sure to only revalidate keys that match the provided RegExp. We could use the following RegExp to match the exact key that updates the medications widgets: const apiUrlPattern = new RegExp(
'\\/ws\\/rest\\/v1\\/order\\?patient' + patientUuid + '\\&careSetting=' + config.careSettingUuid,
)
// Find matching keys from SWR's cache and broadcast a revalidation message to their pre-bound SWR hooks
Array.from(cache.keys())
.filter((url: string) => apiUrlPattern.test(url))
.forEach((url: string) => mutate(url)); Amending the PR to adopt this would be straightforward. |
@denniskigen I think adding the regex based filter is our based option here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work @denniskigen
Requirements
Summary
This PR is a follow-up to #774. It adds a call to SWR's
mutate
function to the orders form submission handler so that when the form gets submitted successfully, a revalidation request gets broadcasted to SWR hooks using the same key. This means the user does not need to reload the patient chart to see newly created orders (as @samuelmale showed in the video demo in #774).This PR also wraps an empty state
Tile
in the OrderBasketItemList component with theLayer
component. This harmonizes its look and feel with that of the other empty states in the app.