From a6e895a74c46bf9e1901367b8d4fc73239c9175f Mon Sep 17 00:00:00 2001 From: xfja Date: Thu, 8 Aug 2024 13:21:40 +0200 Subject: [PATCH] feat(web): add filter panel with rollup filter in PaginatedTable --- .../PaginatedTable/PaginatedTable.tsx | 11 ++++ .../PaginatedTable/components/FilterPanel.tsx | 45 ++++++++++++++++ .../components/RollupFilter.tsx | 53 +++++++++++++++++++ apps/web/src/components/RollupIcon.tsx | 6 ++- apps/web/src/pages/blobs.tsx | 15 +++++- apps/web/src/pages/blocks.tsx | 16 +++++- apps/web/src/pages/txs.tsx | 10 +++- 7 files changed, 150 insertions(+), 6 deletions(-) create mode 100644 apps/web/src/components/PaginatedTable/components/FilterPanel.tsx create mode 100644 apps/web/src/components/PaginatedTable/components/RollupFilter.tsx diff --git a/apps/web/src/components/PaginatedTable/PaginatedTable.tsx b/apps/web/src/components/PaginatedTable/PaginatedTable.tsx index c9424640d..bf463d014 100644 --- a/apps/web/src/components/PaginatedTable/PaginatedTable.tsx +++ b/apps/web/src/components/PaginatedTable/PaginatedTable.tsx @@ -11,6 +11,8 @@ import type { PaginationProps } from "~/components/Pagination"; import { Pagination } from "~/components/Pagination"; import type { TableProps } from "~/components/Table"; import { Table } from "~/components/Table"; +import type { Rollup } from "~/types"; +import { FilterPanel } from "./components/FilterPanel"; const DEFAULT_TABLE_EMPTY_STATE = "No items"; const PAGE_SIZES_OPTIONS: DropdownProps["options"] = [ @@ -21,6 +23,10 @@ const PAGE_SIZES_OPTIONS: DropdownProps["options"] = [ ]; const DEFAULT_ROW_SKELETON_HEIGHT = 22; +export interface PaginatedTableQueryFilters { + rollup: Rollup; +} + type PaginationData = { page: number; pageSize: number; @@ -33,6 +39,7 @@ export type PaginatedTableProps = { isExpandable?: boolean; paginationData: PaginationData; rowSkeletonHeight?: string | number; + onFilter: (filters: PaginatedTableQueryFilters) => void; } & Pick; const getRowsSkeleton = ( @@ -58,6 +65,7 @@ export const PaginatedTable: FC = function ({ paginationData, isExpandable = false, rowSkeletonHeight = DEFAULT_ROW_SKELETON_HEIGHT, + onFilter, }) { const { page, pageSize } = paginationData; @@ -120,6 +128,9 @@ export const PaginatedTable: FC = function ({ emptyState={DEFAULT_TABLE_EMPTY_STATE} >
+
+ +
void; +} + +export const FilterPanel: FC = function ({ onFilter }) { + const [formData, setFormData] = useState({ + rollup: null, + }); + + const allowToFilter = !!formData.rollup; + + const handleSubmit = () => { + !!formData.rollup && onFilter({ rollup: formData.rollup.value as Rollup }); + }; + + const handleRollupFilterChange = (newRollup: Option) => { + setFormData((prevState) => ({ ...prevState, rollup: newRollup })); + }; + + return ( +
+ +