forked from nomad-nmr/nomad-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAccountsTable.jsx
109 lines (102 loc) · 2.68 KB
/
AccountsTable.jsx
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React from 'react'
import { Table, Tooltip } from 'antd'
import classes from './AccountsTable.module.css'
const AccountsTable = props => {
console.log(props)
const columns = [
{
title: props.header,
width: 35,
dataIndex: 'name',
key: 'name',
fixed: 'left',
align: 'center',
className: classes.NameHighlight
}
]
//add the grantcode if it exists
if (props.data[0].grantCode) {
columns.push({
title: 'Grant Code',
width: 35,
dataIndex: 'grantCode',
key: 'grantCode',
fixed: 'left',
align: 'center',
render: (text, record) => {
return (record.grantCode && <Tooltip title={`ID: ${record.grantCode?.grantId} \n mutiplier: ${record.grantCode?.multiplier}`}>
<p style={{ color: 'blue' }}>See Grants Info</p>
</Tooltip>)
}
})
}
//Getting dynamic table headers from the first data object
props.data[0].costsPerInstrument.forEach((cost, index) => {
columns.push({
title: cost.instrument,
children: [
{
title: 'Exp Time',
children: [
{
title: 'Manual',
dataIndex: 'expTimeClaims' + index,
align: 'center',
width: 20
},
{
title: 'Auto',
dataIndex: 'expTimeAuto' + index,
align: 'center',
width: 20
}
]
},
{
title: 'Cost [£]',
dataIndex: 'cost' + index,
align: 'center',
width: 20,
render: record => <span style={{ color: 'blue' }}>{record}</span>
}
]
})
})
//adding total column header
columns.push({
title: 'Total Cost [£]',
dataIndex: 'totalCost',
align: 'center',
fixed: 'right',
width: 25,
className: classes.ColHighlight
})
const data = props.data.map((entry, key) => {
const newEntry = {
name: entry.name,
grantCode: entry.grantCode || undefined,
totalCost: entry.totalCost,
key
}
entry.costsPerInstrument.forEach((instr, index) => {
newEntry['expTimeClaims' + index] = instr.expTimeClaims
newEntry['expTimeAuto' + index] = instr.expTimeAuto
newEntry['cost' + index] = instr.cost
})
return newEntry
})
return (
<div style={{ margin: '0 50px 0 50px', height: 'fit-content' }}>
<Table
columns={columns}
dataSource={data}
bordered={true}
size='small'
pagination={false}
rowClassName={record => record.name === 'Total' && classes.RowHighlight}
scroll={{ x: 1500, y: 500 }}
/>
</div>
)
}
export default AccountsTable