Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

feat: Implement infinite scroll for jobs and runs in automation detail page

Khuram Niaz4f9013e85124
diff --git a/__tests__/DiscoveredJobsList.spec.tsx b/__tests__/DiscoveredJobsList.spec.tsx
new file mode 100644
index 0000000..c36f6ac
--- /dev/null
+++ b/__tests__/DiscoveredJobsList.spec.tsx
@@ -0,0 +1,143 @@
+import { render, screen, waitFor, act } from "@testing-library/react";
+import { DiscoveredJobsList } from "@/components/automations/DiscoveredJobsList";
+import type { DiscoveredJob } from "@/models/automation.model";
+
+vi.mock("@/actions/automation.actions", () => ({
+ acceptDiscoveredJob: vi.fn(),
+ dismissDiscoveredJob: vi.fn(),
+ analyzeDiscoveredJob: vi.fn(),
+ clearDiscoveredJobs: vi.fn(),
+}));
+
+let intersectionCallback: IntersectionObserverCallback;
+global.IntersectionObserver = class IntersectionObserver {
+ constructor(callback: IntersectionObserverCallback) {
+ intersectionCallback = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as any;
+
+function makeJob(overrides: Partial<DiscoveredJob> = {}): DiscoveredJob {
+ return {
+ id: "job-1",
+ userId: "user-1",
+ automationId: "automation-1",
+ jobUrl: null,
+ description: "desc",
+ jobType: "full-time",
+ createdAt: new Date("2024-06-01"),
+ jobTitleId: "title-1",
+ companyId: "company-1",
+ locationId: "location-1",
+ matchScore: 80,
+ matchData: null,
+ discoveryStatus: "new",
+ discoveredAt: new Date("2024-06-01"),
+ JobTitle: { label: "Software Engineer" },
+ Company: { label: "Acme Corp" },
+ Location: { label: "Remote" },
+ ...overrides,
+ };
+}
+
+function renderList(
+ overrides: Partial<React.ComponentProps<typeof DiscoveredJobsList>> = {},
+) {
+ const onLoadMore = vi.fn();
+ const onRefresh = vi.fn();
+ const props: React.ComponentProps<typeof DiscoveredJobsList> = {
+ jobs: [makeJob()],
+ totalJobs: 1,
+ loadingMore: false,
+ onLoadMore,
+ dismissedCount: 0,
+ newCount: 1,
+ automationId: "automation-1",
+ onRefresh,
+ ...overrides,
+ };
+ const result = render(<DiscoveredJobsList {...props} />);
+ return { ...result, onLoadMore, onRefresh };
+}
+
+describe("DiscoveredJobsList", () => {
+ it("renders jobs and the records-count summary", () => {
+ const { container } = renderList({
+ jobs: [makeJob(), makeJob({ id: "job-2", JobTitle: { label: "Backend Engineer" } })],
+ totalJobs: 5,
+ });
+
+ expect(screen.getByText("Software Engineer")).toBeInTheDocument();
+ expect(screen.getByText("Backend Engineer")).toBeInTheDocument();
+ expect(
+ container.textContent?.replace(/\s+/g, " "),
+ ).toContain("Showing 1 to 2 of 5 jobs");
+ });
+
+ it("does not render the load-more sentinel once every job is loaded", () => {
+ renderList({ jobs: [makeJob()], totalJobs: 1 });
+
+ expect(
+ screen.queryByTestId("jobs-load-more-sentinel"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("calls onLoadMore when the sentinel scrolls into view and more jobs remain", async () => {
+ const { onLoadMore } = renderList({
+ jobs: [makeJob()],
+ totalJobs: 5,
+ loadingMore: false,
+ });
+
+ expect(screen.getByTestId("jobs-load-more-sentinel")).toBeInTheDocument();
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ await waitFor(() => {
+ expect(onLoadMore).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ it("does not call onLoadMore while a page is already loading", async () => {
+ const { onLoadMore } = renderList({
+ jobs: [makeJob()],
+ totalJobs: 5,
+ loadingMore: true,
+ });
+
+ expect(screen.getByTestId("jobs-load-more-spinner")).toBeInTheDocument();
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ expect(onLoadMore).not.toHaveBeenCalled();
+ });
+
+ it("does not call onLoadMore when the sentinel is not intersecting", async () => {
+ const { onLoadMore } = renderList({
+ jobs: [makeJob()],
+ totalJobs: 5,
+ loadingMore: false,
+ });
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: false }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ expect(onLoadMore).not.toHaveBeenCalled();
+ });
+});
diff --git a/__tests__/RunHistoryList.spec.tsx b/__tests__/RunHistoryList.spec.tsx
new file mode 100644
index 0000000..a5b9c0e
--- /dev/null
+++ b/__tests__/RunHistoryList.spec.tsx
@@ -0,0 +1,132 @@
+import { render, screen, waitFor, act } from "@testing-library/react";
+import { RunHistoryList } from "@/components/automations/RunHistoryList";
+import type { AutomationRun } from "@/models/automation.model";
+
+vi.mock("@/actions/automation.actions", () => ({
+ deleteAutomationRun: vi.fn(),
+}));
+
+let intersectionCallback: IntersectionObserverCallback;
+global.IntersectionObserver = class IntersectionObserver {
+ constructor(callback: IntersectionObserverCallback) {
+ intersectionCallback = callback;
+ }
+ observe() {}
+ unobserve() {}
+ disconnect() {}
+} as any;
+
+function makeRun(overrides: Partial<AutomationRun> = {}): AutomationRun {
+ return {
+ id: "run-1",
+ automationId: "automation-1",
+ jobsSearched: 10,
+ jobsDeduplicated: 8,
+ jobsProcessed: 8,
+ jobsMatched: 3,
+ jobsSaved: 2,
+ status: "completed",
+ errorMessage: null,
+ blockedReason: null,
+ funnelStats: null,
+ startedAt: new Date("2024-06-01T10:00:00"),
+ completedAt: new Date("2024-06-01T10:05:00"),
+ ...overrides,
+ };
+}
+
+function renderList(
+ overrides: Partial<React.ComponentProps<typeof RunHistoryList>> = {},
+) {
+ const onLoadMore = vi.fn();
+ const onDelete = vi.fn();
+ const props: React.ComponentProps<typeof RunHistoryList> = {
+ runs: [makeRun()],
+ totalRuns: 1,
+ loadingMore: false,
+ onLoadMore,
+ onDelete,
+ ...overrides,
+ };
+ const result = render(<RunHistoryList {...props} />);
+ return { ...result, onLoadMore, onDelete };
+}
+
+describe("RunHistoryList", () => {
+ it("renders runs and the records-count summary", () => {
+ const { container } = renderList({
+ runs: [makeRun(), makeRun({ id: "run-2" })],
+ totalRuns: 5,
+ });
+
+ expect(screen.getAllByText("completed")).toHaveLength(2);
+ expect(
+ container.textContent?.replace(/\s+/g, " "),
+ ).toContain("Showing 1 to 2 of 5 runs");
+ });
+
+ it("does not render the load-more sentinel once every run is loaded", () => {
+ renderList({ runs: [makeRun()], totalRuns: 1 });
+
+ expect(
+ screen.queryByTestId("runs-load-more-sentinel"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("calls onLoadMore when the sentinel scrolls into view and more runs remain", async () => {
+ const { onLoadMore } = renderList({
+ runs: [makeRun()],
+ totalRuns: 5,
+ loadingMore: false,
+ });
+
+ expect(screen.getByTestId("runs-load-more-sentinel")).toBeInTheDocument();
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ await waitFor(() => {
+ expect(onLoadMore).toHaveBeenCalledTimes(1);
+ });
+ });
+
+ it("does not call onLoadMore while a page is already loading", async () => {
+ const { onLoadMore } = renderList({
+ runs: [makeRun()],
+ totalRuns: 5,
+ loadingMore: true,
+ });
+
+ expect(screen.getByTestId("runs-load-more-spinner")).toBeInTheDocument();
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: true }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ expect(onLoadMore).not.toHaveBeenCalled();
+ });
+
+ it("does not call onLoadMore when the sentinel is not intersecting", async () => {
+ const { onLoadMore } = renderList({
+ runs: [makeRun()],
+ totalRuns: 5,
+ loadingMore: false,
+ });
+
+ await act(async () => {
+ intersectionCallback(
+ [{ isIntersecting: false }] as IntersectionObserverEntry[],
+ {} as IntersectionObserver,
+ );
+ });
+
+ expect(onLoadMore).not.toHaveBeenCalled();
+ });
+});
diff --git a/src/app/dashboard/automations/[id]/page.tsx b/src/app/dashboard/automations/[id]/page.tsx
index 8818ce4..5c68c75 100644
--- a/src/app/dashboard/automations/[id]/page.tsx
+++ b/src/app/dashboard/automations/[id]/page.tsx
@@ -56,6 +56,7 @@ import { DiscoveredJobDetail } from "@/components/automations/DiscoveredJobDetai
import { RunHistoryList } from "@/components/automations/RunHistoryList";
import { LogsTab, type LogData } from "@/components/automations/LogsTab";
import Loading from "@/components/Loading";
+import { APP_CONSTANTS } from "@/lib/constants";
export default function AutomationDetailPage() {
const params = useParams();
@@ -72,7 +73,13 @@ export default function AutomationDetailPage() {
null,
);
const [runs, setRuns] = useState<AutomationRun[]>([]);
+ const [runsPage, setRunsPage] = useState(1);
+ const [totalRuns, setTotalRuns] = useState(0);
+ const [runsLoadingMore, setRunsLoadingMore] = useState(false);
const [jobs, setJobs] = useState<DiscoveredJob[]>([]);
+ const [jobsPage, setJobsPage] = useState(1);
+ const [totalJobs, setTotalJobs] = useState(0);
+ const [jobsLoadingMore, setJobsLoadingMore] = useState(false);
const [jobStatusCounts, setJobStatusCounts] = useState<{
new: number;
dismissed: number;
@@ -108,8 +115,15 @@ export default function AutomationDetailPage() {
try {
const [automationResult, runsResult, jobsResult] = await Promise.all([
getAutomationById(automationId),
- getAutomationRuns(automationId),
- getDiscoveredJobs({ automationId }),
+ getAutomationRuns(automationId, {
+ page: 1,
+ limit: APP_CONSTANTS.RECORDS_PER_PAGE,
+ }),
+ getDiscoveredJobs({
+ automationId,
+ page: 1,
+ limit: APP_CONSTANTS.RECORDS_PER_PAGE,
+ }),
]);
if (automationResult.success && automationResult.data) {
@@ -127,10 +141,14 @@ export default function AutomationDetailPage() {
if (runsResult.success && runsResult.data) {
setRuns(runsResult.data);
+ setTotalRuns(runsResult.total ?? 0);
+ setRunsPage(1);
}
if (jobsResult.success && jobsResult.data) {
setJobs(jobsResult.data);
+ setTotalJobs(jobsResult.total ?? 0);
+ setJobsPage(1);
if (jobsResult.statusCounts) {
setJobStatusCounts(jobsResult.statusCounts);
}
@@ -226,15 +244,58 @@ export default function AutomationDetailPage() {
}, [automationId]);
const refreshJobs = useCallback(async () => {
- const jobsResult = await getDiscoveredJobs({ automationId });
+ const jobsResult = await getDiscoveredJobs({
+ automationId,
+ page: 1,
+ limit: APP_CONSTANTS.RECORDS_PER_PAGE,
+ });
if (jobsResult.success && jobsResult.data) {
setJobs(jobsResult.data);
+ setTotalJobs(jobsResult.total ?? 0);
+ setJobsPage(1);
if (jobsResult.statusCounts) {
setJobStatusCounts(jobsResult.statusCounts);
}
}
}, [automationId]);
+ const loadMoreJobs = useCallback(async () => {
+ setJobsLoadingMore(true);
+ try {
+ const nextPage = jobsPage + 1;
+ const jobsResult = await getDiscoveredJobs({
+ automationId,
+ page: nextPage,
+ limit: APP_CONSTANTS.RECORDS_PER_PAGE,
+ });
+ if (jobsResult.success && jobsResult.data) {
+ setJobs((prev) => [...prev, ...jobsResult.data!]);
+ setTotalJobs(jobsResult.total ?? 0);
+ setJobsPage(nextPage);
+ }
+ } finally {
+ setJobsLoadingMore(false);
+ }
+ }, [automationId, jobsPage]);
+
+ const loadMoreRuns = useCallback(async () => {
+ setRunsLoadingMore(true);
+ try {
+ const nextPage = runsPage + 1;
+ const runsResult = await getAutomationRuns(automationId, {
+ page: nextPage,
+ limit: APP_CONSTANTS.RECORDS_PER_PAGE,
+ });
+ if (runsResult.success && runsResult.data) {
+ setRuns((prev) => [...prev, ...runsResult.data!]);
+ setTotalRuns(runsResult.total ?? 0);
+ setRunsPage(nextPage);
+ }
+ } finally {
+ setRunsLoadingMore(false);
+ }
+ }, [automationId, runsPage]);
+
// While a manual run is in flight, jobs are persisted to the DB
// incrementally (un-analyzed tier first, then each LLM-analyzed job).
// Poll so they surface live instead of all at once when the run ends.
@@ -387,7 +448,7 @@ export default function AutomationDetailPage() {
}
const resumeMissing = !automation.resume;
- const newJobsCount = jobs.filter((j) => j.discoveryStatus === "new").length;
+ const newJobsCount = jobStatusCounts.new;
// The button must reflect the real run state, not just this page instance's
// runNowLoading: after navigating away and back, runNowLoading resets but the
// SSE reports the run is still live, so fall back to logData.isRunning.
@@ -530,7 +591,7 @@ export default function AutomationDetailPage() {
<div>
<p className="text-sm text-muted-foreground">Discovered Jobs</p>
<p className="font-medium">
- {jobs.length} total
+ {totalJobs} total
{newJobsCount > 0 && (
<Badge variant="secondary" className="ml-2">
{newJobsCount} new
@@ -561,6 +622,9 @@ export default function AutomationDetailPage() {
<TabsContent value="jobs" className="mt-4">
<DiscoveredJobsList
jobs={jobs}
+ totalJobs={totalJobs}
+ loadingMore={jobsLoadingMore}
+ onLoadMore={loadMoreJobs}
dismissedCount={jobStatusCounts.dismissed}
newCount={jobStatusCounts.new}
automationId={automationId}
@@ -571,7 +635,13 @@ export default function AutomationDetailPage() {
/>
</TabsContent>
<TabsContent value="history" className="mt-4">
- <RunHistoryList runs={runs} onDelete={loadData} />
+ <RunHistoryList
+ runs={runs}
+ totalRuns={totalRuns}
+ loadingMore={runsLoadingMore}
+ onLoadMore={loadMoreRuns}
+ onDelete={loadData}
+ />
</TabsContent>
</Tabs>
diff --git a/src/components/automations/DiscoveredJobsList.tsx b/src/components/automations/DiscoveredJobsList.tsx
index af8765f..0fe1031 100644
--- a/src/components/automations/DiscoveredJobsList.tsx
+++ b/src/components/automations/DiscoveredJobsList.tsx
@@ -1,11 +1,11 @@
"use client";
-import { useState, useMemo, useEffect } from "react";
+import { useState, useMemo, useEffect, useRef } from "react";
import { format } from "date-fns";
+import { APP_CONSTANTS } from "@/lib/constants";
import {
Card,
CardContent,
- CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
@@ -49,6 +49,7 @@ import {
analyzeDiscoveredJob,
clearDiscoveredJobs,
} from "@/actions/automation.actions";
+import { RecordsCount } from "@/components/RecordsCount";
// A job is "un-analyzed" only when matchData explicitly marks it so (Greenhouse
// floor survivors). JSearch and legacy jobs have no flag but carry a real AI
@@ -74,6 +75,11 @@ function getPrerankPercent(job: DiscoveredJob): number | null {
interface DiscoveredJobsListProps {
jobs: DiscoveredJob[];
+ // Total jobs for this automation across all pages (not just the loaded
+ // ones), used to drive infinite scroll.
+ totalJobs: number;
+ loadingMore: boolean;
+ onLoadMore: () => void;
// Full per-status counts for the automation (not just the loaded page), so
// the clear dialog matches what clearDiscoveredJobs actually deletes.
dismissedCount: number;
@@ -90,6 +96,9 @@ interface DiscoveredJobsListProps {
export function DiscoveredJobsList({
jobs,
+ totalJobs,
+ loadingMore,
+ onLoadMore,
dismissedCount,
newCount,
automationId,
@@ -102,11 +111,30 @@ export function DiscoveredJobsList({
const [clearOpen, setClearOpen] = useState(false);
const [clearIncludeNew, setClearIncludeNew] = useState(false);
const [clearing, setClearing] = useState(false);
+ const sentinelRef = useRef<HTMLDivElement>(null);
useEffect(() => {
onBusyChange?.(loadingAction !== null);
}, [loadingAction, onBusyChange]);
+ // Infinite scroll: auto-load next page when sentinel is visible
+ useEffect(() => {
+ const sentinel = sentinelRef.current;
+ if (!sentinel) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (entries[0].isIntersecting && !loadingMore && jobs.length < totalJobs) {
+ onLoadMore();
+ }
+ },
+ { threshold: APP_CONSTANTS.INTERSECTION_OBSERVER_THRESHOLD },
+ );
+
+ observer.observe(sentinel);
+ return () => observer.disconnect();
+ }, [jobs.length, totalJobs, loadingMore, onLoadMore]);
+
// Analyzed-first, then by matchScore desc (un-analyzed sort by their lexical
// matchScore value). The analyzed flag lives in matchData JSON, so sort in JS.
const sortedJobs = useMemo(() => {
@@ -231,9 +259,9 @@ export function DiscoveredJobsList({
<div className="flex items-start justify-between gap-4">
<div className="space-y-1.5">
<CardTitle>Discovered Jobs</CardTitle>
- <CardDescription>
- Jobs found by your automations that match your criteria
- </CardDescription>
+ {totalJobs > 0 && (
+ <RecordsCount count={jobs.length} total={totalJobs} label="jobs" />
+ )}
</div>
{dismissedCount + newCount > 0 && (
<Button
@@ -395,6 +423,20 @@ export function DiscoveredJobsList({
})}
</TableBody>
</Table>
+ {jobs.length < totalJobs && (
+ <div
+ ref={sentinelRef}
+ data-testid="jobs-load-more-sentinel"
+ className="flex justify-center p-4"
+ >
+ {loadingMore && (
+ <Loader2
+ data-testid="jobs-load-more-spinner"
+ className="h-5 w-5 animate-spin text-blue-500"
+ />
+ )}
+ </div>
+ )}
</CardContent>
<AlertDialog open={clearOpen} onOpenChange={setClearOpen}>
diff --git a/src/components/automations/RunHistoryList.tsx b/src/components/automations/RunHistoryList.tsx
index 817d8d2..03a0aa7 100644
--- a/src/components/automations/RunHistoryList.tsx
+++ b/src/components/automations/RunHistoryList.tsx
@@ -1,15 +1,11 @@
"use client";
-import { useState } from "react";
+import { useEffect, useRef, useState } from "react";
import { format } from "date-fns";
import { Fragment } from "react";
-import {
- Card,
- CardContent,
- CardDescription,
- CardHeader,
- CardTitle,
-} from "@/components/ui/card";
+import { APP_CONSTANTS } from "@/lib/constants";
+import { RecordsCount } from "@/components/RecordsCount";
+import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
import { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import {
@@ -45,6 +41,11 @@ import { toast } from "@/components/ui/use-toast";
interface RunHistoryListProps {
runs: AutomationRun[];
+ // Total runs for this automation across all pages (not just the loaded
+ // ones), used to drive infinite scroll.
+ totalRuns: number;
+ loadingMore: boolean;
+ onLoadMore: () => void;
onDelete?: () => void;
}
@@ -59,18 +60,79 @@ function parseFunnel(funnelStats: string | null): FunnelStage[] {
}
const STATUS_CONFIG = {
- running: { icon: Clock, color: "text-blue-500", variant: "secondary" as const },
- cancelling: { icon: Loader2, color: "text-amber-500", variant: "secondary" as const },
- completed: { icon: CheckCircle2, color: "text-green-500", variant: "default" as const },
- failed: { icon: XCircle, color: "text-red-500", variant: "destructive" as const },
- completed_with_errors: { icon: AlertCircle, color: "text-amber-500", variant: "secondary" as const },
- blocked: { icon: Ban, color: "text-red-500", variant: "destructive" as const },
- rate_limited: { icon: Timer, color: "text-amber-500", variant: "secondary" as const },
- cancelled: { icon: Square, color: "text-muted-foreground", variant: "secondary" as const },
+ running: {
+ icon: Clock,
+ color: "text-blue-500",
+ variant: "secondary" as const,
+ },
+ cancelling: {
+ icon: Loader2,
+ color: "text-amber-500",
+ variant: "secondary" as const,
+ },
+ completed: {
+ icon: CheckCircle2,
+ color: "text-green-500",
+ variant: "default" as const,
+ },
+ failed: {
+ icon: XCircle,
+ color: "text-red-500",
+ variant: "destructive" as const,
+ },
+ completed_with_errors: {
+ icon: AlertCircle,
+ color: "text-amber-500",
+ variant: "secondary" as const,
+ },
+ blocked: {
+ icon: Ban,
+ color: "text-red-500",
+ variant: "destructive" as const,
+ },
+ rate_limited: {
+ icon: Timer,
+ color: "text-amber-500",
+ variant: "secondary" as const,
+ },
+ cancelled: {
+ icon: Square,
+ color: "text-muted-foreground",
+ variant: "secondary" as const,
+ },
};
-export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
+export function RunHistoryList({
+ runs,
+ totalRuns,
+ loadingMore,
+ onLoadMore,
+ onDelete,
+}: RunHistoryListProps) {
const [deleteRunId, setDeleteRunId] = useState<string | null>(null);
+ const sentinelRef = useRef<HTMLDivElement>(null);
+
+ // Infinite scroll: auto-load next page when sentinel is visible
+ useEffect(() => {
+ const sentinel = sentinelRef.current;
+ if (!sentinel) return;
+
+ const observer = new IntersectionObserver(
+ (entries) => {
+ if (
+ entries[0].isIntersecting &&
+ !loadingMore &&
+ runs.length < totalRuns
+ ) {
+ onLoadMore();
+ }
+ },
+ { threshold: APP_CONSTANTS.INTERSECTION_OBSERVER_THRESHOLD },
+ );
+
+ observer.observe(sentinel);
+ return () => observer.disconnect();
+ }, [runs.length, totalRuns, loadingMore, onLoadMore]);
const handleDelete = async () => {
if (!deleteRunId) return;
@@ -80,7 +142,11 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
toast({ title: "Run deleted" });
onDelete?.();
} else {
- toast({ title: "Error", description: result.message, variant: "destructive" });
+ toast({
+ title: "Error",
+ description: result.message,
+ variant: "destructive",
+ });
}
};
@@ -103,9 +169,9 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
<Card>
<CardHeader>
<CardTitle>Run History</CardTitle>
- <CardDescription>
- Recent automation runs and their results
- </CardDescription>
+ {totalRuns > 0 && (
+ <RecordsCount count={runs.length} total={totalRuns} label="runs" />
+ )}
</CardHeader>
<CardContent className="overflow-x-auto">
<Table>
@@ -125,11 +191,14 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
</TableHeader>
<TableBody>
{runs.map((run) => {
- const config = STATUS_CONFIG[run.status] || STATUS_CONFIG.failed;
+ const config =
+ STATUS_CONFIG[run.status] || STATUS_CONFIG.failed;
const StatusIcon = config.icon;
const duration = run.completedAt
? Math.round(
- (new Date(run.completedAt).getTime() - new Date(run.startedAt).getTime()) / 1000
+ (new Date(run.completedAt).getTime() -
+ new Date(run.startedAt).getTime()) /
+ 1000,
)
: null;
const funnel = parseFunnel(run.funnelStats);
@@ -140,7 +209,9 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
<TableCell>
<div className="flex items-center gap-2">
<StatusIcon className={`h-4 w-4 ${config.color}`} />
- <Badge variant={config.variant}>{run.status.replace("_", " ")}</Badge>
+ <Badge variant={config.variant}>
+ {run.status.replace("_", " ")}
+ </Badge>
</div>
</TableCell>
<TableCell>
@@ -149,10 +220,18 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
<TableCell>
{duration !== null ? `${duration}s` : "-"}
</TableCell>
- <TableCell className="text-center">{run.jobsSearched}</TableCell>
- <TableCell className="text-center">{run.jobsDeduplicated}</TableCell>
- <TableCell className="text-center">{run.jobsProcessed}</TableCell>
- <TableCell className="text-center">{run.jobsMatched}</TableCell>
+ <TableCell className="text-center">
+ {run.jobsSearched}
+ </TableCell>
+ <TableCell className="text-center">
+ {run.jobsDeduplicated}
+ </TableCell>
+ <TableCell className="text-center">
+ {run.jobsProcessed}
+ </TableCell>
+ <TableCell className="text-center">
+ {run.jobsMatched}
+ </TableCell>
<TableCell className="text-center">
<span className="font-medium">{run.jobsSaved}</span>
</TableCell>
@@ -161,7 +240,10 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
<TooltipProvider>
<Tooltip>
<TooltipTrigger>
- <Badge variant="outline" className="max-w-[150px] truncate">
+ <Badge
+ variant="outline"
+ className="max-w-[150px] truncate"
+ >
{run.blockedReason || run.errorMessage}
</Badge>
</TooltipTrigger>
@@ -208,6 +290,20 @@ export function RunHistoryList({ runs, onDelete }: RunHistoryListProps) {
})}
</TableBody>
</Table>
+ {runs.length < totalRuns && (
+ <div
+ ref={sentinelRef}
+ data-testid="runs-load-more-sentinel"
+ className="flex justify-center p-4"
+ >
+ {loadingMore && (
+ <Loader2
+ data-testid="runs-load-more-spinner"
+ className="h-5 w-5 animate-spin text-blue-500"
+ />
+ )}
+ </div>
+ )}
</CardContent>
</Card>