-
Notifications
You must be signed in to change notification settings - Fork 231
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) O3-4199: Bed management should use the modal system #1381
base: main
Are you sure you want to change the base?
(refactor) O3-4199: Bed management should use the modal system #1381
Conversation
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.
A couple of quick thoughts. While its a good idea to use the new modal system, I don't like the idea of having to maintain 6 forms instead of the previous 3.
message: string; | ||
} | ||
|
||
const EditBedTagForm: React.FC<EditBedTagFormProps> = ({ editData, mutate, closeModal }) => { |
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 don't quite understand why we've broken things out this way instead of keeping a single, shared form used for both adding and editing a bed tag. This is way more work to maintain.
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.
Ideally, we should maintain a single for adding/editing a tag.
const [showErrorNotification, setShowErrorNotification] = useState(false); | ||
const [formStateError, setFormStateError] = useState(''); |
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.
It's weird to have these consts declared what is now mid-way down the file.
}, | ||
}); | ||
|
||
const onSubmit = (formData: BedTagData) => { |
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.
Why is handleUpdateBedTag
wrapped in useCallback()
but this isn't?
|
||
const onSubmit = (formData: BedTagData) => { | ||
const result = BedTagAdministrationSchema.safeParse(formData); | ||
if (result.success) { |
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.
Shouldn't something happen if the result is not a success?
}); | ||
|
||
const onSubmit = (formData: BedTagData) => { | ||
const result = BedTagAdministrationSchema.safeParse(formData); |
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.
Also, why are we parsing the form data here? What's the goal of this method?
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.
The original code was written by @brandones in my understanding so I feel he is at a better position to answer 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.
I don't think I wrote this; if I appear in the blame I probably moved the code in from somewhere else. Anyway it looks like this is outdated, so I will assume the question is resolved.
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.
@amosmachora please take note
}; | ||
|
||
const onError = (error: { [key: string]: ErrorType }) => { | ||
setFormStateError(Object.entries(error)[0][1].message); |
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.
So we only support a single error? That seems wrong...
In principle, each field should display an error message related to that field and we only need a bigger message if there's an error... bigger than a field.
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.
@ibacher the aim of this PR was to just separate out the forms. As I said in the PR description I consciously made the decision to leave everything as is to make it easier for review. If more changes like this are required I am more than happy to work on them but that might bloat the PR and make it more challenging to review.
Also as I was working on this I made the assumption that since I was working on top of already merged changes there is not much need to concentrate on the details.
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.
Because of the way these changes are done, it's very hard for me to tell what's "new" in this PR and what's just "moved" from somewhere else.
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 see. Think of it this way. the new tag form
and the edit tag form
both used an abstracted tag component
. what I did was duplicate the tag component in both forms. So the new tag form
know owns its own functionality that was previously in the tag component
same as the edit one.
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.
so nothing is new in short
render={({ field, fieldState }) => ( | ||
<> | ||
<TextInput | ||
id="bedTag" |
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.
Is id
required here?
Hello @denniskigen is at a better position to answer this question. Also the new 'architecture' is a personal preference of mine too as it allows for separation of concerns. I think it looks like more work from the onset but it simplifies work later IMO. |
See, I see this in exactly the opposite way. Previously, we had one form to add or edit each of the three things (bed tags, etc.). Now, we have a separate form for each. That means if we decide that we need to, I don't know, collect a date the change should be effective on, we now need to add that field to both the add form and the edit form. With the previous setup, we just needed to modify the code in a single place. While, in general, I'm in favour of breaking things up a bit, breaking things up in this way makes on-going maintenance harder, precisely because you need to know that there are two files that need to be updated for each change. The objection here isn't necessarily to having a separate |
Great points @ibacher this absolutely makes sense if you explain it that way. I guess its just a personal preference of mine and the ticket did leave room for some creativity. What do you suggest we do in that case then? should we just refactor the modals to use the modal system and leave everything as is? |
While we are on the topic, just for fun, how about when you only need to refactor one functionality, say, the edit functionality? Isn`t there a chance that you might end up breaking two features instead of one or making an unnecessary change in the other while you only aimed at changing one thing? |
In addition to @ibacher's response, it is also a case of convention and standards which also guide code reviews. If you look at many forms in the system, the convention is to use a single form for add/edit and unit tests ensure the forms work as expected. I suggest that you only refactor the original code to use the modals. That will also align with the PR title for ease of reviews |
Perfect. Makes sense if that is the ongoing standard then there is probably no reason for this one to be different. |
09545c7
to
eea4e30
Compare
Requirements
Summary
This PR refactors the current modal functionality in the bed management app to use the openmrs modal system as described here. When I was working on this PR I was careful only to refactor the modals, separate edit-add functionalities (beds, bed tags bed types), and not change any underlying implementation. Any change made can be considered absolutely necessary.
I also improved the UX when submitting the modals by adding loading states on the button and showing a spinner. Nothing major.
Screenshots
Short video verifying that nothing breaks after this change
bed-modals-refactor.mp4
Related Issue
https://openmrs.atlassian.net/browse/O3-4199
Other