@@ -3,15 +3,17 @@ import React from 'react';
33import { MRT_ColumnDef } from 'material-react-table' ;
44import { Checkbox } from '@mui/material' ;
55import * as Icons from '@carbon/icons-react' ;
6- import { ReplicateType } from '../../../../types/consep/TestingActivityType' ;
6+ import { ReplicateKeys , ReplicateType } from '../../../../types/consep/TestingActivityType' ;
7+
8+ export const TABLE_TITLE = 'Activity results per replicate' ;
79
810const alignRight = {
911 muiTableHeadCellProps : { align : 'right' as const } ,
1012 muiTableBodyCellProps : { align : 'right' as const }
1113} ;
1214
1315const createEditableNumberColumn = (
14- accessorKey : keyof ReplicateType ,
16+ accessorKey : ReplicateKeys ,
1517 header : string ,
1618 validationMsg : string ,
1719 updateRow : ( row : ReplicateType ) => void ,
@@ -22,7 +24,7 @@ const createEditableNumberColumn = (
2224 header,
2325 size : 120 ,
2426 muiEditTextFieldProps : ( { cell, row } ) => {
25- const value = row . original [ accessorKey ] ?? '' ;
27+ const value = row . original [ accessorKey as keyof typeof row . original ] ?? '' ;
2628 return {
2729 type : 'number' ,
2830 value,
@@ -60,7 +62,7 @@ const createEditableNumberColumn = (
6062} ) ;
6163
6264const createEditableTextColumn = (
63- accessorKey : keyof ReplicateType ,
65+ accessorKey : ReplicateKeys ,
6466 header : string ,
6567 maxLength : number ,
6668 validationMsg : string ,
@@ -72,7 +74,7 @@ const createEditableTextColumn = (
7274 header,
7375 size : 80 ,
7476 muiEditTextFieldProps : ( { cell, row } ) => {
75- const value = row . original [ accessorKey ] ?? '' ;
77+ const value = row . original [ accessorKey as keyof typeof row . original ] ?? '' ;
7678 return {
7779 type : 'text' ,
7880 value,
@@ -96,7 +98,7 @@ const createEditableTextColumn = (
9698 ...alignRight
9799} ) ;
98100
99- export const getColumns = (
101+ export const getMccColumns = (
100102 disableEditing : boolean ,
101103 handleClearOne : ( replicateNumber : number ) => void ,
102104 updateRow : ( row : ReplicateType ) => void ,
@@ -153,7 +155,7 @@ export const getColumns = (
153155 enableEditing : false ,
154156 muiEditTextFieldProps : ( { row } ) => ( {
155157 type : 'text' ,
156- value : row . original . dryWeight ?? ''
158+ value : 'dryWeight' in row . original ? row . original . dryWeight : ''
157159 } )
158160 } ,
159161 {
@@ -162,7 +164,7 @@ export const getColumns = (
162164 size : 80 ,
163165 muiEditTextFieldProps : ( { row } ) => ( {
164166 type : 'text' ,
165- value : row . original . mcValue ?? ''
167+ value : 'mcValue' in row . original ? row . original . mcValue : ''
166168 } ) ,
167169 enableEditing : false ,
168170 ...alignRight
@@ -193,7 +195,7 @@ export const getColumns = (
193195 size : 300 ,
194196 muiEditTextFieldProps : ( { row } ) => ( {
195197 type : 'text' ,
196- value : row . original . replicateComment ?? '' ,
198+ value : 'replicateComment' in row . original ? row . original . replicateComment : '' ,
197199 onChange : ( event ) => {
198200 updateRow ( {
199201 ...row . original ,
@@ -217,3 +219,97 @@ export const getColumns = (
217219 ...alignRight
218220 }
219221] ;
222+
223+ export const getPurityColumns = (
224+ disableEditing : boolean ,
225+ handleClearOne : ( replicateNumber : number ) => void ,
226+ updateRow : ( row : ReplicateType ) => void ,
227+ validationErrors : Record < string , string | undefined > ,
228+ setValidationErrors : React . Dispatch < React . SetStateAction < Record < string , string | undefined > > >
229+ ) : MRT_ColumnDef < ReplicateType > [ ] => [
230+ {
231+ accessorKey : 'replicateNumber' ,
232+ header : 'Replicate' ,
233+ size : 40 ,
234+ enableEditing : false ,
235+ ...alignRight
236+ } ,
237+ createEditableNumberColumn (
238+ 'pureSeedWeight' ,
239+ 'Pure seed weight (g)' ,
240+ 'Pure Seed Weight must be greater than or equal to 0 and less than 1,000' ,
241+ updateRow ,
242+ validationErrors ,
243+ setValidationErrors
244+ ) ,
245+ createEditableNumberColumn (
246+ 'inertMttrWeight' ,
247+ 'Inert matter weight (g)' ,
248+ 'Inert Matter Weight must be greater than or equal to 0 and less than 1,000' ,
249+ updateRow ,
250+ validationErrors ,
251+ setValidationErrors
252+ ) ,
253+ createEditableNumberColumn (
254+ 'otherSeedWeight' ,
255+ 'Other seed weight (g)' ,
256+ 'Other Seed Weight must be greater than or equal to 0 and less than 1,000' ,
257+ updateRow ,
258+ validationErrors ,
259+ setValidationErrors
260+ ) ,
261+ {
262+ accessorKey : 'purityValue' ,
263+ header : 'Purity' ,
264+ size : 80 ,
265+ ...alignRight
266+ } ,
267+ {
268+ accessorKey : 'replicateAccInd' ,
269+ header : 'Acc' ,
270+ Cell : ( { row } : { row : { original : ReplicateType } } ) => (
271+ < Checkbox
272+ checked = { ! ! row . original . replicateAccInd }
273+ disabled = { disableEditing }
274+ onClick = { ( ) => {
275+ updateRow ( {
276+ ...row . original ,
277+ replicateAccInd : row . original . replicateAccInd === 1 ? 0 : 1
278+ } ) ;
279+ } }
280+ />
281+ ) ,
282+ size : 40 ,
283+ muiTableHeadCellProps : { align : 'center' } ,
284+ muiTableBodyCellProps : { align : 'center' } ,
285+ enableEditing : false
286+ } ,
287+ {
288+ accessorKey : 'overrideReason' ,
289+ header : 'Comments' ,
290+ size : 300 ,
291+ muiEditTextFieldProps : ( { row } ) => ( {
292+ type : 'text' ,
293+ onChange : ( event ) => {
294+ updateRow ( {
295+ ...row . original ,
296+ replicateComment : event . currentTarget . value
297+ } ) ;
298+ }
299+ } )
300+ } ,
301+ {
302+ accessorKey : 'actions' ,
303+ header : '' ,
304+ Cell : ( { row } : { row : { original : ReplicateType } } ) => (
305+ < Icons . TrashCan
306+ size = { 15 }
307+ style = { { cursor : 'pointer' } }
308+ onClick = { ( ) => handleClearOne ( row . original . replicateNumber ) }
309+ />
310+ ) ,
311+ enableEditing : false ,
312+ size : 40 ,
313+ ...alignRight
314+ }
315+ ] ;
0 commit comments