Skip to content

Commit 9914ac8

Browse files
feat(dashboard): conditionally show/hide pagination controls
1 parent 14dd01f commit 9914ac8

3 files changed

Lines changed: 64 additions & 43 deletions

File tree

packages/dashboard/src/lib/runs-page-pagination.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,15 @@ export function resolveStepAttemptsPageSize(
5252
): StepAttemptsPageSize {
5353
return resolveRunsPageSize(limit);
5454
}
55+
56+
export interface CursorPaginationState {
57+
prev?: string | null;
58+
next?: string | null;
59+
}
60+
61+
export function shouldShowPaginationControls(
62+
pagination: CursorPaginationState,
63+
): boolean {
64+
const cursor = pagination.prev ?? pagination.next;
65+
return cursor !== null && cursor !== undefined;
66+
}

packages/dashboard/src/routes/index.tsx

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
RUNS_PAGE_SIZE_OPTIONS,
2828
type RunsPaginationSearch,
2929
resolveRunsPageSize,
30+
shouldShowPaginationControls,
3031
validateRunsPaginationSearch,
3132
} from "@/lib/runs-page-pagination";
3233
import { usePolling } from "@/lib/use-polling";
@@ -117,6 +118,7 @@ function HomePage() {
117118
const [isCreateRunOpen, setIsCreateRunOpen] = useState(false);
118119
const pageSize = resolveRunsPageSize(search.limit);
119120
const runs = data;
121+
const showRunsPagination = shouldShowPaginationControls(pagination);
120122

121123
function updateRunsSearch(next: Partial<RunsPaginationSearch>) {
122124
void navigate({
@@ -196,51 +198,53 @@ function HomePage() {
196198
showHeader={false}
197199
/>
198200

199-
<div className="flex flex-wrap items-center justify-between gap-3">
200-
<p className="text-muted-foreground text-xs">
201-
Showing {runs.length} run{runs.length === 1 ? "" : "s"}
202-
</p>
203-
<div className="flex w-full flex-wrap items-center gap-2 sm:w-auto sm:justify-end">
204-
<div className="flex items-center gap-2 sm:mr-1">
205-
<p className="text-muted-foreground text-xs">Page size</p>
206-
<Select
207-
value={String(pageSize)}
208-
onValueChange={handlePageSizeChange}
201+
{showRunsPagination && (
202+
<div className="flex flex-wrap items-center justify-between gap-3">
203+
<p className="text-muted-foreground text-xs">
204+
Showing {runs.length} run{runs.length === 1 ? "" : "s"}
205+
</p>
206+
<div className="flex w-full flex-wrap items-center gap-2 sm:w-auto sm:justify-end">
207+
<div className="flex items-center gap-2 sm:mr-1">
208+
<p className="text-muted-foreground text-xs">Page size</p>
209+
<Select
210+
value={String(pageSize)}
211+
onValueChange={handlePageSizeChange}
212+
>
213+
<SelectTrigger className="h-8 w-20">
214+
<SelectValue />
215+
</SelectTrigger>
216+
<SelectContent>
217+
{RUNS_PAGE_SIZE_OPTIONS.map((option) => (
218+
<SelectItem key={option} value={String(option)}>
219+
{option}
220+
</SelectItem>
221+
))}
222+
</SelectContent>
223+
</Select>
224+
</div>
225+
<Button
226+
variant="outline"
227+
size="sm"
228+
className="flex-1 sm:flex-none"
229+
type="button"
230+
onClick={goToPreviousPage}
231+
disabled={!pagination.prev}
232+
>
233+
Previous
234+
</Button>
235+
<Button
236+
variant="outline"
237+
size="sm"
238+
className="flex-1 sm:flex-none"
239+
type="button"
240+
onClick={goToNextPage}
241+
disabled={!pagination.next}
209242
>
210-
<SelectTrigger className="h-8 w-20">
211-
<SelectValue />
212-
</SelectTrigger>
213-
<SelectContent>
214-
{RUNS_PAGE_SIZE_OPTIONS.map((option) => (
215-
<SelectItem key={option} value={String(option)}>
216-
{option}
217-
</SelectItem>
218-
))}
219-
</SelectContent>
220-
</Select>
243+
Next
244+
</Button>
221245
</div>
222-
<Button
223-
variant="outline"
224-
size="sm"
225-
className="flex-1 sm:flex-none"
226-
type="button"
227-
onClick={goToPreviousPage}
228-
disabled={!pagination.prev}
229-
>
230-
Previous
231-
</Button>
232-
<Button
233-
variant="outline"
234-
size="sm"
235-
className="flex-1 sm:flex-none"
236-
type="button"
237-
onClick={goToNextPage}
238-
disabled={!pagination.next}
239-
>
240-
Next
241-
</Button>
242246
</div>
243-
</div>
247+
)}
244248
</div>
245249
</div>
246250

packages/dashboard/src/routes/runs/$runId.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
STEP_ATTEMPTS_PAGE_SIZE_OPTIONS,
2626
type RunsPaginationSearch,
2727
resolveStepAttemptsPageSize,
28+
shouldShowPaginationControls,
2829
validateStepAttemptsPaginationSearch,
2930
} from "@/lib/runs-page-pagination";
3031
import {
@@ -139,6 +140,7 @@ function RunDetailsPage() {
139140
{},
140141
);
141142
const stepPageSize = resolveStepAttemptsPageSize(search.limit);
143+
const showStepPagination = shouldShowPaginationControls(pagination);
142144

143145
function updateStepSearch(next: Partial<RunsPaginationSearch>) {
144146
void navigate({
@@ -475,8 +477,11 @@ function RunDetailsPage() {
475477
</div>
476478
)}
477479

478-
{steps.length > 0 && (
480+
{showStepPagination && (
479481
<div className="border-border bg-muted/20 flex flex-wrap items-center justify-between gap-3 border-t px-4 py-3 sm:px-6">
482+
<p className="text-muted-foreground text-xs">
483+
Showing {steps.length} step{steps.length === 1 ? "" : "s"}
484+
</p>
480485
<div className="flex w-full flex-wrap items-center gap-2 sm:w-auto sm:justify-end">
481486
<div className="flex items-center gap-2 sm:mr-1">
482487
<p className="text-muted-foreground text-xs">Page size</p>

0 commit comments

Comments
 (0)