ArafatKhan2198 commented on code in PR #9994:
URL: https://github.com/apache/ozone/pull/9994#discussion_r3121974739


##########
hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/v2/pages/containers/containers.tsx:
##########
@@ -175,6 +178,99 @@ const Containers: React.FC<{}> = () => {
     5: mismatchedReplicaContainerData
   }
 
+  // Mapping tab keys to the backend state parameter for CSV export
+  const tabToExportState: Record<string, string> = {
+    '1': 'MISSING',
+    '2': 'UNDER_REPLICATED',
+    '3': 'OVER_REPLICATED',
+    '4': 'MIS_REPLICATED',
+    '5': 'REPLICA_MISMATCH'
+  };
+
+  // Human-readable labels for the export tooltip
+  const tabToLabel: Record<string, string> = {
+    '1': 'Missing',
+    '2': 'Under-Replicated',
+    '3': 'Over-Replicated',
+    '4': 'Mis-Replicated',
+    '5': 'Mismatched Replicas'
+  };
+
+  const handleExportCsv = useCallback(async () => {
+    const state = tabToExportState[selectedTab];
+    const label = tabToLabel[selectedTab];
+
+    if (exportLimit > 0 && exportLimit <= 500000) {
+      const exportUrl = 
`/api/v1/containers/unhealthy/export?state=${state}&limit=${exportLimit}`;
+      window.open(exportUrl, '_blank');
+      message.success(`Exporting ${label} containers as CSV (Limit: 
${exportLimit})`);
+      return;
+    }
+
+    const chunkSize = 500000;
+    let prevKey = 0;
+    let part = 1;
+    let totalExported = 0;
+    const hideMessage = message.loading(`Starting export of ${label} 
containers in chunks...`, 0);
+
+    try {
+      while (true) {
+        const currentLimit = exportLimit === 0 ? chunkSize : 
Math.min(chunkSize, exportLimit - totalExported);
+        if (currentLimit <= 0) break;
+
+        const exportUrl = 
`/api/v1/containers/unhealthy/export?state=${state}&limit=${currentLimit}&prevKey=${prevKey}`;
+        const response = await fetch(exportUrl);
+        
+        if (!response.ok) {
+          throw new Error(`Failed to fetch part ${part}`);
+        }
+
+        const text = await response.text();
+        const lines = text.trim().split('\n');
+        
+        // lines[0] is header. If only header, no data.
+        if (lines.length <= 1) {
+          break;
+        }
+
+        const blob = new Blob([text], { type: 'text/csv' });
+        const url = window.URL.createObjectURL(blob);
+        const a = document.createElement('a');
+        a.href = url;
+        a.download = 
`unhealthy_containers_${state.toLowerCase()}_part${part}.csv`;
+        document.body.appendChild(a);
+        a.click();
+        document.body.removeChild(a);
+        window.URL.revokeObjectURL(url);
+
+        const recordsInChunk = lines.length - 1;
+        totalExported += recordsInChunk;
+        
+        const lastLine = lines[lines.length - 1];
+        const lastContainerId = parseInt(lastLine.split(',')[0], 10);

Review Comment:
   Fixed! 
   Instead of parsing the CSV body to extract the last container ID, the 
backend now sends it as an X-Last-Container-Id response header. The frontend 
reads that header directly hence no CSV parsing needed at all.



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