Merge pull request #246 from bluewave-labs/feat/incidents-pg-refactor

Incidents page refactor.
This commit is contained in:
Alexander Holliday authored and GitHub committed 2024-07-03 13:23:08 -07:00
commit 6f4e7d6631
1 file changed
+105 -10
+105 -10
View File
@@ -1,4 +1,7 @@
import { styled } from '@mui/material/styles'; import * as React from 'react';
import TextField from '@mui/material/TextField';
import Autocomplete, { createFilterOptions } from '@mui/material/Autocomplete';
import { styled, useTheme } from '@mui/material/styles';
import Table from '@mui/material/Table'; import Table from '@mui/material/Table';
import TableBody from '@mui/material/TableBody'; import TableBody from '@mui/material/TableBody';
import TableCell, { tableCellClasses } from '@mui/material/TableCell'; import TableCell, { tableCellClasses } from '@mui/material/TableCell';
@@ -6,9 +9,16 @@ import TableContainer from '@mui/material/TableContainer';
import TableHead from '@mui/material/TableHead'; import TableHead from '@mui/material/TableHead';
import TableRow from '@mui/material/TableRow'; import TableRow from '@mui/material/TableRow';
import Paper from '@mui/material/Paper'; import Paper from '@mui/material/Paper';
import Box from '@mui/material/Box';
import Typography from '@mui/material/Typography';
import { StatusLabel } from "../../Components/Label/"; import { StatusLabel } from "../../Components/Label/";
import TuneIcon from '@mui/icons-material/Tune';
/**
* Creates a styled TableCell component.
* @param {object} theme - The theme object.
* @returns {JSX.Element} The styled TableCell component.
*/
const StyledTableCell = styled(TableCell)(({ theme }) => ({ const StyledTableCell = styled(TableCell)(({ theme }) => ({
[`&.${tableCellClasses.head}`]: { [`&.${tableCellClasses.head}`]: {
backgroundColor: theme.palette.action.hover, backgroundColor: theme.palette.action.hover,
@@ -19,11 +29,16 @@ const StyledTableCell = styled(TableCell)(({ theme }) => ({
}, },
})); }));
/**
* Creates a styled TableRow component.
* @param {object} theme - The theme object.
* @returns {JSX.Element} The styled TableRow component.
*/
const StyledTableRow = styled(TableRow)(({ theme }) => ({ const StyledTableRow = styled(TableRow)(({ theme }) => ({
'&:nth-of-type(1)': { '&:nth-of-type(odd)': {
backgroundColor: theme.palette.action.hover, backgroundColor: theme.palette.action.hover,
}, },
'&:nth-of-type(n+1)': { '&:nth-of-type(even)': {
backgroundColor: theme.palette.common.white, backgroundColor: theme.palette.common.white,
}, },
'&:last-child td, &:last-child th': { '&:last-child td, &:last-child th': {
@@ -31,10 +46,36 @@ const StyledTableRow = styled(TableRow)(({ theme }) => ({
}, },
})); }));
function createData(name, calories, fat, carbs, protein) { const filterOptions = createFilterOptions({
return { name, calories, fat, carbs, protein }; matchFrom: 'start',
stringify: (option) => option.title,
});
const titles = [
{ title: 'Down' },
{ title: 'Cannot resolve' },
{ title: 'Clear / show all' },
];
/**
* Creates a data object for the table row.
* @param {JSX.Element} name - The status label JSX element.
* @param {string} date - The date and time string.
* @param {string} message - The message string.
* @returns {object} The data object containing name, date, and message.
*/
function createData(name, date, message) {
return { name, date, message };
} }
/**
* Customized table component displaying incident history.
* @returns {JSX.Element} The JSX element representing the customized table.
*/
export default function CustomizedTables() {
const theme = useTheme();
const rows = [ const rows = [
createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'HTTP 350 - NOK'), createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'HTTP 350 - NOK'),
createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'timeout of 48000ms exceeded'), createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'timeout of 48000ms exceeded'),
@@ -43,9 +84,24 @@ const rows = [
createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'HTTP 350 - NOK'), createData(<StatusLabel status="Down" customStyles={{ backgroundColor: '#fff9f9', borderColor: '#ffcac6', color: '#344054' }} />, '2024-03-14 21:41:09', 'HTTP 350 - NOK'),
]; ];
export default function CustomizedTables() {
return ( return (
<Box
sx={{
marginTop: theme.spacing(4),
marginX: 'auto',
width: '80%',
paddingX: theme.spacing(6),
[theme.breakpoints.down('md')]: {
width: '100%',
},
}}
>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: theme.spacing(2) }}>
<Typography variant="h6" component="div" sx={{ fontWeight: 600, fontSize: 16 }}>
Incident History
</Typography>
<Filter />
</Box>
<TableContainer component={Paper}> <TableContainer component={Paper}>
<Table sx={{ minWidth: 700 }} aria-label="customized table"> <Table sx={{ minWidth: 700 }} aria-label="customized table">
<TableHead> <TableHead>
@@ -61,12 +117,51 @@ export default function CustomizedTables() {
<StyledTableCell component="th" scope="row"> <StyledTableCell component="th" scope="row">
{row.name} {row.name}
</StyledTableCell> </StyledTableCell>
<StyledTableCell align="right">{row.calories}</StyledTableCell> <StyledTableCell align="right">{row.date}</StyledTableCell>
<StyledTableCell align="right">{row.fat}</StyledTableCell> <StyledTableCell align="right">{row.message}</StyledTableCell>
</StyledTableRow> </StyledTableRow>
))} ))}
</TableBody> </TableBody>
</Table> </Table>
</TableContainer> </TableContainer>
</Box>
);
}
/**
* Filter component with autocomplete for status filtering.
* @returns {JSX.Element} The JSX element representing the filter component.
*/
function Filter() {
return (
<Autocomplete
id="filter-demo"
options={titles}
getOptionLabel={(option) => option.title}
filterOptions={filterOptions}
sx={{
width: 170,
'& .MuiAutocomplete-inputRoot': {
height: '50px',
},
'& .MuiAutocomplete-listbox': {
maxHeight: '200px',
},
}}
disableClearable
renderInput={(params) => (
<TextField
{...params}
size="small"
label={
<React.Fragment>
<TuneIcon sx={{ marginRight: '0.5rem', position: 'relative', top: '6px' }} />
Filter by status
</React.Fragment>
}
InputProps={{ ...params.InputProps, endAdornment: null }}
/>
)}
/>
); );
} }