11import type { GridRow } from '../grid.js' ;
22import type { SeverityColour } from '../theme/types.js' ;
3- import type { MatrixDetail , MatrixSlotStyles } from '../types/index.js' ;
3+ import type { MatrixDetail , MatrixSlotStyles , ReactMatrixProps } from '../types/index.js' ;
44import TableData from './TableData.js' ;
55
66interface MatrixRowsProps {
7- title : string ;
7+ rowTitle : string ;
8+ columnTitle : string ;
89 columns : MatrixDetail [ ] ;
910 rows : GridRow [ ] ;
1011 tiers : ReadonlyMap < string , number > ;
1112 /** Severity colour per value id; `null` when unstyled. */
1213 colours : ReadonlyMap < number , SeverityColour > | null ;
1314 styles : MatrixSlotStyles ;
15+ onCellClick ?: ReactMatrixProps [ 'onCellClick' ] ;
1416}
1517
16- const MatrixRows = ( { title, columns, rows, tiers, colours, styles } : MatrixRowsProps ) => (
18+ const MatrixRows = ( {
19+ rowTitle,
20+ columnTitle,
21+ columns,
22+ rows,
23+ tiers,
24+ colours,
25+ styles,
26+ onCellClick,
27+ } : MatrixRowsProps ) => (
1728 < tbody >
1829 { rows . map ( ( { detail, cells } , rowIndex ) => (
1930 < tr key = { detail . id } data-row = { detail . likelihood } >
@@ -24,24 +35,38 @@ const MatrixRows = ({ title, columns, rows, tiers, colours, styles }: MatrixRows
2435 rowSpan = { rows . length }
2536 style = { styles . axisTitle }
2637 >
27- { title }
38+ { rowTitle }
2839 </ th >
2940 ) }
3041 < th className = "rdm-row-header" scope = "row" style = { styles . rowHeader } >
3142 { detail . row_header_title }
3243 < div className = "rdm-subtitle" > { detail . row_header_sub_title } </ div >
3344 </ th >
34- { cells . map ( ( value , columnIndex ) => (
35- < TableData
36- key = { value ?. id ?? `empty-${ columnIndex } ` }
37- value = { value }
38- row = { detail . likelihood }
39- column = { columns [ columnIndex ] . consequence }
40- tier = { value ? tiers . get ( value . colour ) : undefined }
41- colours = { value ? colours ?. get ( value . id ) : undefined }
42- style = { styles . cell }
43- />
44- ) ) }
45+ { cells . map ( ( value , columnIndex ) => {
46+ const column = columns [ columnIndex ] ;
47+ const interactive = value && onCellClick ;
48+ return (
49+ < TableData
50+ key = { value ?. id ?? `empty-${ columnIndex } ` }
51+ value = { value }
52+ row = { detail . likelihood }
53+ column = { column . consequence }
54+ tier = { value ? tiers . get ( value . colour ) : undefined }
55+ colours = { value ? colours ?. get ( value . id ) : undefined }
56+ style = { styles . cell }
57+ onActivate = {
58+ interactive
59+ ? ( event ) => onCellClick ( value , { row : detail , column, event } )
60+ : undefined
61+ }
62+ accessibleName = {
63+ interactive
64+ ? `${ rowTitle } ${ detail . row_header_title } , ${ columnTitle } ${ column . header_title } : ${ value . description } (${ value . score_value } )`
65+ : undefined
66+ }
67+ />
68+ ) ;
69+ } ) }
4570 </ tr >
4671 ) ) }
4772 </ tbody >
0 commit comments