@@ -79,20 +79,53 @@ PulseApp.ui.nodes = (() => {
79
79
console . error ( 'Critical element #nodes-table-body not found for nodes table update!' ) ;
80
80
return ;
81
81
}
82
- // tbody.innerHTML = ''; // Handled by renderTableBody
82
+ tbody . innerHTML = '' ; // Clear previous content
83
+
84
+ if ( ! nodes || nodes . length === 0 ) {
85
+ tbody . innerHTML = '<tr><td colspan="7" class="p-4 text-center text-gray-500 dark:text-gray-400">No nodes found or data unavailable</td></tr>' ;
86
+ return ;
87
+ }
88
+
89
+ // Group nodes by clusterIdentifier
90
+ const clusters = nodes . reduce ( ( acc , node ) => {
91
+ const key = node . clusterIdentifier || 'Unknown Cluster' ; // Fallback for safety
92
+ if ( ! acc [ key ] ) {
93
+ acc [ key ] = [ ] ;
94
+ }
95
+ acc [ key ] . push ( node ) ;
96
+ return acc ;
97
+ } , { } ) ;
83
98
84
99
const sortStateNodes = PulseApp . state . getSortState ( 'nodes' ) ;
85
- const dataToDisplay = PulseApp . utils . sortData ( nodes , sortStateNodes . column , sortStateNodes . direction , 'nodes' ) ;
86
100
87
- // if (dataToDisplay.length === 0) { // Handled by renderTableBody
88
- // tbody.innerHTML = '<tr><td colspan="7" class="p-4 text-center text-gray-500 dark:text-gray-400">No nodes found or data unavailable</td></tr>';
89
- // return;
90
- // }
101
+ // Iterate over each cluster group
102
+ for ( const clusterIdentifier in clusters ) {
103
+ if ( clusters . hasOwnProperty ( clusterIdentifier ) ) {
104
+ const nodesInCluster = clusters [ clusterIdentifier ] ;
105
+ // All nodes in this group should have the same endpointType, so pick from the first.
106
+ // Default to 'standalone' if nodesInCluster is empty or endpointType is missing for some reason.
107
+ const endpointType = ( nodesInCluster && nodesInCluster . length > 0 && nodesInCluster [ 0 ] . endpointType )
108
+ ? nodesInCluster [ 0 ] . endpointType
109
+ : 'standalone' ;
110
+
111
+ const iconSvg = endpointType === 'cluster'
112
+ ? PulseApp . ui . common . NODE_GROUP_CLUSTER_ICON_SVG
113
+ : PulseApp . ui . common . NODE_GROUP_STANDALONE_ICON_SVG ;
91
114
92
- // Use the utility function
93
- PulseApp . utils . renderTableBody ( tbody , dataToDisplay , createNodeRow , "No nodes found or data unavailable" , 7 ) ;
94
-
95
- // REMOVED: dataToDisplay.forEach(node => { ... tbody.appendChild(row); });
115
+ const clusterHeaderRow = document . createElement ( 'tr' ) ;
116
+ // Applying base background, then overlaying with stripe pattern classes
117
+ clusterHeaderRow . innerHTML = PulseApp . ui . common . generateNodeGroupHeaderCellHTML ( clusterIdentifier , 7 , 'th' ) ;
118
+ tbody . appendChild ( clusterHeaderRow ) ;
119
+
120
+ // Sort nodes within this cluster group
121
+ const sortedNodesInCluster = PulseApp . utils . sortData ( nodesInCluster , sortStateNodes . column , sortStateNodes . direction , 'nodes' ) ;
122
+
123
+ sortedNodesInCluster . forEach ( node => {
124
+ const nodeRow = createNodeRow ( node ) ;
125
+ tbody . appendChild ( nodeRow ) ;
126
+ } ) ;
127
+ }
128
+ }
96
129
}
97
130
98
131
return {
0 commit comments