From 6d0787dc7289c6aefac2f6210a72d438081e35d9 Mon Sep 17 00:00:00 2001 From: Aleksandr Gumroian Date: Tue, 5 Nov 2024 22:37:17 +0100 Subject: [PATCH] fixup! Add RichTable component with header, body, and pagination --- src/common/RichTable/RichTable.js | 8 +- src/common/RichTable/RichTableBody.js | 10 +- src/common/RichTable/RichTableHeader.js | 63 ++++---- src/common/RichTable/RichTablePagination.js | 160 +++++++------------- 4 files changed, 103 insertions(+), 138 deletions(-) diff --git a/src/common/RichTable/RichTable.js b/src/common/RichTable/RichTable.js index 43cabc2..fa52d7d 100644 --- a/src/common/RichTable/RichTable.js +++ b/src/common/RichTable/RichTable.js @@ -37,8 +37,8 @@ const RichTable = ({ }); const table = useReactTable({ - columns: tableColumns, data: tableData, + columns: tableColumns, getCoreRowModel: getCoreRowModel(), getSortedRowModel: getSortedRowModel(), getPaginationRowModel: getPaginationRowModel(), @@ -57,7 +57,11 @@ const RichTable = ({ {withPagination && ( - + )} ); diff --git a/src/common/RichTable/RichTableBody.js b/src/common/RichTable/RichTableBody.js index b02d6bc..97f6f48 100644 --- a/src/common/RichTable/RichTableBody.js +++ b/src/common/RichTable/RichTableBody.js @@ -12,10 +12,16 @@ const RichTableBody = ({ table, flexRender }) => { {table.getRowModel().rows.map((row) => { return ( - + {row.getVisibleCells().map((cell) => { return ( - + {flexRender( cell.column.columnDef.cell, cell.getContext() diff --git a/src/common/RichTable/RichTableHeader.js b/src/common/RichTable/RichTableHeader.js index 3abdf1c..35d144d 100644 --- a/src/common/RichTable/RichTableHeader.js +++ b/src/common/RichTable/RichTableHeader.js @@ -26,44 +26,43 @@ const RichTableHeader = ({ table, flexRender }) => { {table.getHeaderGroups().map((headerGroup) => ( - {headerGroup.headers.map((header) => { - return ( - - {header.isPlaceholder ? null : ( - - )} - - ); - })} + onClick={header.column.getToggleSortingHandler()} + title={getThTitle(header)} + > + {flexRender( + header.column.columnDef.header, + header.getContext() + )} + {{ + asc: ( + + ), + desc: ( + + ), + }[header.column.getIsSorted()] ?? null} + + )} + + ))} ))} diff --git a/src/common/RichTable/RichTablePagination.js b/src/common/RichTable/RichTablePagination.js index bbafb96..c0a5ace 100644 --- a/src/common/RichTable/RichTablePagination.js +++ b/src/common/RichTable/RichTablePagination.js @@ -5,7 +5,7 @@ * See /LICENSE for more information. */ -import React from "react"; +import React, { useMemo } from "react"; import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"; import { faAngleLeft, @@ -14,89 +14,68 @@ import { faAnglesRight, } from "@fortawesome/free-solid-svg-icons"; -const RichTablePagination = ({ table, tablePageSize }) => { +const RichTablePagination = ({ table, tablePageSize, allRows }) => { + const { pagination } = table.getState(); const prevPagBtnDisabled = !table.getCanPreviousPage(); const nextPagBtnDisabled = !table.getCanNextPage(); + const pageSizes = useMemo(() => { + return [tablePageSize ?? 5, 10, 25].filter( + (value, index, self) => self.indexOf(value) === index + ); + }, [tablePageSize]); + + const renderPaginationButton = (icon, ariaLabel, onClick, disabled) => ( +
  • + +
  • + ); + return ( );