navinko commented on code in PR #10076:
URL: https://github.com/apache/ozone/pull/10076#discussion_r3221761432
##########
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:
Good catch! I missed this scenario of empty list .
In the existing code,the pagination logic is implemented in two separate
places:
Once for the initial page load
https://github.com/navinko/ozone/blob/master/hadoop-hdds/server-scm/src/main/resources/webapps/scm/scm.js#L166-L167
> $scope.totalItems = nodeStatusCopy.length;
**$scope.lastIndex = Math.ceil(nodeStatusCopy.length /
$scope.RecordsToDisplay);**
$scope.nodeStatus = nodeStatusCopy.slice(0, $scope.RecordsToDisplay);
and once user clicks for the dropdown updates.
https://github.com/navinko/ozone/blob/master/hadoop-hdds/server-scm/src/main/resources/webapps/scm/scm.js#L253-L254
> $scope.UpdateRecordsToShow = () => {
if($scope.RecordsToDisplay == 'All') {
$scope.lastIndex = 1;
$scope.nodeStatus = nodeStatusCopy;
} else {
**$scope.lastIndex = Math.ceil(nodeStatusCopy.length /
$scope.RecordsToDisplay);**
$scope.nodeStatus = nodeStatusCopy.slice(0,
$scope.RecordsToDisplay);
}
$scope.currentPage = 1;
}
In both places, if nodeStatusCopy.length would be 0, (cluster with empty
datanode list ) the lastIndex evaluated to 0. Since currentPage resets to 1,
the lastIndex == currentPage check failed and did not disbale next button
leaving the UI broken at "Page 1 of 0" with an active Next button.
In order to fix that used math.max(1,0) logic which will return lastIndex to
one during both the cases, fresh load with empty datanode list and once user
updates the dropdown. I updated the UpdateRecordsToShow() function to use
Math.max(1, Math.ceil(...)) so lastIndex is forced to always be at least 1.
Also, resued UpdateRecordsToShow on initial page load and avoided same logic
both place. Now, the initial load just calls the fixed UpdateRecordsToShow()
function so everything shares the exact same logic.
This way, any empty result (whether from a search or an empty cluster)
safely clamps to "Page 1 of 1" and correctly disables the Next button!
<img width="1155" height="218" alt="3"
src="https://github.com/user-attachments/assets/f553e313-fdc8-4fa0-95ae-4367583b8d44"
/>
<img width="1136" height="279" alt="4"
src="https://github.com/user-attachments/assets/4ae7b8e2-8edc-4338-9b55-940243ad3ecc"
/>
<img width="1120" height="217" alt="5"
src="https://github.com/user-attachments/assets/8772cebb-9982-46b9-8d54-3210beef6ac3"
/>
--
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]