smengcl commented on code in PR #10076:
URL: https://github.com/apache/ozone/pull/10076#discussion_r3199108286


##########
hadoop-hdds/server-scm/src/main/resources/webapps/scm/scm.js:
##########
@@ -218,28 +221,48 @@
                     $scope.statistics.containers.health.open_without_pipeline 
= ctrl.scmcontainermanager.OpenContainersWithoutPipeline;
                 });
 
-            /*if option is 'All' display all records else display specified 
record on page*/
-            $scope.UpdateRecordsToShow = () => {
-                if($scope.RecordsToDisplay == 'All') {
-                    $scope.lastIndex = 1;
-                    $scope.nodeStatus = nodeStatusCopy;
+            /* Global Search Logic */
+            $scope.applyGlobalSearch = function() {
+                if (!$scope.search || $scope.search.trim() === "") {
+                    // Reset to full list if search is empty
+                    $scope.filteredNodes = [...nodeStatusCopy];
                 } else {
-                    $scope.lastIndex = Math.ceil(nodeStatusCopy.length / 
$scope.RecordsToDisplay);
-                    $scope.nodeStatus = nodeStatusCopy.slice(0, 
$scope.RecordsToDisplay);
-                }
-                $scope.currentPage = 1;
-            }
-            /* Page Slicing  logic */
-            $scope.handlePagination = (pageIndex, isDisabled) => {
-                if(!isDisabled && $scope.RecordsToDisplay != 'All') {
-                    pageIndex = parseInt(pageIndex);
-                    let startIndex = 0, endIndex = 0;
-                    $scope.currentPage = pageIndex;
-                    startIndex = ($scope.currentPage - 1) * 
parseInt($scope.RecordsToDisplay);
-                    endIndex = startIndex + parseInt($scope.RecordsToDisplay);
-                    $scope.nodeStatus = nodeStatusCopy.slice(startIndex, 
endIndex);
+                    let query = $scope.search.toLowerCase();
+                    // Filter the master list
+                    $scope.filteredNodes = 
nodeStatusCopy.filter(function(node) {
+                        return (node.hostname && 
node.hostname.toLowerCase().includes(query)) ||
+                               (node.opstate && 
node.opstate.toLowerCase().includes(query)) ||
+                               (node.comstate && 
node.comstate.toLowerCase().includes(query)) ||
+                               (node.uuid && 
node.uuid.toLowerCase().includes(query));
+                    });

Review Comment:
   This should also cover other fields like Used Space Percent / Capacity / 
Last Heartbeat to match original search behavior?
   
   Or even better for maintenance: is it possible to match the whole row 
without having to specify each in case we add new columns in the future but 
forget to change the code here?



##########
hadoop-hdds/server-scm/src/main/resources/webapps/scm/scm.js:
##########
@@ -218,28 +221,48 @@
                     $scope.statistics.containers.health.open_without_pipeline 
= ctrl.scmcontainermanager.OpenContainersWithoutPipeline;
                 });
 
-            /*if option is 'All' display all records else display specified 
record on page*/
-            $scope.UpdateRecordsToShow = () => {
-                if($scope.RecordsToDisplay == 'All') {
-                    $scope.lastIndex = 1;
-                    $scope.nodeStatus = nodeStatusCopy;
+            /* Global Search Logic */
+            $scope.applyGlobalSearch = function() {
+                if (!$scope.search || $scope.search.trim() === "") {
+                    // Reset to full list if search is empty
+                    $scope.filteredNodes = [...nodeStatusCopy];
                 } else {
-                    $scope.lastIndex = Math.ceil(nodeStatusCopy.length / 
$scope.RecordsToDisplay);
-                    $scope.nodeStatus = nodeStatusCopy.slice(0, 
$scope.RecordsToDisplay);
-                }
-                $scope.currentPage = 1;
-            }
-            /* Page Slicing  logic */
-            $scope.handlePagination = (pageIndex, isDisabled) => {
-                if(!isDisabled && $scope.RecordsToDisplay != 'All') {
-                    pageIndex = parseInt(pageIndex);
-                    let startIndex = 0, endIndex = 0;
-                    $scope.currentPage = pageIndex;
-                    startIndex = ($scope.currentPage - 1) * 
parseInt($scope.RecordsToDisplay);
-                    endIndex = startIndex + parseInt($scope.RecordsToDisplay);
-                    $scope.nodeStatus = nodeStatusCopy.slice(startIndex, 
endIndex);
+                    let query = $scope.search.toLowerCase();
+                    // Filter the master list
+                    $scope.filteredNodes = 
nodeStatusCopy.filter(function(node) {
+                        return (node.hostname && 
node.hostname.toLowerCase().includes(query)) ||
+                               (node.opstate && 
node.opstate.toLowerCase().includes(query)) ||
+                               (node.comstate && 
node.comstate.toLowerCase().includes(query)) ||
+                               (node.uuid && 
node.uuid.toLowerCase().includes(query));
+                    });
                 }
-            }
+                $scope.totalItems = $scope.filteredNodes.length;
+                $scope.UpdateRecordsToShow(); // Re-calculate pagination
+            };
+             /* If option is 'All' display all records, else display specified 
records on page */
+             $scope.UpdateRecordsToShow = () => {
+                 if ($scope.RecordsToDisplay === 'All') {
+                     $scope.lastIndex = 1;
+                     $scope.nodeStatus = $scope.filteredNodes;
+                 } else {
+                     let limit = parseInt($scope.RecordsToDisplay);
+                     $scope.lastIndex = Math.ceil($scope.filteredNodes.length 
/ limit);
+                     $scope.nodeStatus = $scope.filteredNodes.slice(0, limit);
+                 }
+                 $scope.currentPage = 1;

Review Comment:
   What should the pager do when the search returns no rows? In that case 
filteredNodes.length is 0, so lastIndex is 0 but currentPage is still reset to 
1. That leaves the UI in an invalid state (Page: of 0) and Next stays enabled 
because it only checks lastIndex == currentPage.
   
   Can we clamp or hide pagination for the empty-results case?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to