diff --git a/src/components/CountryCommon.jsx b/src/components/CountryCommon.jsx
index a63f333..59eb7af 100644
--- a/src/components/CountryCommon.jsx
+++ b/src/components/CountryCommon.jsx
@@ -42,11 +42,15 @@ export default function CountryData({country}) {
method: 'GET', // or 'PUT'
});
const json = await response.json();
- console.log(json);
+ // console.log(json);
setData(json);
+ // console.log(json);
setLoading(false);
+ // console.log(JSON.parse(data["records"][0]));
+
} catch (error) {
setError(error);
+ console.log("ERROR"+ error);
setLoading(false);
}
}
@@ -81,7 +85,7 @@ export default function CountryData({country}) {
(No data found.
)
}
-
+
diff --git a/src/components/Export.jsx b/src/components/Export.jsx
index a754f7f..72b9f89 100644
--- a/src/components/Export.jsx
+++ b/src/components/Export.jsx
@@ -2,13 +2,63 @@
// it is disabled when there is no data to export
import React from 'react';
import { Button } from '@mui/material';
+import { useEffect, useState } from 'react';
+import { Box, CircularProgress } from "@mui/material";
import FileDownloadRoundedIcon from '@mui/icons-material/FileDownloadRounded';
-export default function ExportButton({ disabled }) {
- const exportData = () => {
+
+export default function ExportButton({ disabled, tablename }) {
+ const [loading, setLoading] = useState(false);
+
+ const exportData = async () => {
console.log("calling mongodb export api");
- }
+
+ try {
+ setLoading(true);
+
+ // Make the API call to the "/export" endpoint
+ const response = await fetch('https://aifuv2.eastus.azurecontainer.io/export?'+ new URLSearchParams({
+ table_name: tablename}), {
+ method: 'GET',
+ });
+
+ if (!response.ok) {
+ throw new Error('Failed to fetch the export data.');
+ }
+
+ // Extract the filename from the response headers
+ const contentDisposition = response.headers.get('content-disposition');
+ const filenameMatch = contentDisposition && contentDisposition.match(/filename="(.+)"/);
+ const filename = filenameMatch ? filenameMatch[1] : 'exported-data.json';
+
+ // Convert the response to a Blob
+ const blob = await response.blob();
+
+ // Create a temporary URL for the Blob
+ const url = URL.createObjectURL(blob);
+
+ // Create a link element to download the file
+ const link = document.createElement('a');
+ link.href = url;
+ link.download = filename;
+
+ // Trigger the click event on the link to download the file
+ link.click();
+
+ setLoading(false);
+ } catch (error) {
+ console.error(error);
+ setLoading(false);
+ }
+ };
+
return (
+
+ {loading ? (
+
+ ) : (
+
+
+ )}
+
);
}