batch processing

This commit is contained in:
DaKheera47 2025-12-15 16:35:18 +00:00
parent 9dd1b7a36e
commit 8227cabd17
6 changed files with 236 additions and 23 deletions

View File

@ -9,6 +9,7 @@
"version": "1.0.0",
"dependencies": {
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-checkbox": "^1.3.2",
"@radix-ui/react-dropdown-menu": "^2.1.15",
"@radix-ui/react-progress": "^1.1.8",
"@radix-ui/react-separator": "^1.1.8",
@ -1392,6 +1393,35 @@
}
}
},
"node_modules/@radix-ui/react-checkbox": {
"version": "1.3.3",
"resolved": "https://registry.npmjs.org/@radix-ui/react-checkbox/-/react-checkbox-1.3.3.tgz",
"integrity": "sha512-wBbpv+NQftHDdG86Qc0pIyXk5IR3tM8Vd0nWLKDcX8nNn4nXFOFwsKuqw2okA/1D/mpaAkmuyndrPJTYDNZtFw==",
"dependencies": {
"@radix-ui/primitive": "1.1.3",
"@radix-ui/react-compose-refs": "1.1.2",
"@radix-ui/react-context": "1.1.2",
"@radix-ui/react-presence": "1.1.5",
"@radix-ui/react-primitive": "2.1.3",
"@radix-ui/react-use-controllable-state": "1.2.2",
"@radix-ui/react-use-previous": "1.1.1",
"@radix-ui/react-use-size": "1.1.1"
},
"peerDependencies": {
"@types/react": "*",
"@types/react-dom": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc",
"react-dom": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
},
"@types/react-dom": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-collection": {
"version": "1.1.7",
"resolved": "https://registry.npmjs.org/@radix-ui/react-collection/-/react-collection-1.1.7.tgz",
@ -2068,6 +2098,20 @@
}
}
},
"node_modules/@radix-ui/react-use-previous": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-previous/-/react-use-previous-1.1.1.tgz",
"integrity": "sha512-2dHfToCj/pzca2Ck724OZ5L0EVrr3eHRNsG/b3xQJLA2hZpVCS99bLAX+hm1IHXDEnzU6by5z/5MIY794/a8NQ==",
"peerDependencies": {
"@types/react": "*",
"react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
},
"peerDependenciesMeta": {
"@types/react": {
"optional": true
}
}
},
"node_modules/@radix-ui/react-use-rect": {
"version": "1.1.1",
"resolved": "https://registry.npmjs.org/@radix-ui/react-use-rect/-/react-use-rect-1.1.1.tgz",

View File

@ -18,6 +18,7 @@
"pipeline:run": "tsx src/server/pipeline/run.ts"
},
"dependencies": {
"@radix-ui/react-checkbox": "^1.3.2",
"@radix-ui/react-dropdown-menu": "^2.1.15",
"@radix-ui/react-alert-dialog": "^1.1.15",
"@radix-ui/react-progress": "^1.1.8",

View File

@ -25,9 +25,9 @@ import { StatusBadge } from "./StatusBadge";
interface JobCardProps {
job: Job;
onApply: (id: string) => void;
onReject: (id: string) => void;
onProcess: (id: string) => void;
onApply: (id: string) => void | Promise<void>;
onReject: (id: string) => void | Promise<void>;
onProcess: (id: string) => void | Promise<void>;
isProcessing: boolean;
}

View File

@ -4,6 +4,7 @@
import React, { useEffect, useMemo, useState } from "react";
import { ArrowUpDown, LayoutGrid, Search, Table2 } from "lucide-react";
import { toast } from "sonner";
import { Button } from "@/components/ui/button";
import { Card, CardContent } from "@/components/ui/card";
@ -26,9 +27,9 @@ import { JobTable, type JobSort } from "./JobTable";
interface JobListProps {
jobs: Job[];
onApply: (id: string) => void;
onReject: (id: string) => void;
onProcess: (id: string) => void;
onApply: (id: string) => void | Promise<void>;
onReject: (id: string) => void | Promise<void>;
onProcess: (id: string) => void | Promise<void>;
processingJobId: string | null;
}
@ -179,6 +180,8 @@ export const JobList: React.FC<JobListProps> = ({
const [activeTab, setActiveTab] = useState<FilterTab>("ready");
const [searchQuery, setSearchQuery] = useState("");
const [sort, setSort] = useState<JobSort>(DEFAULT_SORT);
const [selectedJobIds, setSelectedJobIds] = useState<Set<string>>(() => new Set());
const [batchAction, setBatchAction] = useState<null | "process" | "reject" | "apply">(null);
const [viewMode, setViewMode] = useState<ViewMode>(() => {
try {
const raw = localStorage.getItem(JOB_LIST_VIEW_STORAGE_KEY);
@ -197,6 +200,10 @@ export const JobList: React.FC<JobListProps> = ({
}
}, [viewMode]);
useEffect(() => {
setSelectedJobIds(new Set());
}, [activeTab, viewMode]);
const counts = useMemo(() => {
const byTab: Record<FilterTab, number> = {
ready: 0,
@ -242,12 +249,63 @@ export const JobList: React.FC<JobListProps> = ({
return map;
}, [jobsForTab, searchQuery, sort]);
const activeTabJobs = visibleJobsForTab.get(activeTab) ?? [];
useEffect(() => {
setSelectedJobIds((current) => {
const visibleIds = new Set(activeTabJobs.map((job) => job.id));
const next = new Set<string>();
for (const id of current) {
if (visibleIds.has(id)) next.add(id);
}
return next.size === current.size ? current : next;
});
}, [activeTabJobs]);
const activeResultsCount = visibleJobsForTab.get(activeTab)?.length ?? 0;
const hasActiveFilters =
searchQuery.trim().length > 0 ||
sort.key !== DEFAULT_SORT.key ||
sort.direction !== DEFAULT_SORT.direction;
const selectedJobs = useMemo(() => {
if (selectedJobIds.size === 0) return [];
return activeTabJobs.filter((job) => selectedJobIds.has(job.id));
}, [activeTabJobs, selectedJobIds]);
const selectedCount = selectedJobIds.size;
const runBatch = async (action: "process" | "reject" | "apply") => {
if (selectedJobs.length === 0) return;
const eligible = selectedJobs.filter((job) => {
if (action === "process") return job.status === "discovered";
if (action === "apply") return job.status === "ready";
return job.status === "discovered" || job.status === "ready";
});
const skipped = selectedJobs.length - eligible.length;
if (eligible.length === 0) {
toast.message("No eligible jobs selected");
return;
}
setBatchAction(action);
try {
for (const job of eligible) {
if (action === "process") await Promise.resolve(onProcess(job.id));
if (action === "apply") await Promise.resolve(onApply(job.id));
if (action === "reject") await Promise.resolve(onReject(job.id));
}
setSelectedJobIds(new Set());
const actionLabel = action === "process" ? "Processed" : action === "apply" ? "Applied" : "Skipped";
toast.success(`${actionLabel} ${eligible.length} jobs`, skipped > 0 ? { description: `Skipped ${skipped} ineligible.` } : undefined);
} finally {
setBatchAction(null);
}
};
return (
<Tabs
value={activeTab}
@ -387,19 +445,65 @@ export const JobList: React.FC<JobListProps> = ({
) : (
<>
{viewMode === "table" ? (
<Card>
<CardContent className="p-0">
<JobTable
jobs={filteredJobs}
sort={sort}
onSortChange={setSort}
onApply={onApply}
onReject={onReject}
onProcess={onProcess}
processingJobId={processingJobId}
/>
</CardContent>
</Card>
<div className="space-y-2">
{tab.id === activeTab && selectedCount > 0 && (
<div className="flex flex-wrap items-center justify-between gap-2 rounded-md border bg-muted/20 px-3 py-2">
<div className="text-sm">
<span className="font-medium">{selectedCount}</span>{" "}
<span className="text-muted-foreground">selected</span>
</div>
<div className="flex flex-wrap items-center gap-2">
<Button
size="sm"
variant="secondary"
onClick={() => runBatch("process")}
disabled={batchAction !== null}
>
Generate Resumes
</Button>
<Button
size="sm"
variant="destructive"
onClick={() => runBatch("reject")}
disabled={batchAction !== null}
>
Skip
</Button>
<Button
size="sm"
onClick={() => runBatch("apply")}
disabled={batchAction !== null}
>
Mark Applied
</Button>
<Button
size="sm"
variant="outline"
onClick={() => setSelectedJobIds(new Set())}
disabled={batchAction !== null}
>
Clear
</Button>
</div>
</div>
)}
<Card>
<CardContent className="p-0">
<JobTable
jobs={filteredJobs}
sort={sort}
onSortChange={setSort}
selectedJobIds={selectedJobIds}
onSelectedJobIdsChange={setSelectedJobIds}
onApply={onApply}
onReject={onReject}
onProcess={onProcess}
processingJobId={processingJobId}
/>
</CardContent>
</Card>
</div>
) : (
<div className="grid gap-4">
{filteredJobs.map((job) => (

View File

@ -17,6 +17,7 @@ import {
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { Checkbox } from "@/components/ui/checkbox";
import {
DropdownMenu,
DropdownMenuContent,
@ -49,9 +50,11 @@ export interface JobTableProps {
jobs: Job[];
sort: JobSort;
onSortChange: (sort: JobSort) => void;
onApply: (id: string) => void;
onReject: (id: string) => void;
onProcess: (id: string) => void;
selectedJobIds: Set<string>;
onSelectedJobIdsChange: (ids: Set<string>) => void;
onApply: (id: string) => void | Promise<void>;
onReject: (id: string) => void | Promise<void>;
onProcess: (id: string) => void | Promise<void>;
processingJobId: string | null;
}
@ -123,15 +126,36 @@ export const JobTable: React.FC<JobTableProps> = ({
jobs,
sort,
onSortChange,
selectedJobIds,
onSelectedJobIdsChange,
onApply,
onReject,
onProcess,
processingJobId,
}) => {
const selectedCount = jobs.reduce((count, job) => count + (selectedJobIds.has(job.id) ? 1 : 0), 0);
const allSelected = jobs.length > 0 && selectedCount === jobs.length;
const someSelected = selectedCount > 0 && selectedCount < jobs.length;
return (
<Table className="table-fixed">
<TableHeader>
<TableRow>
<TableHead className="w-10">
<Checkbox
aria-label="Select all rows"
checked={allSelected ? true : someSelected ? "indeterminate" : false}
onCheckedChange={(checked) => {
const next = new Set(selectedJobIds);
if (checked) {
for (const job of jobs) next.add(job.id);
} else {
for (const job of jobs) next.delete(job.id);
}
onSelectedJobIdsChange(next);
}}
/>
</TableHead>
<TableHead className="w-[28%]">
<SortButton label="Title" sortKey="title" sort={sort} onSortChange={onSortChange} />
</TableHead>
@ -178,9 +202,22 @@ export const JobTable: React.FC<JobTableProps> = ({
const canProcess = job.status === "discovered";
const canReject = ["discovered", "ready"].includes(job.status);
const isProcessing = processingJobId === job.id;
const isSelected = selectedJobIds.has(job.id);
return (
<TableRow key={job.id}>
<TableRow key={job.id} data-state={isSelected ? "selected" : undefined}>
<TableCell className="align-top">
<Checkbox
aria-label={`Select ${job.title}`}
checked={isSelected}
onCheckedChange={(checked) => {
const next = new Set(selectedJobIds);
if (checked) next.add(job.id);
else next.delete(job.id);
onSelectedJobIdsChange(next);
}}
/>
</TableCell>
<TableCell className="align-top">
<Button
asChild

View File

@ -0,0 +1,27 @@
import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"
import { cn } from "@/lib/utils"
const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-primary shadow focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator className={cn("flex items-center justify-center text-current")}>
<Check className="h-4 w-4" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = "Checkbox"
export { Checkbox }