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

[draft] Add grouped provider download button #3533

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
Initial commit
  • Loading branch information
rohitvinnakota-codecov committed Nov 27, 2024
commit 06993ba135816fe910f35d874ec0861109a7dc4f
4 changes: 2 additions & 2 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -22,8 +22,8 @@ if (
process.env.NODE_ENV === 'development' &&
process.env.REACT_APP_MSW_BROWSER
) {
const { worker } = require('./mocks/browser')
worker.start()
// const { worker } = require('./mocks/browser')
// worker.start()
}

ReactModal.setAppElement('#root')
Original file line number Diff line number Diff line change
@@ -124,6 +124,39 @@ function UploadsCard() {
const uploadErrorCount = flatMap(erroredUploads).length
const flagErrorCount = flatMap(flagErrorUploads).length

const getUrlsFromUploads = async (
provider: string,
groupedUploads: Record<string, Array<{ downloadUrl: string }>>
) => {
const uploads = groupedUploads[provider]
if (!uploads?.length) return

uploads.forEach(async (upload) => {
if (upload.downloadUrl) {
try {
const response = await fetch(upload.downloadUrl, {
headers: {
'Content-Type': 'text/plain',
},
})
const blob = await response.blob()
const filename = upload.downloadUrl.split('/').pop() || 'download.txt'

// Force download
const link = document.createElement('a')
link.href = window.URL.createObjectURL(blob)
link.setAttribute('download', filename)
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
window.URL.revokeObjectURL(link.href)
} catch (error) {
console.error('Download failed:', error)
}
}
})
}

return (
<>
<Card className="overflow-x-hidden">
@@ -174,15 +207,26 @@ function UploadsCard() {
title === NONE && 'text-ds-gray-quaternary'
)}
>
<div className="flex items-center">
<Checkbox
icon={determineCheckboxIcon(title)}
checked={determineCheckboxIcon(title) !== undefined}
onClick={() => handleSelectAllForProviderGroup(title)}
/>
<span className="ml-2">
{title === NONE ? 'Provider not specified' : title}
</span>
<div className="flex items-center justify-between">
<div className="flex items-center">
<Checkbox
icon={determineCheckboxIcon(title)}
checked={determineCheckboxIcon(title) !== undefined}
onClick={() => handleSelectAllForProviderGroup(title)}
/>
<span className="ml-2">
{title === NONE ? 'Provider not specified' : title}
</span>
</div>
{/* Download button moved to the right end */}
<button
onClick={() =>
getUrlsFromUploads(title, groupedUploads)
}
className="text-ds-blue-default hover:underline"
>
Download
</button>
</div>
</span>
{groupedUploads[title]?.map((upload, i) => (
Loading
Oops, something went wrong.