🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
feat(ui): jump to page x in table via input in pagination (#3090)
Marc Klingen81c898b4ed33
diff --git a/web/src/components/table/data-table-pagination.tsx b/web/src/components/table/data-table-pagination.tsxindex 89a4bf2bd7..1aa5a47afa 100644--- a/web/src/components/table/data-table-pagination.tsx+++ b/web/src/components/table/data-table-pagination.tsx@@ -16,6 +16,8 @@ import {} from "@/src/components/ui/select";import { usePostHogClientCapture } from "@/src/features/posthog-analytics/usePostHogClientCapture";import { LoaderCircle } from "lucide-react";+import { Input } from "@/src/components/ui/input";+import { useEffect, useState } from "react";interface DataTablePaginationProps<TData> {table: Table<TData>;@@ -28,6 +30,13 @@ export function DataTablePagination<TData>({}: DataTablePaginationProps<TData>) {const capture = usePostHogClientCapture();+ const currentPage = table.getState().pagination.pageIndex + 1;+ const [inputState, setInputState] = useState<number | string>(currentPage);++ useEffect(() => {+ setInputState(currentPage);+ }, [currentPage]);+return (<div className="flex items-center justify-between"><div className="flex-1 text-sm text-muted-foreground">@@ -63,14 +72,65 @@ export function DataTablePagination<TData>({</SelectContent></Select></div>- <div className="flex items-center justify-center whitespace-nowrap text-sm font-medium">- Page {table.getState().pagination.pageIndex + 1} of{" "}- {table.getPageCount() === -1 ? (- <LoaderCircle className="ml-1 h-3 w-3 animate-spin text-muted-foreground" />+ <div className="flex items-center justify-center gap-1 whitespace-nowrap text-sm font-medium">+ {table.getPageCount() !== -1 ? (+ <>+ Page+ <Input+ type="number"+ min={1}+ max={table.getPageCount()}+ value={inputState} // Ensure the value is within bounds+ onChange={(e) => {+ setInputState(e.target.value);+ }}+ onBlur={(e) => {+ const newValue = e.target.value;+ if (newValue === "") {+ table.setPageIndex(0);+ setInputState(1);+ return;+ }++ // if nan, reset to current page+ if (isNaN(Number(newValue))) {+ setInputState(currentPage);+ return;+ }++ const newPageIndex = Number(newValue) - 1;+ if (+ newPageIndex < 0 ||+ newPageIndex >= table.getPageCount()+ ) {+ setInputState(currentPage);+ return;+ }++ table.setPageIndex(newPageIndex);+ setInputState(newPageIndex + 1);+ }}+ className="h-8 appearance-none"+ style={{+ width: `${+ 3 + Math.max(1, table.getPageCount().toString().length)+ }ch`,+ }}+ />+ </>+ ) : (+ `Page ${table.getState().pagination.pageIndex + 1}`+ )}+ {table.getPageCount() !== -1 ? (+ <span>of {table.getPageCount()}</span>) : (- table.getPageCount()+ <span>+ of{" "}+ <LoaderCircle className="ml-1 inline-block h-3 w-3 animate-spin text-muted-foreground" />+ </span>)}</div>+<div className="flex items-center space-x-2"><Buttonvariant="outline"