Skip to content

Commit

Permalink
Merge pull request #4 from jaypyles/3-add-multijob-downloading
Browse files Browse the repository at this point in the history
feat: add multijob downloading
  • Loading branch information
jaypyles authored Jul 7, 2024
2 parents a4440a3 + 9b55689 commit 6b5d0b6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
4 changes: 2 additions & 2 deletions api/backend/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion api/backend/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class RetrieveScrapeJobs(pydantic.BaseModel):


class DownloadJob(pydantic.BaseModel):
id: str
ids: list[str]


class DeleteScrapeJobs(pydantic.BaseModel):
Expand Down
20 changes: 16 additions & 4 deletions src/components/JobTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -38,11 +39,11 @@ const JobTable: React.FC<JobTableProps> = ({ 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) {
Expand All @@ -51,7 +52,7 @@ const JobTable: React.FC<JobTableProps> = ({ 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);
Expand Down Expand Up @@ -146,6 +147,17 @@ const JobTable: React.FC<JobTableProps> = ({ jobs, fetchJobs }) => {
</IconButton>
</span>
</Tooltip>
<Tooltip title="Download Selected">
<span>
<IconButton
color="primary"
onClick={() => handleDownload(Array.from(selectedJobs))}
disabled={selectedJobs.size === 0}
>
<DownloadIcon />
</IconButton>
</span>
</Tooltip>
</Box>
<Box sx={{ overflow: "auto", width: "75%" }}>
<Table sx={{ tableLayout: "fixed", width: "100%" }}>
Expand Down Expand Up @@ -231,7 +243,7 @@ const JobTable: React.FC<JobTableProps> = ({ jobs, fetchJobs }) => {
<TableCell sx={{ maxWidth: 100, overflow: "auto" }}>
<Button
onClick={() => {
handleDownload(row.id);
handleDownload([row.id]);
}}
>
Download
Expand Down

0 comments on commit 6b5d0b6

Please sign in to comment.