-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic table rendering CSV Errors implemented
- Loading branch information
Showing
8 changed files
with
232 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 0 additions & 15 deletions
15
api/src/utils/csv-utils/csv-config-validation.interface.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { GridColDef } from '@mui/x-data-grid'; | ||
import { StyledDataGrid } from 'components/data-grid/StyledDataGrid'; | ||
import { useMemo } from 'react'; | ||
import { CSVError } from 'utils/file-utils'; | ||
import { v4 } from 'uuid'; | ||
|
||
interface CSVErrorsTableProps { | ||
errors: CSVError[]; | ||
} | ||
|
||
export const CSVErrorsTable = (props: CSVErrorsTableProps) => { | ||
const columns: GridColDef[] = [ | ||
{ | ||
field: 'row', | ||
headerName: 'Row', | ||
description: 'Row number in the CSV file', | ||
type: 'number' | ||
}, | ||
{ | ||
field: 'header', | ||
headerName: 'Header', | ||
description: 'Column header in the CSV file', | ||
minWidth: 200, | ||
type: 'string' | ||
}, | ||
{ | ||
field: 'error', | ||
headerName: 'Error', | ||
description: 'The error message', | ||
flex: 2, | ||
type: 'string' | ||
}, | ||
{ | ||
field: 'solution', | ||
headerName: 'Solution', | ||
description: 'The solution to the error', | ||
flex: 2, | ||
type: 'string' | ||
}, | ||
{ | ||
field: 'cell', | ||
headerName: 'Cell', | ||
description: 'The cell value in the CSV file', | ||
type: 'string' | ||
} | ||
]; | ||
|
||
const rows = useMemo(() => { | ||
return props.errors.map((error) => { | ||
return { | ||
id: v4(), | ||
...error | ||
}; | ||
}); | ||
}, [props.errors]); | ||
|
||
return ( | ||
<StyledDataGrid | ||
noRowsMessage={'No validation errors found'} | ||
autoHeight | ||
rows={rows} | ||
getRowId={(row) => row.id} | ||
columns={columns} | ||
pageSizeOptions={[5, 10, 20, 100]} | ||
rowSelection={false} | ||
checkboxSelection={false} | ||
sortingOrder={['asc', 'desc']} | ||
/> | ||
); | ||
}; |
45 changes: 45 additions & 0 deletions
45
app/src/features/surveys/animals/profile/captures/import-captures/CSVDropzoneSection.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { Box } from '@mui/material'; | ||
import Button from '@mui/material/Button'; | ||
import { CSVErrorsTable } from 'components/csv/CSVErrorsTable'; | ||
import HorizontalSplitFormComponent from 'components/fields/HorizontalSplitFormComponent'; | ||
import { PropsWithChildren, useState } from 'react'; | ||
import { CSVError } from 'utils/file-utils'; | ||
|
||
interface CSVDropzoneSectionProps { | ||
title: string; | ||
summary: string; | ||
onDownloadTemplate: () => void; | ||
errors: CSVError[]; | ||
} | ||
|
||
export const CSVDropzoneSection = (props: PropsWithChildren<CSVDropzoneSectionProps>) => { | ||
const [showErrorsTable, setShowErrorsTable] = useState(false); | ||
|
||
return ( | ||
<HorizontalSplitFormComponent title={props.title} summary={props.summary}> | ||
<Box sx={{ display: 'flex', flexDirection: 'column' }} gap={2}> | ||
<Box sx={{ display: 'flex', ml: 'auto' }}> | ||
<Button | ||
sx={{ textTransform: 'none', fontWeight: 'regular' }} | ||
variant="outlined" | ||
size="small" | ||
onClick={props.onDownloadTemplate}> | ||
Download Template | ||
</Button> | ||
{props.errors.length > 0 && ( | ||
<Button | ||
sx={{ ml: 2, textTransform: 'none', fontWeight: 'regular' }} | ||
variant="contained" | ||
color="error" | ||
size="small" | ||
onClick={() => setShowErrorsTable((s) => !s)}> | ||
View CSV Errors | ||
</Button> | ||
)} | ||
</Box> | ||
{props.children} | ||
{showErrorsTable && <CSVErrorsTable errors={props.errors} />} | ||
</Box> | ||
</HorizontalSplitFormComponent> | ||
); | ||
}; |
Oops, something went wrong.