This repository has been archived by the owner on Jun 8, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a493aaf
commit 675ad0b
Showing
6 changed files
with
122 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
client/src/components/screens/Patient/components/FilesTab/components/MetadataButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useState } from 'react'; | ||
import intl from 'react-intl-universal'; | ||
import { Button, message } from 'antd'; | ||
import Api from 'helpers/api'; | ||
import capitalize from 'lodash/capitalize'; | ||
|
||
type Props = { | ||
filename: string; | ||
taskId: string; | ||
}; | ||
|
||
const displayErrorMessage = () => message.error(capitalize(intl.get('download.error'))); | ||
|
||
const MetadataButton = ({ filename, taskId }: Props): React.ReactElement => { | ||
const [loading, setLoading] = useState(false); | ||
return ( | ||
<Button | ||
className="link--underline" | ||
disabled={loading} | ||
loading={loading} | ||
onClick={async () => { | ||
setLoading(true); | ||
try { | ||
const response = await Api.downloadFileMetadata(taskId, filename); | ||
if ('error' in response) { | ||
displayErrorMessage(); | ||
} | ||
} catch { | ||
displayErrorMessage(); | ||
} finally { | ||
setLoading(false); | ||
} | ||
}} | ||
type="link" | ||
> | ||
Metadata | ||
</Button> | ||
); | ||
}; | ||
|
||
export default MetadataButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
const FileDownload = (data: Blob, fileName: string) => { | ||
const FileDownload = (data: Blob, fileName: string): void => { | ||
const downloadLinkElement = window.document.createElement('a'); | ||
downloadLinkElement.href = window.URL.createObjectURL(data); | ||
downloadLinkElement.download = fileName; | ||
document.body.appendChild(downloadLinkElement); | ||
downloadLinkElement.click(); | ||
document.body.removeChild(downloadLinkElement); | ||
window.URL.revokeObjectURL(downloadLinkElement.href); | ||
} | ||
|
||
export default FileDownload; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters