Skip to content

Commit

Permalink
Add copy link button
Browse files Browse the repository at this point in the history
  • Loading branch information
manics committed Jul 24, 2023
1 parent a243976 commit b5be122
Showing 1 changed file with 35 additions and 6 deletions.
41 changes: 35 additions & 6 deletions src/components/egress/EgressRequestList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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 = {
Expand All @@ -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 {
Expand All @@ -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 = {};
Expand Down Expand Up @@ -624,6 +640,19 @@ function EgressRequestList() {
Download
</Button>
)}
{downloading ? (
<CircularProgress size={25} color="primary" />
) : (
<Button
color="primary"
variant="contained"
onClick={handleCopyLink}
disabled={!isDownloadable}
startIcon={<ContentCopyIcon />}
>
Copy link
</Button>
)}
</Stack>
</MDBModalFooter>
</form>
Expand Down

0 comments on commit b5be122

Please sign in to comment.