55 Tbody ,
66 Td ,
77 TdProps ,
8+ Tr ,
89 TreeRowWrapper ,
910} from '@patternfly/react-table' ;
1011import { useInternalContext } from '../InternalContext' ;
@@ -34,6 +35,8 @@ export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'r
3435 columns : DataViewTh [ ] ;
3536 /** Current page rows */
3637 rows : DataViewTrTree [ ] ;
38+ /** Empty state to be displayed */
39+ emptyState ?: React . ReactNode ;
3740 /** Optional icon for the leaf rows */
3841 leafIcon ?: React . ReactNode ;
3942 /** Optional icon for the expanded parent rows */
@@ -47,6 +50,7 @@ export interface DataViewTableTreeProps extends Omit<TableProps, 'onSelect' | 'r
4750export const DataViewTableTree : React . FC < DataViewTableTreeProps > = ( {
4851 columns,
4952 rows,
53+ emptyState = null ,
5054 leafIcon = null ,
5155 expandedIcon = null ,
5256 collapsedIcon = null ,
@@ -99,7 +103,6 @@ export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
99103 'aria-posinset' : posinset ,
100104 'aria-setsize' : node . children ?. length ?? 0 ,
101105 isChecked,
102- ouiaId : `${ ouiaId } -tree-toggle-${ node . id } ` ,
103106 checkboxId : `checkbox_id_${ node . id ?. toLowerCase ( ) . replace ( / \s + / g, '_' ) } ` ,
104107 icon,
105108 } ,
@@ -110,7 +113,7 @@ export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
110113 : [ ] ;
111114
112115 return [
113- < TreeRowWrapper key = { node . id } row = { { props : treeRow . props } } >
116+ < TreeRowWrapper key = { node . id } row = { { props : treeRow . props } } ouiaId = { ` ${ ouiaId } -tr- ${ rowIndex } ` } >
114117 { node . row . map ( ( cell , colIndex ) => {
115118 const cellIsObject = isDataViewTdObject ( cell ) ;
116119 return (
@@ -136,7 +139,15 @@ export const DataViewTableTree: React.FC<DataViewTableTreeProps> = ({
136139 return (
137140 < Table isTreeTable aria-label = "Data table" ouiaId = { ouiaId } { ...props } >
138141 < DataViewTableHeader isTreeTable columns = { columns } ouiaId = { ouiaId } />
139- < Tbody > { nodes } </ Tbody >
142+ < Tbody >
143+ { nodes . length > 0 ? nodes : (
144+ < Tr key = "empty" ouiaId = { `${ ouiaId } -tr-empty` } >
145+ < Td colSpan = { columns . length } >
146+ { emptyState }
147+ </ Td >
148+ </ Tr >
149+ ) }
150+ </ Tbody >
140151 </ Table >
141152 ) ;
142153} ;
0 commit comments