Skip to content

Commit

Permalink
fix(transcriptomics): SJIP-1124 add tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
lflangis committed Dec 10, 2024
1 parent a798089 commit 0b5b2e2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 36 deletions.
2 changes: 2 additions & 0 deletions src/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,8 @@ const en = {
download: 'Download data',
notification:
'Please wait while we generate your report. This process may take a few moments.',
diffGeneTooltip: 'Download differential gene expression across all genes',
sampleTooltip: 'Download gene expression data across all genes',
},
about: {
title: 'About this dataset',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.overlayTooltip {
max-width: 400px;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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 { Button, Tooltip } from 'antd';
import { BaseButtonProps } from 'antd/lib/button/button';
import axios from 'axios';
import saveAs from 'file-saver';
Expand All @@ -11,58 +11,68 @@ import { getBlobFromResponse } from 'common/downloader';
import { ApiResponse } from 'services/api';
import { globalActions } from 'store/global';

import styles from './index.module.css';

type TDownloadTranscriptomics = BaseButtonProps & {
handleUrl: () => Promise<ApiResponse<{ url: string }>>;
filename: string;
displayNotification?: boolean;
tooltip: string;
};

const DownloadTranscriptomics = ({
handleUrl,
filename,
displayNotification = false,
tooltip,
...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();
<Tooltip
title={tooltip}
overlayClassName={styles.overlayTooltip}
overlayInnerStyle={{ textAlign: 'center' }}
>
<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,
}),
);
}
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>
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>
</Tooltip>
);
};

Expand Down
2 changes: 2 additions & 0 deletions src/views/Analytics/Transcriptomic/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,15 @@ const TranscriptomicFooter = ({
<div className={styles.footer}>
<div className={styles.gene}>
<DownloadTranscriptomics
tooltip={intl.get('screen.analytics.transcriptomic.footer.diffGeneTooltip')}
filename="htp-dge-data"
handleUrl={TranscriptomicsApi.fetchExportUrlDiffGeneExp}
disabled={loading}
/>
</div>
<div className={styles.sample}>
<DownloadTranscriptomics
tooltip={intl.get('screen.analytics.transcriptomic.footer.sampleTooltip')}
filename="htp-rnaseq-data"
displayNotification
handleUrl={TranscriptomicsApi.fetchExportUrlSampleGeneExp}
Expand Down

0 comments on commit 0b5b2e2

Please sign in to comment.