@@ -5,15 +5,15 @@ import {
55 getHeaderSubTitleStyles ,
66 getHeaderPrimaryTitleStyles ,
77} from '../helpers/getStyles.js' ;
8- import { groupObjectsByProp , capitaliseString } from '../utils/functions.js' ;
8+ import { capitaliseString } from '../utils/functions.js' ;
99import TableData from './TableData.js' ;
10- import { MatrixRowsProps , MatrixValue } from '../types/index.js' ;
10+ import { MatrixRowsProps } from '../types/index.js' ;
1111
1212const MatrixRows : FC < MatrixRowsProps > = ( {
1313 data,
14+ rows,
1415 rowPrimaryUpper = true ,
1516 hasInlineStyles = true ,
16- reverseMatrixValues = true ,
1717 trRowStyles = { } ,
1818 trTitleStyles = { } ,
1919 trSubTitleStyles = { } ,
@@ -23,15 +23,6 @@ const MatrixRows: FC<MatrixRowsProps> = ({
2323 customRowHeaderDynamicIdValue = '' ,
2424 customTableDataDynamicIdValue = '' ,
2525} : MatrixRowsProps ) => {
26- const valuesArray = reverseMatrixValues
27- ? groupObjectsByProp ( data . matrix_values , 'likelihood_descriptor' )
28- . reverse ( )
29- . slice ( 0 , data . matrix_size )
30- : groupObjectsByProp ( data . matrix_values , 'likelihood_descriptor' ) . slice (
31- 0 ,
32- data . matrix_size
33- ) ;
34-
3526 const tableRowStyles = getHeaderRowStyles ( hasInlineStyles , trRowStyles ) ;
3627 const tableRowHeaderTitleStyles = getHeaderTitleStyles (
3728 hasInlineStyles ,
@@ -53,59 +44,53 @@ const MatrixRows: FC<MatrixRowsProps> = ({
5344 return (
5445 < tbody >
5546 < tr id = "react-matrix-row-primary-title" >
56- < th scope = "row" rowSpan = { 6 } style = { rowHeaderPrimaryTitleStyles } >
47+ < th
48+ scope = "row"
49+ rowSpan = { rows . length + 1 }
50+ style = { rowHeaderPrimaryTitleStyles }
51+ >
5752 { rowPrimaryTitle }
5853 </ th >
5954 </ tr >
60- { valuesArray . map ( ( row , index ) => {
61- const rowHeaderOrder = reverseMatrixValues
62- ? data . matrix_size - ( index + 1 )
63- : index ;
64-
65- return (
66- < tr
67- style = { tableRowStyles }
68- key = { `row-${ index } ` }
69- id = { `react-matrix-dynamic-rows-${
70- data . matrix_details [ rowHeaderOrder ] ?. row_header_title
71- } -${ data . matrix_details [ rowHeaderOrder ] ?. row_header_sub_title } ${
72- ! customRowDynamicIdValue ? '' : `-${ customRowDynamicIdValue } `
55+ { rows . map ( ( { detail, cells } ) => (
56+ < tr
57+ style = { tableRowStyles }
58+ key = { detail . id }
59+ id = { `react-matrix-dynamic-rows-${ detail . row_header_title } -${
60+ detail . row_header_sub_title
61+ } ${ ! customRowDynamicIdValue ? '' : `-${ customRowDynamicIdValue } ` } `}
62+ >
63+ < th
64+ scope = "row"
65+ style = { tableRowHeaderTitleStyles }
66+ id = { `react-matrix-dynamic-rows-${ detail . row_header_title } -${
67+ detail . row_header_sub_title
68+ } ${
69+ ! customRowHeaderDynamicIdValue
70+ ? ''
71+ : `-${ customRowHeaderDynamicIdValue } `
7372 } `}
7473 >
75- < th
76- scope = "row"
77- style = { tableRowHeaderTitleStyles }
78- id = { `react-matrix-dynamic-rows-${
79- data . matrix_details [ rowHeaderOrder ] ?. row_header_title
80- } -${ data . matrix_details [ rowHeaderOrder ] ?. row_header_sub_title } ${
81- ! customRowHeaderDynamicIdValue
82- ? ''
83- : `-${ customRowHeaderDynamicIdValue } `
84- } `}
85- >
86- { data . matrix_details [ rowHeaderOrder ] ?. row_header_title }
87- < div style = { tableRowHeaderSubTitleStyles } >
88- { data . matrix_details [ rowHeaderOrder ] ?. row_header_sub_title }
89- </ div >
90- </ th >
91- { row
92- . slice ( 0 , data . matrix_size )
93- . map ( ( item : MatrixValue , index : number ) => {
94- return (
95- < TableData
96- data = { item }
97- tdStyles = { tdStyles }
98- key = { `${ item . id } -${ index } ` }
99- hasInlineStyles = { hasInlineStyles }
100- customTableDataDynamicIdValue = {
101- customTableDataDynamicIdValue
102- }
103- />
104- ) ;
105- } ) }
106- </ tr >
107- ) ;
108- } ) }
74+ { detail . row_header_title }
75+ < div style = { tableRowHeaderSubTitleStyles } >
76+ { detail . row_header_sub_title }
77+ </ div >
78+ </ th >
79+ { cells . map ( ( cell , index ) =>
80+ cell ? (
81+ < TableData
82+ data = { cell }
83+ tdStyles = { tdStyles }
84+ key = { cell . id }
85+ hasInlineStyles = { hasInlineStyles }
86+ customTableDataDynamicIdValue = { customTableDataDynamicIdValue }
87+ />
88+ ) : (
89+ < td key = { `empty-${ index } ` } />
90+ )
91+ ) }
92+ </ tr >
93+ ) ) }
10994 </ tbody >
11095 ) ;
11196} ;
0 commit comments