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

Add copy link button #20

Merged
merged 2 commits into from
Jul 25, 2023
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
6 changes: 5 additions & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
"parserOptions": {
"ecmaFeatures": { "jsx": true, "modules": true },
"ecmaVersion": 2018,
"sourceType": "module"
"sourceType": "module",
"requireConfigFile": false,
"babelOptions": {
"presets": ["@babel/preset-react"]
}
},
"plugins": ["react", "prettier"],
"rules": {
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-nodejs
name: Test

on:
pull_request:
push:
workflow_dispatch:

jobs:
pre-commit:
runs-on: ubuntu-22.04
timeout-minutes: 10

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: 18.x
cache: npm

- name: Install dependencies
run: npm ci

- name: Lint and security checks
run: npm run pipeline

- name: Build
run: npm run build

# There are no tests
# - run: npm test
120 changes: 65 additions & 55 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
},
"devDependencies": {
"@babel/eslint-parser": "7.22.5",
"@babel/preset-react": "7.22.5",
"eslint": "8.42.0",
"eslint-config-airbnb": "19.0.4",
"eslint-config-prettier": "8.8.0",
Expand Down
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