From 9b5568924e50646020d082f71e5c1200e9ece799 Mon Sep 17 00:00:00 2001 From: Jayden Pyles Date: Sun, 7 Jul 2024 17:21:25 -0500 Subject: [PATCH] feat: add multijob downloading --- api/backend/app.py | 4 ++-- api/backend/models.py | 2 +- src/components/JobTable.tsx | 20 ++++++++++++++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/api/backend/app.py b/api/backend/app.py index 913b723..6262c01 100644 --- a/api/backend/app.py +++ b/api/backend/app.py @@ -89,9 +89,9 @@ async def retrieve_scrape_jobs(retrieve: RetrieveScrapeJobs): @app.post("/api/download") async def download(download_job: DownloadJob): - LOG.info(f"Downloading job with id: {download_job.id}") + LOG.info(f"Downloading job with ids: {download_job.ids}") try: - results = await query({"id": download_job.id}) + results = await query({"id": {"$in": download_job.ids}}) flattened_results = [] for result in results: diff --git a/api/backend/models.py b/api/backend/models.py index 38769b2..ae4d9cb 100644 --- a/api/backend/models.py +++ b/api/backend/models.py @@ -31,7 +31,7 @@ class RetrieveScrapeJobs(pydantic.BaseModel): class DownloadJob(pydantic.BaseModel): - id: str + ids: list[str] class DeleteScrapeJobs(pydantic.BaseModel): diff --git a/src/components/JobTable.tsx b/src/components/JobTable.tsx index df3846e..134f711 100644 --- a/src/components/JobTable.tsx +++ b/src/components/JobTable.tsx @@ -18,6 +18,7 @@ import { import DeleteIcon from "@mui/icons-material/Delete"; import SelectAllIcon from "@mui/icons-material/SelectAll"; import ExpandMoreIcon from "@mui/icons-material/ExpandMore"; +import DownloadIcon from "@mui/icons-material/Download"; import { useRouter } from "next/router"; interface Job { @@ -38,11 +39,11 @@ const JobTable: React.FC = ({ jobs, fetchJobs }) => { const [allSelected, setAllSelected] = useState(false); const router = useRouter(); - const handleDownload = async (id: string) => { + const handleDownload = async (ids: string[]) => { const response = await fetch("/api/download", { method: "POST", headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ id: id }), + body: JSON.stringify({ ids: ids }), }); if (response.ok) { @@ -51,7 +52,7 @@ const JobTable: React.FC = ({ jobs, fetchJobs }) => { const a = document.createElement("a"); a.style.display = "none"; a.href = url; - a.download = `job_${id}.csv`; + a.download = `job_${ids.splice(0, 1)}.csv`; document.body.appendChild(a); a.click(); window.URL.revokeObjectURL(url); @@ -146,6 +147,17 @@ const JobTable: React.FC = ({ jobs, fetchJobs }) => { + + + handleDownload(Array.from(selectedJobs))} + disabled={selectedJobs.size === 0} + > + + + + @@ -231,7 +243,7 @@ const JobTable: React.FC = ({ jobs, fetchJobs }) => {