Skip to content
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) O3-2626: Visit note attach image should be able to attach multiple images #1798

Closed
wants to merge 1 commit into from

Conversation

jwnasambu
Copy link
Contributor

@jwnasambu jwnasambu commented Apr 19, 2024

Requirements

  • This PR has a title that briefly describes the work done including the ticket number. If there is a ticket, make sure your PR title includes a conventional commit label. See existing PR titles for inspiration.
  • My work conforms to the OpenMRS 3.0 Styleguide and design documentation.
  • My work includes tests or is validated by existing tests.

Summary

I fixed the VisitNotesForm component to allow attaching multiple images without necessarily being an array by adjusting the UploadedFile type to accommodate multiple files and update the related logic.

Screenshots

Uploading screencast 2024-05-01 5 PM-36-32.mp4…

Related Issue

https://openmrs.atlassian.net/browse/O3-2626

Other

@jwnasambu
Copy link
Contributor Author

@ibacher Thanks for the review ref .

@jwnasambu jwnasambu marked this pull request as draft April 22, 2024 08:03
@jwnasambu jwnasambu changed the title (fix)o3-2626: Visit note attach image should be able to attach multiple images (fix)o3-2626c: Visit note attach image should be able to attach multiple images May 1, 2024
@jwnasambu jwnasambu changed the title (fix)o3-2626c: Visit note attach image should be able to attach multiple images (fix)o3-2626: Visit note attach image should be able to attach multiple images May 1, 2024
@jwnasambu jwnasambu marked this pull request as ready for review May 1, 2024 14:32
@jwnasambu
Copy link
Contributor Author

@ibacher, @denniskigen and @brandones kindly help me review my PR at your convinient time please!

@brandones brandones requested a review from ibacher May 2, 2024 18:26
@brandones brandones changed the title (fix)o3-2626: Visit note attach image should be able to attach multiple images (feat) O3-2626: Visit note attach image should be able to attach multiple images May 2, 2024
@ibacher
Copy link
Member

ibacher commented May 3, 2024

@jwnasambu Are you stuck on any particular point or is this ready for a full review?

@jwnasambu
Copy link
Contributor Author

@ibacher Its ready for review. Thanks for asking.

Copy link
Member

@ibacher ibacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @jwnasambu! Overall functionality looks good, but there are some finishing touches needed here.

images.map((image) => {
const uploadedFile: UploadedFile = {
base64Content: image.base64Content,
fileName: 'filename',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to either use the image name or allow the user to edit it.

base64Content: image.base64Content,
fileName: 'filename',
fileType: image.fileType,
fileDescription: 'description',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to collect this from the user somehow or omit it altogether rather than supplying junk data.

if (filteredFiles) {
setUploadedImages([...uploadedImages, file]);
} else {
console.error('Error: Unsupported file type');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Errors should be displayed as some kind of notification (either an inline or snackbar) and not simply logged to the console.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want to use reportError for things like this

Copy link
Member

@denniskigen denniskigen May 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, because we want to show an InlineNotification similar to https://github.com/openmrs/openmrs-esm-patient-chart/blob/main/packages/esm-patient-attachments-app/src/camera-media-uploader/media-uploader.component.tsx#L81 here because they're both doing the same thing. So, using an InlineNotification is the ideal approach. We shouldn't log anything to the console.

@@ -49,7 +49,7 @@ import {
} from './visit-notes.resource';
import styles from './visit-notes-form.scss';

const allowedImageTypes = ['jpeg', 'jpg', 'png', 'webp'];
const allowedImageTypes = ['.jpeg', '.jpg', '.png', '.webp'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be hard-coded. I think we can adopt the approach from the attachments ESM to load the allowed extensions from the global properties.

Copy link
Member

@denniskigen denniskigen May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibacher @NethmiRodrigo's handled that in https://openmrs.atlassian.net/browse/O3-3153. Presently, it's set to return the following allowedFileExtensions: ['jpeg', 'jpg', 'png' , 'pdf'].

Any notable omissions?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've had to omit out 'webp' from the list of allowed file extensions since it wasn't a supported form of image as per openmrs-module-attachments (list of supported mime types were found from here)

@@ -49,7 +49,7 @@ import {
} from './visit-notes.resource';
import styles from './visit-notes-form.scss';

const allowedImageTypes = ['jpeg', 'jpg', 'png', 'webp'];
const allowedImageTypes = ['.jpeg', '.jpg', '.png', '.webp'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const allowedImageTypes = ['.jpeg', '.jpg', '.png', '.webp'];
const allowedImageTypes = ['jpeg', 'jpg', 'png', 'webp'];

We shouldn't change these values as they'll break things for other teams. See this comment for context, and this follow-up commit.

Copy link
Contributor Author

@jwnasambu jwnasambu May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ibacher kindly I have worked on the proposed changes but I have failed to push and error is displayed. Kindly it has been hours trying to solve the issue without success. Kindly any suggestion on the way forward please?

Copy link
Member

@denniskigen denniskigen May 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disregard my suggestion above. We should delete that array and replace it with the allowed file extensions specified in the backend.

Basically, you can now get the allowedFileExtensions array from the useAllowedFileExtensions hook that Common Lib exports. To leverage it, rebase your branch against main and then import useAllowedFileExtensions from Common Lib and then get allowedFileExtensions from the hook. You can then replace occurrences of allowedImageTypes with allowedFileExtensions.

Finally, you’ll also want to filter allowedFileExtensions to exclude PDF files as we’re only dealing with images here.

@jwnasambu
Copy link
Contributor Author

@ibacher and @denniskigen Kindly am so sorry I have tried to push the changes and even update this PR but all in vain since yesterday and no error thrown to guide me. Kindly I have created this link #1826 with the proposed changes.

@jwnasambu jwnasambu closed this May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants