-
Notifications
You must be signed in to change notification settings - Fork 245
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-4271 fix callback registration in visit form #2151
Conversation
Size Change: +54 B (0%) Total Size: 16 MB ℹ️ View Unchanged
|
Have you tried |
patientUuid, | ||
setVisitFormCallbacks: (callbacks) => { | ||
setVisitFormCallbacks((old) => { | ||
return new Map(old).set(extension.id, callbacks); |
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.
Do we need a new Map
on every call? It might simplify things if it's possible to do an update-in-place.
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.
I think we do, if we keep using useState
, as the Map should be immutable. (This is akin of editing / adding an element to an array state). That said, I think we should move to useRef
.
That's a good idea. Filed O3-4274 to track this. I'll commit this in the meantime as it's a blocker. |
Requirements
Summary
See also corresponding PR in patient-management.
This is a regression from O3-4200. In the service queues app, the form for creating a new queue entry for patient with existing visit is broken. The actual fix is in corresponding PR in patient management; this PR makes necessary change on how the visit form registers
onVisitCreatedOrUpdated
callbacks.Root cause:
[state, setState = useState<Function>()
is generally a bad idea, becausesetState
is overloaded to take in either 1) the new state or 2) a lambda that returns the new state. When doingsetState(callback)
, JavaScript has no way to distinguish between the two, and erroneously treats it as case 2. The visit form, which storesonVisitCreatedOrUpdated
callbacks in aMap<string, Callbacks>
, doesn't actually have this problem, but the form for creating a new queue entry for patient with existing visit does.This PR addresses this by wrapping the callback states in an object.
Unrelated, the visit form has a non-functional / performance issue with infinite state updates when the extensions in
VisitFormExtensionSlot
register callbacks. (Generally, the pattern of a child component updating the parent's state is dangerous if the state is an object.) This PR address that with a combination ofuseCallbacks
,useMemo
andmemo
in various places. (It feels like it should be possible to reduce the use of these memoing functions, but I haven't been able to simplify it.)Screenshots
On submission on start visit form to: start a visit, update visit attributes, check-in appointment, create queue entry.
On submission of form to create queue entry for patient with existing visit:
Related Issue
https://openmrs.atlassian.net/browse/O3-4271
Other