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 3 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,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">
Expand Down Expand Up @@ -200,15 +233,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) => (
Expand Down
Loading