From af4ba8c102fca255a03687dfd1280b3b826d961a Mon Sep 17 00:00:00 2001 From: Arkadiusz Moscicki Date: Sat, 27 Dec 2025 23:41:11 +0000 Subject: [PATCH] refactor(data-table): Clean up data table components - Remove unused imports and dead code - Improve type safety --- .../data-table/data-table-date-filter.tsx | 12 +- .../data-table/data-table-faceted-filter.tsx | 17 ++- .../data-table/data-table-pagination.tsx | 5 +- .../data-table/data-table-slider-filter.tsx | 18 ++- .../data-table/data-table-toolbar.tsx | 136 +++++++++--------- src/hooks/use-data-table.ts | 6 +- src/lib/parsers.ts | 23 ++- 7 files changed, 117 insertions(+), 100 deletions(-) diff --git a/src/components/data-table/data-table-date-filter.tsx b/src/components/data-table/data-table-date-filter.tsx index dc64c5d6..63e0a303 100644 --- a/src/components/data-table/data-table-date-filter.tsx +++ b/src/components/data-table/data-table-date-filter.tsx @@ -181,15 +181,21 @@ export function DataTableDateFilter({ className="border-dashed font-normal" > {hasValue ? ( -
{ + if (e.key === "Enter" || e.key === " ") { + e.preventDefault(); + onReset(e as unknown as React.MouseEvent); + } + }} className="rounded-sm opacity-70 transition-opacity hover:opacity-100 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring" > -
+ ) : ( )} diff --git a/src/components/data-table/data-table-faceted-filter.tsx b/src/components/data-table/data-table-faceted-filter.tsx index a35f1eb4..3111382e 100644 --- a/src/components/data-table/data-table-faceted-filter.tsx +++ b/src/components/data-table/data-table-faceted-filter.tsx @@ -40,8 +40,9 @@ export function DataTableFacetedFilter({ const [open, setOpen] = React.useState(false); const columnFilterValue = column?.getFilterValue(); - const selectedValues = new Set( - Array.isArray(columnFilterValue) ? columnFilterValue : [], + const selectedValues = React.useMemo( + () => new Set(Array.isArray(columnFilterValue) ? columnFilterValue : []), + [columnFilterValue] ); const onItemSelect = React.useCallback( @@ -82,15 +83,21 @@ export function DataTableFacetedFilter({ className="border-dashed font-normal" > {selectedValues?.size > 0 ? ( -
{ + if (e.key === "Enter" || e.key === " ") { + e.preventDefault(); + onReset(); + } + }} > -
+ ) : ( )} diff --git a/src/components/data-table/data-table-pagination.tsx b/src/components/data-table/data-table-pagination.tsx index 4ae343a5..1dcf5a9b 100644 --- a/src/components/data-table/data-table-pagination.tsx +++ b/src/components/data-table/data-table-pagination.tsx @@ -69,8 +69,9 @@ export function DataTablePagination({
- Page {table.getState().pagination.pageIndex + 1} of{" "} - {table.getPageCount()} + {table.getPageCount() > 0 + ? `Page ${table.getState().pagination.pageIndex + 1} of ${table.getPageCount()}` + : "No pages"}