spacemonkd commented on code in PR #10615:
URL: https://github.com/apache/ozone/pull/10615#discussion_r3534986577


##########
hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/pages/capacity/capacity.tsx:
##########
@@ -90,15 +90,24 @@ const Capacity: React.FC<object> = () => {
     }
   );
 
-  const [selectedDatanode, setSelectedDatanode] = 
React.useState<string>(storageDistribution.data.dataNodeUsage[0]?.hostName ?? 
"");
+  const [selectedDatanode, setSelectedDatanode] = React.useState<string>("");
+
+  // Only show DNs that appear in the pending deletion response (max 15), so 
the
+  // dropdown and the pending-block-size values are always in sync.
+  const filteredDNs = React.useMemo(() => {
+    const pendingHostNames = new Set(
+      (dnPendingDeletes.data.pendingDeletionPerDataNode ?? []).map(dn => 
dn.hostName)
+    );
+    return storageDistribution.data.dataNodeUsage.filter(dn => 
pendingHostNames.has(dn.hostName));
+  }, [storageDistribution.data.dataNodeUsage, 
dnPendingDeletes.data.pendingDeletionPerDataNode]);
 
   // Seed selected datanode once data loads so dependent calculations work
   React.useEffect(() => {
-    const firstHost = storageDistribution.data.dataNodeUsage[0]?.hostName;
+    const firstHost = filteredDNs[0]?.hostName;
     if (!selectedDatanode && firstHost) {
       setSelectedDatanode(firstHost);
     }
-  }, [selectedDatanode, storageDistribution.data.dataNodeUsage]);
+  }, [selectedDatanode, filteredDNs]);

Review Comment:
   There is a possible bug in the existing code. Once `selectedDatanode` is 
set, it's never reset — even if the DN disappears from filteredDNs on a 
subsequent poll response. If a previously-selected DN drops out of the top-15 
on the next fetch, the dropdown shows a stale selection.
   
   ```suggestion
   React.useEffect(() => {
     const hostNames = filteredDNs.map(dn => dn.hostName);
     if (!hostNames.includes(selectedDatanode)) {
       setSelectedDatanode(hostNames[0] ?? "");
     }
   }, [filteredDNs]);
   ```



-- 
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