From b5be1225b09dd33cae24a653bcc3e84464d61cea Mon Sep 17 00:00:00 2001 From: Simon Li Date: Mon, 24 Jul 2023 19:18:36 +0100 Subject: [PATCH] Add `copy link` button --- src/components/egress/EgressRequestList.js | 41 ++++++++++++++++++---- 1 file changed, 35 insertions(+), 6 deletions(-) diff --git a/src/components/egress/EgressRequestList.js b/src/components/egress/EgressRequestList.js index 80685d1..16b7128 100644 --- a/src/components/egress/EgressRequestList.js +++ b/src/components/egress/EgressRequestList.js @@ -25,6 +25,7 @@ import Snackbar from '@mui/material/Snackbar'; import SnackbarContent from '@mui/material/SnackbarContent'; import IconButton from '@mui/material/IconButton'; import CloseIcon from '@material-ui/icons/Close'; +import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import FileDownloadIcon from '@mui/icons-material/FileDownloadRounded'; import ThumbUpRoundedIcon from '@mui/icons-material/ThumbUpRounded'; import ThumbDownRoundedIcon from '@mui/icons-material/ThumbDownRounded'; @@ -242,7 +243,7 @@ function EgressRequestList() { }; // Make API call to download API - const handleDownload = async () => { + const handleDownloadOrCopy = async (copyToClipboard) => { setDownloading(true); const count = selectedEgressRequest.download_count == null ? 0 : selectedEgressRequest.download_count; const requestDetails = { @@ -257,11 +258,17 @@ function EgressRequestList() { if (requestsApiResult.data.downloadData !== null) { const presignUrl = requestsApiResult.data.downloadData.presign_url; - // Open presign_url link to download file - const downloadLink = document.createElement('a'); - downloadLink.download = 'egress_data.zip'; - downloadLink.href = presignUrl; - downloadLink.click(); + if (copyToClipboard) { + navigator.clipboard.writeText(presignUrl); + setNotificationMessage('Link copied to clipboard'); + setOpenNotification(true); + } else { + // Open presign_url link to download file + const downloadLink = document.createElement('a'); + downloadLink.download = 'egress_data.zip'; + downloadLink.href = presignUrl; + downloadLink.click(); + } selectedEgressRequest.download_count = Number(selectedEgressRequest.download_count) + 1; setDownloading(false); } else { @@ -274,6 +281,15 @@ function EgressRequestList() { } }; + // Make API call to download API + const handleDownload = async () => { + await handleDownloadOrCopy(false); + }; + + const handleCopyLink = async () => { + await handleDownloadOrCopy(true); + }; + // Make API call to submit egress request review const updateEgressRequest = async () => { let requestDetails = {}; @@ -624,6 +640,19 @@ function EgressRequestList() { Download )} + {downloading ? ( + + ) : ( + + )}