From 1fa6d3db27081cbe734a9aa976c29b632f00c161 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Fri, 26 Sep 2025 18:29:10 +0200 Subject: [PATCH] refactor(DataTable): enhance type definitions for processed data rows and update custom actions renderer type --- .../client/src/components/DataTable/DataTable.tsx | 11 +++-------- .../src/components/DataTable/DataTable.types.ts | 6 +++++- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/packages/client/src/components/DataTable/DataTable.tsx b/packages/client/src/components/DataTable/DataTable.tsx index 2cb332b448..e9e1c0e37a 100644 --- a/packages/client/src/components/DataTable/DataTable.tsx +++ b/packages/client/src/components/DataTable/DataTable.tsx @@ -9,9 +9,8 @@ import { type VisibilityState, type ColumnDef, type Row, - type Table as TTable, } from '@tanstack/react-table'; -import type { DataTableProps } from './DataTable.types'; +import type { DataTableProps, ProcessedDataRow, TableColumnDef } from './DataTable.types'; import { SelectionCheckbox, MemoizedTableRow, SkeletonRows } from './DataTableComponents'; import { Table, TableBody, TableHead, TableHeader, TableCell, TableRow } from '../Table'; import { useDebounced, useOptimizedRowSelection } from './DataTable.hooks'; @@ -23,10 +22,6 @@ import { Button } from '../Button'; import { Label } from '../Label'; import { Spinner } from '~/svgs'; -type ProcessedDataRow = TData & { _id: string; _index: number }; - -type TableColumnDef = ColumnDef, TValue>; - function DataTable, TValue>({ columns, data, @@ -190,7 +185,7 @@ function DataTable, TValue>({ const virtualRows = rowVirtualizer.getVirtualItems(); const totalSize = rowVirtualizer.getTotalSize(); - const paddingTop = virtualRows.length > 0 ? (virtualRows[0]?.start ?? 0) : 0; + const paddingTop = virtualRows[0]?.start ?? 0; const paddingBottom = virtualRows.length > 0 ? totalSize - (virtualRows[virtualRows.length - 1]?.end ?? 0) : 0; @@ -294,7 +289,7 @@ function DataTable, TValue>({ customActionsRenderer({ selectedCount, selectedRows: table.getSelectedRowModel().rows.map((r) => r.original), - table: table as unknown as TTable, + table, })} diff --git a/packages/client/src/components/DataTable/DataTable.types.ts b/packages/client/src/components/DataTable/DataTable.types.ts index 183a0a971b..bcdcbe6b78 100644 --- a/packages/client/src/components/DataTable/DataTable.types.ts +++ b/packages/client/src/components/DataTable/DataTable.types.ts @@ -1,6 +1,10 @@ import type { ColumnDef, SortingState, Table } from '@tanstack/react-table'; import type React from 'react'; +export type ProcessedDataRow = TData & { _id: string; _index: number }; + +export type TableColumnDef = ColumnDef, TValue>; + export type TableColumn = ColumnDef & { accessorKey?: string | number; meta?: { @@ -56,7 +60,7 @@ export interface DataTableProps, TValue> { customActionsRenderer?: (params: { selectedCount: number; selectedRows: TData[]; - table: Table; + table: Table>; }) => React.ReactNode; }