diff --git a/optuna_dashboard/ts/components/TrialTable.tsx b/optuna_dashboard/ts/components/TrialTable.tsx index 62887e24..b066f0c3 100644 --- a/optuna_dashboard/ts/components/TrialTable.tsx +++ b/optuna_dashboard/ts/components/TrialTable.tsx @@ -14,7 +14,19 @@ import TableCell from "@mui/material/TableCell" import TableContainer from "@mui/material/TableContainer" import TableHead from "@mui/material/TableHead" import TableRow from "@mui/material/TableRow" +import TablePagination from "@mui/material/TablePagination" import Paper from "@mui/material/Paper" +import { TablePaginationActionsProps } from "@mui/material/TablePagination/TablePaginationActions" +import FirstPageIcon from "@mui/icons-material/FirstPage" +import KeyboardArrowLeft from "@mui/icons-material/KeyboardArrowLeft" +import KeyboardArrowRight from "@mui/icons-material/KeyboardArrowRight" +import LastPageIcon from "@mui/icons-material/LastPage" + +import { + TiArrowSortedDown, + TiArrowSortedUp, + TiArrowUnsorted, +} from "react-icons/ti" import { ColumnDef, @@ -22,18 +34,87 @@ import { flexRender, getCoreRowModel, getSortedRowModel, + getPaginationRowModel, SortingState, useReactTable, } from "@tanstack/react-table" -function BasicTable(props: { - columns: ColumnDef[] - rows: Trial[] -}): React.ReactElement { - const { columns, rows } = props - const [sorting, setSorting] = React.useState([]) +const TablePaginationActions = (props: TablePaginationActionsProps) => { + const theme = useTheme() + const { count, page, rowsPerPage, onPageChange } = props - const data = rows + const handleFirstPageButtonClick = ( + event: React.MouseEvent + ) => { + onPageChange(event, 0) + } + + const handleBackButtonClick = ( + event: React.MouseEvent + ) => { + onPageChange(event, page - 1) + } + + const handleNextButtonClick = ( + event: React.MouseEvent + ) => { + onPageChange(event, page + 1) + } + + const handleLastPageButtonClick = ( + event: React.MouseEvent + ) => { + onPageChange(event, Math.max(0, Math.ceil(count / rowsPerPage) - 1)) + } + + return ( + + + {theme.direction === "rtl" ? : } + + + {theme.direction === "rtl" ? ( + + ) : ( + + )} + + = Math.ceil(count / rowsPerPage) - 1} + aria-label="next page" + > + {theme.direction === "rtl" ? ( + + ) : ( + + )} + + = Math.ceil(count / rowsPerPage) - 1} + aria-label="last page" + > + {theme.direction === "rtl" ? : } + + + ) +} + +function BasicTable(props: { + data: Trial[] + columns: ColumnDef[] +}): React.ReactElement { + const { data, columns } = props + const [sorting, setSorting] = React.useState([]) const table = useReactTable({ data, @@ -44,9 +125,13 @@ function BasicTable(props: { onSortingChange: setSorting, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), + getPaginationRowModel: getPaginationRowModel(), + // debugTable: true, }) + const { pageSize, pageIndex } = table.getState().pagination + return ( @@ -79,10 +164,13 @@ function BasicTable(props: { header.column.columnDef.header, header.getContext() )} - {{ - asc: " 🔼", - desc: " 🔽", - }[header.column.getIsSorted() as string] ?? null} + {header.column.getCanSort() + ? { + asc: , + desc: , + false: , + }[header.column.getIsSorted() as string] + : null} )} @@ -111,6 +199,27 @@ function BasicTable(props: { + { + table.setPageIndex(page) + }} + onRowsPerPageChange={(e) => { + const size = e.target.value ? Number(e.target.value) : 10 + table.setPageSize(size) + }} + ActionsComponent={TablePaginationActions} + /> ) } @@ -359,7 +468,7 @@ export const TrialTable: FC<{ > Download CSV File - + ) }