import { getCoreRowModel, getFilteredRowModel, getPaginationRowModel, getSortedRowModel, TableOptions, TableState, useReactTable, } from '@tanstack/react-table'; import { AutomationTestingProps } from '@/types'; import { defaultGetRowId } from './defaultGetRowId'; import { Table } from './Table'; import { NestedTable } from './NestedTable'; import { DatatableContent } from './DatatableContent'; import { BasicTableSettings, DefaultType } from './types'; interface Props extends AutomationTestingProps { dataset: D[]; columns: TableOptions['columns']; getRowId?(row: D): string; emptyContentLabel?: string; initialTableState?: Partial; isLoading?: boolean; initialSortBy?: BasicTableSettings['sortBy']; /** * keyword to filter by */ search?: string; 'aria-label'?: string; } export function NestedDatatable({ columns, dataset, getRowId = defaultGetRowId, emptyContentLabel, initialTableState = {}, isLoading, initialSortBy, search, 'data-cy': dataCy, 'aria-label': ariaLabel, }: Props) { const tableInstance = useReactTable({ columns, data: dataset, initialState: { sorting: initialSortBy ? [initialSortBy] : [], ...initialTableState, }, defaultColumn: { enableColumnFilter: false, enableHiding: false, }, state: { globalFilter: search, }, getRowId, autoResetExpanded: false, getCoreRowModel: getCoreRowModel(), getFilteredRowModel: getFilteredRowModel(), getSortedRowModel: getSortedRowModel(), getPaginationRowModel: getPaginationRowModel(), }); return ( tableInstance={tableInstance} isLoading={isLoading} emptyContentLabel={emptyContentLabel} renderRow={(row) => cells={row.getVisibleCells()} />} aria-label={ariaLabel} data-cy={dataCy} /> ); }