Skip to content

Commit

Permalink
fixing ui, integrating with new server
Browse files Browse the repository at this point in the history
  • Loading branch information
armsp committed Aug 1, 2023
1 parent 9bca45b commit 67b592a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/components/CardGrid.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const CountryGrid = () => {
setTimeout(() => {
setCards(sortedCards);
setInTransition(false);
}, 500); // Adjust the duration as needed
}, 50); // Adjust the duration as needed
};

const handleSortByData = () => {
Expand Down
35 changes: 19 additions & 16 deletions src/components/CollapsibleTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import AnswerMe from './AnswerMe';
// ];
const Row = React.memo((props) => {
const { row, open, setOpen, collapseOthers } = props;

console.log(row);
const handleClick = () => {
if (collapseOthers) {
if (open === row.name) {
Expand Down Expand Up @@ -67,21 +67,20 @@ const Row = React.memo((props) => {
</TableCell>
<TableCell>{row.headline}</TableCell>
<TableCell>{row['media_org']}</TableCell>
<TableCell>{row.uri}</TableCell>
<TableCell>{row.score}</TableCell>
</TableRow>
<TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={3}>
<Collapse in={isOpen} timeout="auto" unmountOnExit>
<Box margin={1}>
<Box margin={1} sx={{ display: 'flex', flexWrap: 'nowrap', flexDirection: 'row'}}>
{/* {moredata.map((item, index) => (
<Typography key={index} variant="body1" component="div">
<strong>{Object.keys(item)[0]}:</strong> {Object.values(item)[0]}
</Typography>
))} */}
<List >
{
row['details'].map((item, index) => ([

row['q_as'].map((item, index) => ([
<ListItem key={index}
// primaryAction={
// Object.values(item)[0].tag.map(who => (
Expand All @@ -97,9 +96,10 @@ const Row = React.memo((props) => {
<>
{Object.values(item)[1]}
{" "}
{ Object.values(item)[2].map(who => (
{/* { Object.values(item)[2].map(who => (
<Chip label={who} color="info" sx={{borderRadius: 1}} size="small" variant="inset" component="span" />))
}
} */}
<Chip label="GPT-4" color="info" sx={{borderRadius: 1}} size="small" variant="inset" component="span" />
</>
}
/>
Expand All @@ -116,14 +116,12 @@ const Row = React.memo((props) => {
))}

</List>
{/* <Paper elevation={4}>
<Box p={2}>
<p>{row.details}</p>
<Button variant="contained" color="primary">
Click me
</Button>

<Box sx={{ width: 500, flexShrink: 1 }}>
<h3>Summary of the Article</h3>
<p>{row.summary}</p>
<p><a href={row.uri}>Link</a> to the article</p>
</Box>
</Paper> */}
</Box>
</Collapse>
</TableCell>
Expand Down Expand Up @@ -164,11 +162,16 @@ const CollapsibleTable = ({ collapseOthers = true, data }) => {
<TableContainer component={Paper}>
<Table>
<TableHead>
<TableRow>
<TableRow sx={{
"& th": {
color: "rgba(96, 96, 96)",
backgroundColor: "lightgrey"
}
}}>
<TableCell />
<TableCell>Headline</TableCell>
<TableCell>Media Org</TableCell>
<TableCell>Link</TableCell>
<TableCell>Score</TableCell>
</TableRow>
</TableHead>
<TableBody>
Expand Down
8 changes: 6 additions & 2 deletions src/components/CountryCommon.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -81,7 +85,7 @@ export default function CountryData({country}) {
(<p>No data found.</p>)
}

<ExportButton />
<ExportButton tablename={country} />
</Container>
<Footer2 />
</Box>
Expand Down
58 changes: 55 additions & 3 deletions src/components/Export.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<div>
{loading ? (
<CircularProgress />
) : (


<Button
// variant="contained"
// color="primary"
Expand All @@ -21,5 +71,7 @@ export default function ExportButton({ disabled }) {
>
Export Data
</Button>
)}
</div>
);
}

0 comments on commit 67b592a

Please sign in to comment.