CI / changes (push) Successful in 9s
CI / commitlint (push) Has been skipped
CI / openapi (push) Has been skipped
CI / web (push) Successful in 52s
CI / go (push) Has been skipped
CI / bird2 (push) Has been skipped
CI / release (push) Successful in 4m16s
Updated multiple components to replace DataGridShell with DataGridSection, integrating search functionality and improved data handling. This change enhances user experience by providing a consistent interface across various grids, including AccessApiKeysGrid, DashboardRecentJobsGrid, and others. Additionally, introduced global filtering capabilities to streamline data retrieval and presentation, ensuring a more efficient user interaction with the data grids.
62 lines
1.3 KiB
TypeScript
62 lines
1.3 KiB
TypeScript
import { useMemo, useState } from 'react'
|
|
import {
|
|
type ColumnDef,
|
|
type FilterFn,
|
|
type TableOptions,
|
|
useReactTable,
|
|
} from '@tanstack/react-table'
|
|
|
|
import {
|
|
createClientDataGridOptions,
|
|
createTextGlobalFilter,
|
|
} from '@/lib/data-grid-defaults'
|
|
|
|
interface UseClientDataGridOptions<TData extends object> {
|
|
data: TData[]
|
|
columns: ColumnDef<TData>[]
|
|
getSearchText: (row: TData) => string
|
|
getRowId: (row: TData) => string
|
|
pageSize?: number
|
|
tableOptions?: Partial<TableOptions<TData>>
|
|
globalFilterFn?: FilterFn<TData>
|
|
}
|
|
|
|
export function useClientDataGrid<TData extends object>({
|
|
data,
|
|
columns,
|
|
getSearchText,
|
|
getRowId,
|
|
pageSize = 10,
|
|
tableOptions,
|
|
globalFilterFn,
|
|
}: UseClientDataGridOptions<TData>) {
|
|
const [globalFilter, setGlobalFilter] = useState('')
|
|
|
|
const filterFn = useMemo(
|
|
() => globalFilterFn ?? createTextGlobalFilter(getSearchText),
|
|
[getSearchText, globalFilterFn],
|
|
)
|
|
|
|
const table = useReactTable({
|
|
data,
|
|
columns,
|
|
state: { globalFilter },
|
|
onGlobalFilterChange: setGlobalFilter,
|
|
globalFilterFn: filterFn,
|
|
...createClientDataGridOptions<TData>({
|
|
initialState: { pagination: { pageSize } },
|
|
...tableOptions,
|
|
}),
|
|
getRowId,
|
|
})
|
|
|
|
const filteredCount = table.getFilteredRowModel().rows.length
|
|
|
|
return {
|
|
table,
|
|
globalFilter,
|
|
setGlobalFilter,
|
|
filteredCount,
|
|
}
|
|
}
|