-
Notifications
You must be signed in to change notification settings - Fork 22
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: [DHIS2-14334] edit enrollment date #3350
Conversation
Todo: - Run program rules after updating enrollment date - Hide edit button if user lacks data capture access to selected program - Show warning message if selected program has auto generated events - Proper recreation of the designed UI layout - Validate date before posting to server
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.
LGTM
..._modules/capture-core/components/WidgetEnrollment/EnrollmentDate/EnrollmentDate.component.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Joe Cooper <[email protected]>
const onUpdateTeiAttributeValues = useCallback((updatedAttributeValues, teiDisplayName) => { | ||
dispatch(updateEnrollmentAttributeValues(updatedAttributeValues | ||
.map(({ attribute, value }) => ({ id: attribute, value })), | ||
)); | ||
dispatch(updateTeiDisplayName(teiDisplayName)); | ||
}, [dispatch]); | ||
|
||
const onUpdateEnrollmentDate = useCallback(enrollmentDate => | ||
dispatch(updateEnrollmentDate(enrollmentDate)), [dispatch]); |
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.
Hey @superskip,
IMHO the enrollment date in the top ScopeSelector should be updated without requiring a page refresh. The WidgetProfile
currently handles it inonUpdateTeiAttributeValues
and updateTeiDisplayName(teiDisplayName)
. Does it make sense to implement something similar for the enrollment date?
Screen.Recording.2023-06-28.at.10.15.11.mov
Thanks you!
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.
Good observation! Will fix :)
🚀 Deployed on https://deploy-preview-3350--dhis2-capture.netlify.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.
Thanks @superskip.
Some comments in the code, but in addition we should implement the same for "incident date" (you might have mentioned that you wanted a review first). The incident date should have the same information regarding auto-generated events.
dense | ||
className={classes.calendar} | ||
label={enrollmentDateLabel} | ||
inputWidth="50%" |
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.
Can we do a maxWidth of 200 instead of this? Not sure what styles we can send to the CalendarInput component, but an option is to wrap the CalendarInput in a div and set maxWidth on this.
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.
There is no maxWidth
prop, but there is already lower bound on how narrow the enrollment widget can get. If we use inputWidth="200px"
then this lower bound will increase by a little. If we instead say inputWidth="180px"
then the lower bound will increase even less (if at all) while at the same time we will get a width matching better with the width shown in the pictures in the jira ticket.
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 a maxWidth of 200 would be best. Let's go for a wrapping div with a maxWidth of 200.
onUpdateDate, | ||
classes, | ||
}: Props) => { | ||
const [updateMutation] = useDataMutation(enrollmentUpdate); |
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.
Let's implement a simple UI-rollback if the request fails. Simple as in; let's not consider that the user can do simultaneous requests for changing the enrollment date. The useDataMutation
takes an onError
callback that we can utilise.
const saveHandler = (selectedDate: string) => { | ||
enrollment.enrolledAt = convertValueClientToServer(selectedDate, dataElementTypes.DATE); | ||
updateMutation(enrollment); | ||
onUpdateDate && onUpdateDate(enrollment.enrolledAt); |
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.
(Putting this comment here, even though it is not directly related to the code line)
At the moment we update enrolledAt by mutating the enrollment object, but we don't actually set the state (to trigger a re-render). The UI currently updates because of some side-effects in the useDataMutation hook. We should follow best practice here and update the enrollment by setting the state.
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.
Which part of the UI are you thinking of here? The date in the enrollment widget is rendered when the states editMode
and selectedDate
(in enrollmentDate.compontent) changes. Anyway, I think perhaps the change you had in mind got implemented in the error handling commit 🙂
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.
Not exactly what I was looking for.
We should use optimistic UI and update the enrollment date instantly when the user changes it. Meaning; Before we get confirmation from the api, the enrollment date in the Widget UI should update and we should invoke the external onUpdate callback. If the request fails, we should revert the value to the original one. Also, in your saveHandler (EnrollmentDate.container) it is fine to invoke updateMutation directly, don't need to use an useEffect.
I think it makes most sense to update the enrollment object from useEnrollment (EnrollmentDate.container) instead of using a local component state.
...re-core/components/Pages/Enrollment/EnrollmentPageDefault/EnrollmentPageDefault.component.js
Outdated
Show resolved
Hide resolved
program={program} | ||
refetchEnrollment={refetchEnrollment} | ||
refetchTEI={refetchTEI} | ||
ownerOrgUnit={{ id: ownerOrgUnit, displayName }} | ||
loading={!(enrollment && program && displayName)} | ||
onDelete={onDelete} | ||
onAddNew={onAddNew} | ||
onUpdateEnrollmentDate={onUpdateEnrollmentDate} | ||
onUpdateIncidentDate={onUpdateIncidentDate} | ||
error={error} |
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.
can we change this to initError
? (hard to keep track of the errors now when we also have error callbacks when updating)
@@ -0,0 +1,151 @@ | |||
// @flow |
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.
NIT: Can we change the name of this file since we are using it for both enrollment date and incident date? A bit hard since it is the enrollment Widget (so EnrollmentDate makes some sense). EnrollmentWidgetDate maybe? (feel free to come up with something better)
Renamed @JoakimSM - I didn't like how the code turned out after doing the thing we discussed (exposing |
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.
Good job 👍
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.
Tested successfully on 2.41,2.40.2,2.38.5,2.39.3 versions
# [100.38.0](v100.37.0...v100.38.0) (2023-09-06) ### Features * [DHIS2-14334] edit enrollment date ([#3350](#3350)) ([9dd1b6a](9dd1b6a))
🎉 This PR is included in version 100.38.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
# [100.38.0](v100.37.0...v100.38.0) (2023-09-06) ### Features * [DHIS2-14334] edit enrollment date ([#3350](#3350)) ([9dd1b6a](9dd1b6a))
DHIS2-14334
Don't be scared by the large number of line changes, a lot of them comes from
yarn.lock
.@cooper-joe Could you please have a look at the
style
-object inEnrollmentDate.component
? I think the units of measurement might be wrong.