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

(fix) O3-3627: Hide filetype extension for image attachment #2071

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/specs/attachments.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ test('Add and remove an attachment', async ({ page }) => {
});

await test.step('Then I should see the file I uploaded displayed in the attachments table', async () => {
await expect(page.getByRole('button', { name: /brainScan.jpeg/i })).toBeVisible();
await expect(page.getByRole('button', { name: /brainScan/i })).toBeVisible();
});

await test.step('When I click on the `Table view` tab', async () => {
Expand All @@ -78,7 +78,7 @@ test('Add and remove an attachment', async ({ page }) => {
});

await test.step('And I should not see the deleted attachment in the list', async () => {
await expect(page.getByRole('button', { name: /brainScan.jpeg/i })).not.toBeVisible();
await expect(page.getByRole('button', { name: /brainScan/i })).not.toBeVisible();
});

await test.step('And the attachments table should be empty', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,20 +70,28 @@ const FilePreview: React.FC<FilePreviewProps> = ({
clearData,
}) => {
const { t } = useTranslation();
const [fileName, setFileName] = useState(uploadedFile.fileName);
const { allowedExtensions } = useContext(CameraMediaUploaderContext);
const fileExtension = uploadedFile.fileName.match(/\.[^\\/.]+$/)?.[0] || '';
const [fileName, setFileName] = useState(uploadedFile.fileName.replace(/\.[^\\/.]+$/, ''));
const [fileDescription, setFileDescription] = useState(uploadedFile.fileDescription);
const [emptyName, setEmptyName] = useState(false);

const saveImageOrPdf = useCallback(
(event: SyntheticEvent) => {
event.preventDefault();

const sanitizedFileName = allowedExtensions.reduce((name, ext) => {
const regex = new RegExp(`\\.(${ext})+$`, 'i');
return name.replace(regex, '');
}, fileName);

onSaveFile?.({
...uploadedFile,
fileName,
fileName: `${sanitizedFileName}${fileExtension}`,
fileDescription,
});
},
[onSaveFile, fileName, fileDescription, uploadedFile],
[onSaveFile, fileName, fileExtension, allowedExtensions, fileDescription, uploadedFile],
);

const cancelCapture = useCallback(
Expand Down Expand Up @@ -177,4 +185,4 @@ const FilePreview: React.FC<FilePreviewProps> = ({
);
};

export default FileReviewContainer;
export default FileReviewContainer;
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,12 @@ const MediaUploaderComponent = () => {
<p className="cds--label-description">
{t('fileUploadSizeConstraints', 'Size limit is {{fileSize}}MB', {
fileSize: maxFileSize,
})}
.
})}.
</p>
<p className='cds--label-description'>
{t('supportedFiletypes', 'Supported files are {{supportedFiles}}',{
supportedFiles: allowedExtensions?.join(', '),
})}.
</p>
<div className={styles.uploadFile}>
<FileUploaderDropContainer
Expand Down
2 changes: 1 addition & 1 deletion packages/esm-patient-attachments-app/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export function createGalleryEntry(data: AttachmentResponse): Attachment {
return {
id: data.uuid,
src: `${window.openmrsBase}${attachmentUrl}/${data.uuid}/bytes`,
filename: data.filename,
filename: data.filename.replace(/\.[^\\/.]+$/, ''),
description: data.comment,
dateTime: formatDate(new Date(data.dateTime), {
mode: 'wide',
Expand Down
Loading