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(transcriptomics): SJIP-1124 add tooltip #794

Merged
merged 1 commit into from
Dec 10, 2024
Merged
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
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
Loading