implement pagination boundary checks and auto-navigation for workflow runs (#2650)
This commit is contained in:
committed by
GitHub
parent
48645d1543
commit
20f0fe9321
@@ -22,7 +22,7 @@ import {
|
|||||||
import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
|
import { basicLocalTimeFormat, basicTimeFormat } from "@/util/timeFormat";
|
||||||
import { cn } from "@/util/utils";
|
import { cn } from "@/util/utils";
|
||||||
import { Pencil2Icon, PlayIcon } from "@radix-ui/react-icons";
|
import { Pencil2Icon, PlayIcon } from "@radix-ui/react-icons";
|
||||||
import { useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import {
|
import {
|
||||||
Link,
|
Link,
|
||||||
useNavigate,
|
useNavigate,
|
||||||
@@ -40,6 +40,8 @@ function WorkflowPage() {
|
|||||||
const [statusFilters, setStatusFilters] = useState<Array<Status>>([]);
|
const [statusFilters, setStatusFilters] = useState<Array<Status>>([]);
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
|
|
||||||
|
const PAGE_SIZE = 10;
|
||||||
|
|
||||||
const { data: workflowRuns, isLoading } = useWorkflowRunsQuery({
|
const { data: workflowRuns, isLoading } = useWorkflowRunsQuery({
|
||||||
workflowPermanentId,
|
workflowPermanentId,
|
||||||
statusFilters,
|
statusFilters,
|
||||||
@@ -47,6 +49,14 @@ function WorkflowPage() {
|
|||||||
refetchOnMount: "always",
|
refetchOnMount: "always",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!isLoading && workflowRuns && workflowRuns.length === 0 && page > 1) {
|
||||||
|
const params = new URLSearchParams();
|
||||||
|
params.set("page", String(page - 1));
|
||||||
|
setSearchParams(params, { replace: true });
|
||||||
|
}
|
||||||
|
}, [workflowRuns, isLoading, page, setSearchParams]);
|
||||||
|
|
||||||
const { data: workflow, isLoading: workflowIsLoading } = useWorkflowQuery({
|
const { data: workflow, isLoading: workflowIsLoading } = useWorkflowQuery({
|
||||||
workflowPermanentId,
|
workflowPermanentId,
|
||||||
});
|
});
|
||||||
@@ -170,7 +180,15 @@ function WorkflowPage() {
|
|||||||
</PaginationItem>
|
</PaginationItem>
|
||||||
<PaginationItem>
|
<PaginationItem>
|
||||||
<PaginationNext
|
<PaginationNext
|
||||||
|
className={cn({
|
||||||
|
"cursor-not-allowed":
|
||||||
|
workflowRuns !== undefined &&
|
||||||
|
workflowRuns.length < PAGE_SIZE,
|
||||||
|
})}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (workflowRuns && workflowRuns.length < PAGE_SIZE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const params = new URLSearchParams();
|
const params = new URLSearchParams();
|
||||||
params.set("page", String(page + 1));
|
params.set("page", String(page + 1));
|
||||||
setSearchParams(params, { replace: true });
|
setSearchParams(params, { replace: true });
|
||||||
|
|||||||
Reference in New Issue
Block a user