({
table,
sheetDefinition,
allData,
sheetValidationErrors,
onCellValueChanged,
setSelectedRows,
tableContainerRef,
enumLabelDict,
}: Props)
| 33 | } |
| 34 | |
| 35 | export default function SheetDataEditorTable({ |
| 36 | table, |
| 37 | sheetDefinition, |
| 38 | allData, |
| 39 | sheetValidationErrors, |
| 40 | onCellValueChanged, |
| 41 | setSelectedRows, |
| 42 | tableContainerRef, |
| 43 | enumLabelDict, |
| 44 | }: Props) { |
| 45 | const { t } = useTranslations(); |
| 46 | const { availableActions } = useImporterDefinition(); |
| 47 | |
| 48 | function cellErrors(columnId: string, rowIndex: number) { |
| 49 | return sheetValidationErrors.filter( |
| 50 | (validation) => |
| 51 | validation.columnId === columnId && validation.rowIndex === rowIndex |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | const headerClass = |
| 56 | 'bg-hello-csv-muted py-3.5 pr-3 pl-4 text-left text-sm font-semibold text-gray-900 whitespace-nowrap border-y border-gray-300'; |
| 57 | const cellClass = |
| 58 | 'text-sm font-medium whitespace-nowrap text-gray-900 border-b border-gray-300'; |
| 59 | |
| 60 | const rows = table.getRowModel().rows; |
| 61 | |
| 62 | const rowVirtualizer = useVirtualizer({ |
| 63 | count: rows.length, |
| 64 | getScrollElement: () => tableContainerRef.current, |
| 65 | estimateSize: () => ESTIMATED_ROW_HEIGHT, |
| 66 | measureElement: (element) => element?.getBoundingClientRect().height, |
| 67 | overscan: 20, |
| 68 | }); |
| 69 | |
| 70 | const visibleRows = rowVirtualizer.getVirtualItems().map((virtualRow) => ({ |
| 71 | row: rows[virtualRow.index], |
| 72 | index: virtualRow.index, |
| 73 | start: virtualRow.start, |
| 74 | end: virtualRow.end, |
| 75 | })); |
| 76 | |
| 77 | // https://github.com/TanStack/virtual/discussions/476 |
| 78 | const [paddingTop, paddingBottom] = |
| 79 | visibleRows.length > 0 |
| 80 | ? [ |
| 81 | Math.max( |
| 82 | 0, |
| 83 | visibleRows[0].start - rowVirtualizer.options.scrollMargin |
| 84 | ), |
| 85 | Math.max( |
| 86 | 0, |
| 87 | rowVirtualizer.getTotalSize() - |
| 88 | visibleRows[visibleRows.length - 1].end |
| 89 | ), |
| 90 | ] |
| 91 | : [0, 0]; |
| 92 |
nothing calls this directly
no test coverage detected