-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(transcriptomics): SJIP-984 add download data buttons
- Loading branch information
Showing
7 changed files
with
109 additions
and
9 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
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
69 changes: 69 additions & 0 deletions
69
src/views/Analytics/Transcriptomic/Footer/DownloadTranscriptomics/index.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,69 @@ | ||
import { useState } from 'react'; | ||
import intl from 'react-intl-universal'; | ||
import { useDispatch } from 'react-redux'; | ||
import { DownloadOutlined } from '@ant-design/icons'; | ||
import { Button } from 'antd'; | ||
import { BaseButtonProps } from 'antd/lib/button/button'; | ||
import axios from 'axios'; | ||
import saveAs from 'file-saver'; | ||
|
||
import { getBlobFromResponse } from 'common/downloader'; | ||
import { ApiResponse } from 'services/api'; | ||
import { globalActions } from 'store/global'; | ||
|
||
type TDownloadTranscriptomics = BaseButtonProps & { | ||
handleUrl: () => Promise<ApiResponse<{ url: string }>>; | ||
filename: string; | ||
displayNotification?: boolean; | ||
}; | ||
|
||
const DownloadTranscriptomics = ({ | ||
handleUrl, | ||
filename, | ||
displayNotification = false, | ||
...props | ||
}: TDownloadTranscriptomics) => { | ||
const [loading, setLoading] = useState<boolean>(false); | ||
const dispatch = useDispatch(); | ||
return ( | ||
<Button | ||
loading={loading} | ||
icon={<DownloadOutlined />} | ||
onClick={async () => { | ||
setLoading(true); | ||
const response = await handleUrl(); | ||
|
||
if (displayNotification) { | ||
dispatch( | ||
globalActions.displayMessage({ | ||
type: 'loading', | ||
key: filename, | ||
content: intl.get('screen.analytics.transcriptomic.footer.notification'), | ||
duration: 0, | ||
}), | ||
); | ||
} | ||
|
||
await axios({ | ||
url: response.data?.url ?? '', | ||
method: 'GET', | ||
responseType: 'blob', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
Accept: '*/*', | ||
}, | ||
}).then((response) => { | ||
const blob = getBlobFromResponse(response, 'blob'); | ||
saveAs(blob, filename); | ||
setLoading(false); | ||
dispatch(globalActions.destroyMessages([filename])); | ||
}); | ||
}} | ||
{...props} | ||
> | ||
{intl.get('screen.analytics.transcriptomic.footer.download')} | ||
</Button> | ||
); | ||
}; | ||
|
||
export default DownloadTranscriptomics; |
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