|
1 |
| -// import { Typography } from "@mui/material"; |
2 |
| -// import React from "react"; |
| 1 | +import * as React from 'react'; |
| 2 | +import Box from '@mui/material/Box'; |
| 3 | +import Collapse from '@mui/material/Collapse'; |
| 4 | +import IconButton from '@mui/material/IconButton'; |
| 5 | +import Table from '@mui/material/Table'; |
| 6 | +import TableBody from '@mui/material/TableBody'; |
| 7 | +import TableCell from '@mui/material/TableCell'; |
| 8 | +import TableContainer from '@mui/material/TableContainer'; |
| 9 | +import TableHead from '@mui/material/TableHead'; |
| 10 | +import TableRow from '@mui/material/TableRow'; |
| 11 | +import Typography from '@mui/material/Typography'; |
| 12 | +import Paper from '@mui/material/Paper'; |
| 13 | +import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; |
| 14 | +import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; |
| 15 | +import CircularProgress from '@mui/material/CircularProgress'; |
3 | 16 |
|
| 17 | +function createRow(file: any, name: string, i: number) { |
| 18 | + const [open, setOpen] = React.useState(false); |
| 19 | + const inLoading = file?.stats?.malicious === undefined; |
| 20 | + const mali = inLoading ? <CircularProgress sx={{color:'#b3b3b5', size: '25'}} /> : file?.stats?.malicious ?? 0; |
| 21 | + |
| 22 | + return ( |
| 23 | + <React.Fragment key={i}> |
| 24 | + <TableRow sx={{borderBottom: 'none', paddingBottom: '2px'}}> |
| 25 | + <TableCell sx={{color: '#97D8C4', fontSize: '16px', borderBottom: 'none', paddingBottom: '3px'}} >{name}</TableCell> |
| 26 | + <TableCell align='left' sx={{color: file?.status === 'completed' ? '#97D8C4' : '#b3b3b5', borderBottom: 'none', paddingBottom: '3px',marginBottom: 'none', fontSize: '14px'}} >{file?.status || 'Scanning...'}</TableCell> |
| 27 | + <TableCell align='left' sx={{color: mali > 0 ? '#F56960' : '#97D8C4' , borderBottom: 'none', paddingBottom: '3px', width: 'auto', fontSize: '14px'}} >{mali}</TableCell> |
| 28 | + <TableCell sx={{borderBottom: 'none', paddingBottom: '3px'}}> |
| 29 | + {/* perhaps this below can be conditional if I find any errors. */} |
| 30 | + <IconButton onClick={() => setOpen(!open)}> |
| 31 | + {open ? <KeyboardArrowUpIcon sx={{color: '#b3b3b5'}} /> : <KeyboardArrowDownIcon sx={{color: mali > 0 ? '#F56960' : '#b3b3b5'}} />} |
| 32 | + </IconButton> |
| 33 | + </TableCell> |
| 34 | + </TableRow> |
| 35 | + <TableRow> |
| 36 | + <TableCell colSpan={3} sx={{ |
| 37 | + // bgcolor: 'purple', |
| 38 | + height: open ? 'auto' : '0', |
| 39 | + padding: open ? '8px' : '0', |
| 40 | + paddingTop: '0', |
| 41 | + marginTop: '0', |
| 42 | + borderBottom: 'none', |
| 43 | + overflow: 'hidden', |
| 44 | + transition: 'height 0.3s ease, padding 0.3s ease', |
| 45 | + }}> |
| 46 | + <Collapse in={open} sx={{ |
| 47 | + margin: '0', |
| 48 | + borderBottom: 'none', |
| 49 | + // bgcolor: 'purple', |
| 50 | + padding: '1px', |
| 51 | + }}> |
| 52 | + {file?.stats?.malicious > 0 ? ( |
| 53 | + Object.entries(file.results).filter(([key, scan]:[string, any], index: number) => |
| 54 | + scan.category === 'malicious').map(([key, scan]:[string, any], index) => { |
| 55 | + return <Box key={index}><strong>{scan.engine_name}</strong> found {scan.category}: {scan.result}</Box>; |
| 56 | + }) |
| 57 | + ) : ( |
| 58 | + <Typography sx={{color: '#b3b3b5', fontSize: '14px', marginTop: 'none', paddingLeft: '20px', paddingTop: '0px'}}>No threats found</Typography> |
| 59 | + )} |
| 60 | + </Collapse> |
| 61 | + </TableCell> |
| 62 | + </TableRow> |
| 63 | + </React.Fragment> |
| 64 | + ); |
| 65 | +} |
| 66 | +export default function VirusTotalResults(props: any) { |
| 67 | + const { VTResults, keyError } = props; |
| 68 | + console.log('these are the VTResults in virus total results: ', VTResults); |
| 69 | + |
| 70 | + if (!VTResults || Object.keys(VTResults).length === 0 || keyError === true) { |
| 71 | + return null; |
| 72 | + } else if (VTResults) { |
| 73 | + return ( |
| 74 | + <TableContainer component={Paper} sx={{bgcolor: '#3D3D3D'}} > |
| 75 | + <Table aria-label="collapsible table" sx={{ |
| 76 | + // '& .MuiTableRow-root': { height: '36px', margin: '0px'}, |
| 77 | + // '& .MuiTableCell-root': { padding: '0px 4px', margin: '0px' }, |
| 78 | + }}> |
| 79 | + <TableHead> |
| 80 | + <TableRow > |
| 81 | + {/* <TableCell /> */} |
| 82 | + <TableCell sx={{color: '#97D8C4', fontWeight: 'bold', fontSize: '20px'}}>File Name</TableCell> |
| 83 | + <TableCell sx={{color: '#97D8C4', fontWeight: 'bold', marginTop: '0px', fontSize: '20px'}} align="left">Status</TableCell> |
| 84 | + <TableCell sx={{color: '#97D8C4', fontWeight: 'bold', fontSize: '20px'}} align="left">Potential Threats Found</TableCell> |
| 85 | + {/* <TableCell align="right">Carbs (g)</TableCell> |
| 86 | + <TableCell align="right">Protein (g)</TableCell> */} |
| 87 | + </TableRow> |
| 88 | + </TableHead> |
| 89 | + <TableBody > |
| 90 | + { Object.keys(VTResults).map((key, i)=> { |
| 91 | + return createRow(VTResults[key], key, i); |
| 92 | + })} |
| 93 | + </TableBody> |
| 94 | + </Table> |
| 95 | + </TableContainer> |
| 96 | + ); |
| 97 | + } |
| 98 | +} |
0 commit comments