-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolumns.tsx
72 lines (61 loc) · 1.59 KB
/
columns.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import { createColumnHelper } from '@tanstack/react-table'
import { Link, routes } from '@redwoodjs/router'
import { formatDateString } from 'src/utils'
const columnHelper = createColumnHelper()
function valueAsLink(cell): JSX.Element {
const value = cell.getValue()
return (
<Link
to={routes.upload({ id: value })}
title={`Show upload ${value} detail`}
className="link-underline link-underline-opacity-0"
>
{value}
</Link>
)
}
function validationDisplay(row) {
const { latestValidation } = row
if (!latestValidation || latestValidation.results === null) {
return 'Not set'
}
const { passed, createdAt } = latestValidation
const formattedDate = formatDateString(createdAt)
if (!passed) {
return (
<span className="text-danger">
Did not pass validation on {formattedDate}
</span>
)
}
return formattedDate
}
export const columnDefs = [
columnHelper.accessor('id', {
cell: valueAsLink,
header: 'ID',
}),
columnHelper.accessor('agency.code', {
cell: (info) => info.getValue(),
header: 'Agency',
}),
columnHelper.accessor('expenditureCategory.code', {
cell: (info) => info.getValue() ?? 'Not set',
header: 'EC Code',
}),
columnHelper.accessor('uploadedBy.email', {
cell: (info) => info.getValue(),
header: 'Uploaded By',
}),
columnHelper.accessor('filename', {
cell: (info) => info.getValue(),
header: 'Filename',
}),
{
accessorFn: validationDisplay,
cell: (info) => info.getValue(),
id: 'createdAt',
header: 'Validated?',
enableSorting: false,
},
]