-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#1403 removed update toast and added downtime column in services status
- Loading branch information
1 parent
e8095a5
commit a9ec2d5
Showing
6 changed files
with
96 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { TableCell, TableRow, makeStyles, styled } from "@material-ui/core"; | ||
import React, { memo, useEffect, useRef, useState } from "react"; | ||
import { StatusLight } from "./StatusLight"; | ||
|
||
const useStyles = makeStyles(theme => ({ | ||
cell: { | ||
color: theme.palette.primary.contrastText | ||
} | ||
})); | ||
|
||
export const ServiceStatusRow = memo(({ service }) => { | ||
|
||
const classes = useStyles(); | ||
const interval = useRef(null); | ||
const [uptime, setUptime] = useState(0); | ||
|
||
const StyledTableRow = styled(TableRow)(({ theme }) => ({ | ||
// hide last border | ||
'&:last-child td, &:last-child th': { | ||
border: 0 | ||
} | ||
})); | ||
|
||
useEffect(() => { | ||
if (service.timestamp) { | ||
interval.current = setInterval(() => { | ||
setUptime(Date.now() - service.timestamp); | ||
}, 1000); | ||
} | ||
|
||
return () => { | ||
if (interval) { | ||
clearInterval(interval.current); | ||
} | ||
} | ||
}, [service, interval]); | ||
|
||
const getServiceDowntime = () => { | ||
if (uptime) { | ||
let minutes = Math.floor(uptime / (1000 * 60)); | ||
let seconds = Math.floor(uptime / (1000) % 60); | ||
if (minutes) { | ||
return `${minutes} m ${seconds} s`; | ||
} else { | ||
return `${seconds} s`; | ||
} | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
return <StyledTableRow> | ||
<TableCell className={classes.cell}><StatusLight service={service} /></TableCell> | ||
<TableCell className={classes.cell}>{service.state}</TableCell> | ||
<TableCell className={classes.cell}>{service.name}</TableCell> | ||
<TableCell className={classes.cell}>{getServiceDowntime()}</TableCell> | ||
</StyledTableRow>; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
export const SERVICE_STATUSES = { | ||
OK: 'OK', | ||
DEGRADED: 'DEGRADED' | ||
} | ||
|
||
export const SERVICE_STATUS_COLORS = { | ||
OK: 'green', | ||
DEGRADED: 'orange', | ||
OTHER: 'red' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters