({
sheetDefinition,
data,
sheetValidationErrors,
setRowData,
removeRows,
addEmptyRow,
resetState,
enumLabelDict,
}: Props)
| 44 | } |
| 45 | |
| 46 | export default function SheetDataEditor({ |
| 47 | sheetDefinition, |
| 48 | data, |
| 49 | sheetValidationErrors, |
| 50 | setRowData, |
| 51 | removeRows, |
| 52 | addEmptyRow, |
| 53 | resetState, |
| 54 | enumLabelDict, |
| 55 | }: Props) { |
| 56 | const { sheetData: allData } = useImporterState(); |
| 57 | const { availableActions } = useImporterDefinition(); |
| 58 | |
| 59 | const [selectedRows, setSelectedRows] = useState<SheetRow[]>([]); |
| 60 | const [viewMode, setViewMode] = useState<SheetViewMode>('all'); |
| 61 | const [searchPhrase, setSearchPhrase] = useState(''); |
| 62 | const [errorColumnFilter, setErrorColumnFilter] = useState<string | null>( |
| 63 | null |
| 64 | ); |
| 65 | |
| 66 | useEffect(() => { |
| 67 | setSelectedRows([]); // On changing sheets |
| 68 | setViewMode('all'); |
| 69 | }, [sheetDefinition]); |
| 70 | |
| 71 | const rowData = useFilteredRowData( |
| 72 | data, |
| 73 | allData, |
| 74 | viewMode, |
| 75 | sheetValidationErrors, |
| 76 | errorColumnFilter, |
| 77 | sheetDefinition, |
| 78 | searchPhrase, |
| 79 | enumLabelDict |
| 80 | ); |
| 81 | |
| 82 | const rowValidationSummary = useMemo(() => { |
| 83 | const allRows = data.rows; |
| 84 | const validRows = allRows.filter( |
| 85 | (_, index) => |
| 86 | !sheetValidationErrors.some((error) => error.rowIndex === index) |
| 87 | ); |
| 88 | const invalidRows = allRows.filter((_, index) => |
| 89 | sheetValidationErrors.some((error) => error.rowIndex === index) |
| 90 | ); |
| 91 | return { |
| 92 | all: allRows.length, |
| 93 | valid: validRows.length, |
| 94 | errors: invalidRows.length, |
| 95 | }; |
| 96 | }, [data, sheetValidationErrors]); |
| 97 | |
| 98 | const columns = useMemo<ColumnDef<SheetRow>[]>(() => { |
| 99 | const baseColumns: ColumnDef<SheetRow>[] = availableActions.includes( |
| 100 | 'removeRows' |
| 101 | ) |
| 102 | ? [ |
| 103 | { |
nothing calls this directly
no test coverage detected