-
Notifications
You must be signed in to change notification settings - Fork 3
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 upload service #214
Conversation
if (data?.attachments) { | ||
const attachments = data.attachments as AttachmentsSchema; | ||
const validFilesetKeys = Object.keys(attachments).filter(key => attachments[key] !== undefined); | ||
const preSignedURLs = await Promise.all(validFilesetKeys.map(() => getPreSignedUrl())); |
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.
@mdial89f @13bfrancis We get one pre-signed URL object back per GROUP of files since every key can hold an array of 1 or more. This was copied functionality from the original approach, but this DOES mean every file in a group associated to a single key is uploaded with the same URL and given the same key. This seems like a flaw, is it?
I believe we should be getting a pre-signed URL per file, not per file group. That way every file has its own upload url and key. But this is making some assumptions about how the upload service and retrieval of a file works.
const getPreSignedUrl = async (): Promise<PreSignedURL> => { | ||
// TODO: Can this be a GET instead of POST w/ empty body | ||
return await API.post("os", "/getUploadUrl", { | ||
body: {}, |
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.
@mdial89f Can this be a GET? POST with an empty body seems like we're maybe compensating for an external services requirement, and if that isn't the case, I think we should refactor.
case buildActionUrl(Action.ISSUE_RAI): | ||
return { | ||
...data, | ||
...userDetails, | ||
requestedDate: seaToolFriendlyTimestamp, | ||
attachments: attachments ? buildAttachmentObject(attachments) : null | ||
}; | ||
case buildActionUrl(Action.RESPOND_TO_RAI): | ||
return { | ||
...data, | ||
...userDetails, | ||
responseDate: seaToolFriendlyTimestamp, | ||
attachments: attachments ? buildAttachmentObject(attachments) : null | ||
}; |
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 like the idea of switch
-ing on our endpoint value because it can help us identify areas where our payloads are literally the same, but have a renamed attribute here and there. We should strive to keep this switch to as few special cases as possible and group similar payloads.
For instance, requestedDate
and responseDate
don't need to be two fields in two payloads...that's just a timestamp. We can derive whether the timestamp is for a response or request based on the action itself.
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 like this. If I get my branch deployed and finished you can use that one for testing if you would like
🎉 This PR is included in version 1.5.0-val.1 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
Purpose
This PR refactors our common submission functionality, including document uploads and the submission payload, out into its own file complete with a standard function and hook adapter. This unifies the code that handles this intricate process, and creates a uniform developer experience.
Linked Issues to Close
N/A
Approach
First, we established that we'd need two interfaces as we sometimes submit actions from pages with just static data, no
form
input, and sometimes we submit from pages with saidform
data viareact-hook-form
. Check outMedicaidForm
andToggleRaiResponseWithdraw
to see this variance.Next, we ported over the document upload process from the big block of code int he MedicaidForm submit handler function, and split it out into well-named functions for easy maintenance and readability.
Finally, we orchestrated document uploads and form data submission via the main
submit
function.Assorted Notes/Considerations/Learning
There is an addition of a map with key/value pairs representing a file's object attribute key and the UI friendly title. If you do not add your attachment type in and it's not currently available in the map, your attachment defaults to the object key (i.e. "cmsForm179" instead of "CMS Form 179")
Examples
For use with
react-hook-form
:For use without any input data or uploaded docs: