Add pagination to workflow tasks (#647)

This commit is contained in:
Kerem Yilmaz 2024-07-25 07:35:47 -07:00 committed by GitHub
parent 7d2dd26931
commit 9f0cad5dd8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 124 additions and 67 deletions

View file

@ -19,6 +19,7 @@ import {
TableRow, TableRow,
} from "@/components/ui/table"; } from "@/components/ui/table";
import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { basicTimeFormat } from "@/util/timeFormat";
import { cn } from "@/util/utils"; import { cn } from "@/util/utils";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { import {
@ -63,31 +64,42 @@ function WorkflowPage() {
<Link to="run">Create New Run</Link> <Link to="run">Create New Run</Link>
</Button> </Button>
</header> </header>
<div> <div className="space-y-4">
<header> <header>
<h1 className="text-lg font-semibold">Past Runs</h1> <h1 className="text-lg font-semibold">Past Runs</h1>
</header> </header>
<div className="rounded-md border">
<Table> <Table>
<TableHeader> <TableHeader>
<TableRow> <TableRow>
<TableHead className="w-1/2">ID</TableHead> <TableHead className="w-1/3">ID</TableHead>
<TableHead className="w-1/2">Status</TableHead> <TableHead className="w-1/3">Status</TableHead>
<TableHead className="w-1/3">Created At</TableHead>
</TableRow> </TableRow>
</TableHeader> </TableHeader>
<TableBody> <TableBody>
{isLoading ? ( {isLoading ? (
<TableRow> <TableRow>
<TableCell colSpan={2}>Loading...</TableCell> <TableCell colSpan={3}>Loading...</TableCell>
</TableRow> </TableRow>
) : workflowRuns?.length === 0 ? ( ) : workflowRuns?.length === 0 ? (
<TableRow> <TableRow>
<TableCell colSpan={2}>No workflow runs found</TableCell> <TableCell colSpan={3}>No workflow runs found</TableCell>
</TableRow> </TableRow>
) : ( ) : (
workflowRuns?.map((workflowRun) => ( workflowRuns?.map((workflowRun) => (
<TableRow <TableRow
key={workflowRun.workflow_run_id} key={workflowRun.workflow_run_id}
onClick={() => { onClick={(event) => {
if (event.ctrlKey || event.metaKey) {
window.open(
window.location.origin +
`/workflows/${workflowPermanentId}/${workflowRun.workflow_run_id}`,
"_blank",
"noopener,noreferrer",
);
return;
}
navigate(`${workflowRun.workflow_run_id}`); navigate(`${workflowRun.workflow_run_id}`);
}} }}
className="cursor-pointer" className="cursor-pointer"
@ -96,6 +108,9 @@ function WorkflowPage() {
<TableCell> <TableCell>
<StatusBadge status={workflowRun.status} /> <StatusBadge status={workflowRun.status} />
</TableCell> </TableCell>
<TableCell>
{basicTimeFormat(workflowRun.created_at)}
</TableCell>
</TableRow> </TableRow>
)) ))
)} )}
@ -132,6 +147,7 @@ function WorkflowPage() {
</Pagination> </Pagination>
</div> </div>
</div> </div>
</div>
); );
} }

View file

@ -12,14 +12,26 @@ import {
} from "@/components/ui/table"; } from "@/components/ui/table";
import { useCredentialGetter } from "@/hooks/useCredentialGetter"; import { useCredentialGetter } from "@/hooks/useCredentialGetter";
import { useQuery } from "@tanstack/react-query"; import { useQuery } from "@tanstack/react-query";
import { useNavigate, useParams } from "react-router-dom"; import { useNavigate, useParams, useSearchParams } from "react-router-dom";
import { TaskListSkeletonRows } from "../tasks/list/TaskListSkeletonRows"; import { TaskListSkeletonRows } from "../tasks/list/TaskListSkeletonRows";
import { basicTimeFormat } from "@/util/timeFormat"; import { basicTimeFormat } from "@/util/timeFormat";
import { TaskActions } from "../tasks/list/TaskActions"; import { TaskActions } from "../tasks/list/TaskActions";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { Input } from "@/components/ui/input"; import { Input } from "@/components/ui/input";
import {
Pagination,
PaginationContent,
PaginationItem,
PaginationLink,
PaginationNext,
PaginationPrevious,
} from "@/components/ui/pagination";
import { cn } from "@/util/utils";
function WorkflowRun() { function WorkflowRun() {
const [searchParams, setSearchParams] = useSearchParams();
const page = searchParams.get("page") ? Number(searchParams.get("page")) : 1;
const { workflowRunId, workflowPermanentId } = useParams(); const { workflowRunId, workflowPermanentId } = useParams();
const credentialGetter = useCredentialGetter(); const credentialGetter = useCredentialGetter();
const navigate = useNavigate(); const navigate = useNavigate();
@ -37,11 +49,13 @@ function WorkflowRun() {
const { data: workflowTasks, isLoading: workflowTasksIsLoading } = useQuery< const { data: workflowTasks, isLoading: workflowTasksIsLoading } = useQuery<
Array<TaskApiResponse> Array<TaskApiResponse>
>({ >({
queryKey: ["workflowTasks", workflowRunId], queryKey: ["workflowTasks", workflowRunId, page],
queryFn: async () => { queryFn: async () => {
const client = await getClient(credentialGetter); const client = await getClient(credentialGetter);
const params = new URLSearchParams();
params.append("page", String(page));
return client return client
.get(`/tasks?workflow_run_id=${workflowRunId}&page_size=200`) .get(`/tasks?workflow_run_id=${workflowRunId}`, { params })
.then((response) => response.data); .then((response) => response.data);
}, },
}); });
@ -90,9 +104,7 @@ function WorkflowRun() {
<TaskListSkeletonRows /> <TaskListSkeletonRows />
) : workflowTasks?.length === 0 ? ( ) : workflowTasks?.length === 0 ? (
<TableRow> <TableRow>
<TableCell colSpan={5}> <TableCell colSpan={5}>No tasks</TableCell>
This workflow run does not have any tasks
</TableCell>
</TableRow> </TableRow>
) : ( ) : (
workflowTasks?.map((task) => { workflowTasks?.map((task) => {
@ -131,6 +143,35 @@ function WorkflowRun() {
)} )}
</TableBody> </TableBody>
</Table> </Table>
<Pagination className="pt-2">
<PaginationContent>
<PaginationItem>
<PaginationPrevious
className={cn({ "cursor-not-allowed": page === 1 })}
onClick={() => {
if (page === 1) {
return;
}
const params = new URLSearchParams();
params.set("page", String(Math.max(1, page - 1)));
setSearchParams(params, { replace: true });
}}
/>
</PaginationItem>
<PaginationItem>
<PaginationLink>{page}</PaginationLink>
</PaginationItem>
<PaginationItem>
<PaginationNext
onClick={() => {
const params = new URLSearchParams();
params.set("page", String(page + 1));
setSearchParams(params, { replace: true });
}}
/>
</PaginationItem>
</PaginationContent>
</Pagination>
</div> </div>
</div> </div>
<div className="space-y-4"> <div className="space-y-4">