retropilot-client/src/components/device/tabPane/crash.jsx

110 lines
3.5 KiB
React
Raw Normal View History

2022-01-09 09:52:29 -07:00
// eslint-disable-next-line react-hooks/exhaustive-deps
2022-01-07 10:42:39 -07:00
import DeleteIcon from '@mui/icons-material/Delete';
import FavoriteBorderIcon from '@mui/icons-material/FavoriteBorder';
import OpenInNewIcon from '@mui/icons-material/OpenInNew';
import { Skeleton } from '@mui/material';
2022-01-03 09:30:54 -07:00
import Box from '@mui/material/Box';
import IconButton from '@mui/material/IconButton';
import Paper from '@mui/material/Paper';
2022-01-03 09:30:54 -07:00
import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody';
import TableCell from '@mui/material/TableCell';
import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow';
2022-01-05 09:55:56 -07:00
import Tooltip from '@mui/material/Tooltip';
import React, { useContext, useEffect } from 'react';
2022-01-09 09:52:29 -07:00
import { context as DeviceContext } from '../../../context/devices';
import * as deviceController from '../../../controllers/devices';
import * as helpers from '../../../controllers/helpers';
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
function buildContent(row) {
2022-01-03 09:30:54 -07:00
return (
2022-01-07 10:59:15 -07:00
<TableRow
2022-01-05 09:55:56 -07:00
hover
2022-01-03 09:30:54 -07:00
>
2022-01-09 09:52:29 -07:00
<TableCell>{helpers.formatDate(row.date)}</TableCell>
<TableCell>{row.name}</TableCell>
<TableCell>{`${Math.round(row.size / 1024)} MiB`}</TableCell>
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
<TableCell>
<Tooltip title="Open in new window">
2022-01-09 09:52:29 -07:00
<IconButton size="small" onClick={() => window.open(row.permalink, '_blank')}>
2022-01-05 09:55:56 -07:00
<OpenInNewIcon fontSize="inherit" />
</IconButton>
</Tooltip>
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
<Tooltip title="Preserve">
<IconButton size="small">
<FavoriteBorderIcon fontSize="inherit" />
</IconButton>
</Tooltip>
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
<Tooltip title="Delete">
<IconButton size="small">
<DeleteIcon fontSize="inherit" />
</IconButton>
</Tooltip>
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
</TableCell>
</TableRow>
2022-01-09 09:52:29 -07:00
);
2022-01-05 09:55:56 -07:00
}
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
function loading() {
return (
<TableRow>
2022-01-09 09:52:29 -07:00
<TableCell><Skeleton animation="wave" /></TableCell>
<TableCell><Skeleton animation="wave" /></TableCell>
<TableCell><Skeleton animation="wave" /></TableCell>
<TableCell><Skeleton animation="wave" /></TableCell>
2022-01-05 09:55:56 -07:00
</TableRow>
2022-01-09 09:52:29 -07:00
);
2022-01-05 09:55:56 -07:00
}
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
export default function EnhancedTable(props) {
2022-01-07 10:42:39 -07:00
// eslint-disable-next-line no-unused-vars
2022-01-09 09:52:29 -07:00
const [state, dispatch] = useContext(DeviceContext);
2022-01-05 09:55:56 -07:00
useEffect(() => {
deviceController.getCrashlogs(props.dongleId).then((res) => {
2022-01-09 09:52:29 -07:00
dispatch({ type: 'update_dongle_bootlogs', dongle_id: props.dongleId, bootlogs: res.data });
});
2022-01-07 08:52:41 -07:00
}, [dispatch, props.dongleId]);
2022-01-03 09:30:54 -07:00
2022-01-09 09:52:29 -07:00
console.log('drives', state.dongles[props.dongleId]);
console.log('drives', typeof state.dongles[props.dongleId]);
2022-01-03 09:30:54 -07:00
return (
<Box sx={{ width: '100%' }}>
<Paper sx={{ width: '100%', mb: 2 }}>
<TableContainer>
<Table
sx={{ minWidth: 750 }}
aria-labelledby="tableTitle"
2022-01-09 09:52:29 -07:00
size="small"
2022-01-03 09:30:54 -07:00
>
2022-01-05 09:55:56 -07:00
<TableHead>
<TableRow>
2022-01-09 09:52:29 -07:00
<TableCell>Date</TableCell>
<TableCell>File</TableCell>
<TableCell>File size</TableCell>
<TableCell>Actions</TableCell>
2022-01-05 09:55:56 -07:00
</TableRow>
</TableHead>
2022-01-03 09:30:54 -07:00
2022-01-05 09:55:56 -07:00
<TableBody>
2022-01-09 09:52:29 -07:00
{state.dongles[props.dongleId].crash
? state.dongles[props.dongleId].crash.length > 0 ? state.dongles[props.dongleId].crash.map(buildContent) : <p> No drives </p>
: [1, 1, 1, 1, 1].map(loading)}
2022-01-03 09:30:54 -07:00
</TableBody>
</Table>
</TableContainer>
2022-01-05 09:55:56 -07:00
2022-01-03 09:30:54 -07:00
</Paper>
</Box>
);
}