import { getClient } from "@/api/AxiosClient"; import { WorkflowRunApiResponse } from "@/api/types"; import { StatusBadge } from "@/components/StatusBadge"; import { Button } from "@/components/ui/button"; import { Pagination, PaginationContent, PaginationItem, PaginationLink, PaginationNext, PaginationPrevious, } from "@/components/ui/pagination"; import { Skeleton } from "@/components/ui/skeleton"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow, } from "@/components/ui/table"; import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat"; import { cn } from "@/util/utils"; import { Pencil2Icon, PlayIcon } from "@radix-ui/react-icons"; import { useQuery } from "@tanstack/react-query"; import { Link, useNavigate, useParams, useSearchParams, } from "react-router-dom"; import { WorkflowApiResponse } from "./types/workflowTypes"; function WorkflowPage() { const credentialGetter = useCredentialGetter(); const { workflowPermanentId } = useParams(); const [searchParams, setSearchParams] = useSearchParams(); const page = searchParams.get("page") ? Number(searchParams.get("page")) : 1; const navigate = useNavigate(); const { data: workflowRuns, isLoading } = useQuery< Array >({ queryKey: ["workflowRuns", workflowPermanentId, page], queryFn: async () => { const client = await getClient(credentialGetter); const params = new URLSearchParams(); params.append("page", String(page)); return client .get(`/workflows/${workflowPermanentId}/runs`, { params, }) .then((response) => response.data); }, refetchOnMount: "always", }); const { data: workflow, isLoading: workflowIsLoading } = useQuery({ queryKey: ["workflow", workflowPermanentId], queryFn: async () => { const client = await getClient(credentialGetter); return client .get(`/workflows/${workflowPermanentId}`) .then((response) => response.data); }, }); if (!workflowPermanentId) { return null; // this should never happen } return (
{workflowIsLoading ? ( <> ) : ( <>

{workflow?.title}

{workflowPermanentId}

)}

Past Runs

ID Status Created At {isLoading ? ( Loading... ) : workflowRuns?.length === 0 ? ( No workflow runs found ) : ( workflowRuns?.map((workflowRun) => ( { if (event.ctrlKey || event.metaKey) { window.open( window.location.origin + `/workflows/${workflowPermanentId}/${workflowRun.workflow_run_id}`, "_blank", "noopener,noreferrer", ); return; } navigate( `/workflows/${workflowPermanentId}/${workflowRun.workflow_run_id}`, ); }} className="cursor-pointer" > {workflowRun.workflow_run_id} {basicLocalTimeFormat(workflowRun.created_at)} )) )}
{ if (page === 1) { return; } const params = new URLSearchParams(); params.set("page", String(Math.max(1, page - 1))); setSearchParams(params, { replace: true }); }} /> {page} { const params = new URLSearchParams(); params.set("page", String(page + 1)); setSearchParams(params, { replace: true }); }} />
); } export { WorkflowPage };