Skip to content

Commit

Permalink
feat(webapp): add loader when the health check has not been executed …
Browse files Browse the repository at this point in the history
…and refactor getStatus
  • Loading branch information
Torresmorah committed Apr 26, 2023
1 parent 5b18b2d commit 015bab1
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 22 deletions.
6 changes: 4 additions & 2 deletions webapp/src/components/EndpointsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ const EndpointsTable = ({ producers }) => {
const diffBlockTimems =
new Date(endpoint.updated_at) - new Date(endpoint.head_block_time)

return diffBlockTimems <= syncToleranceInterval || !endpoint.head_block_time
return diffBlockTimems <= syncToleranceInterval
}

const getStatus = endpoint => {
if (endpoint.response.status === undefined) return

switch (Math.floor(endpoint.response?.status / 100)) {
case 2:
return isSynchronized(endpoint) ? 'greenLight' : 'timerOff'
return !endpoint.head_block_time || isSynchronized(endpoint)
? 'greenLight'
: 'timerOff'
case 4:
case 5:
return 'yellowLight'
Expand Down
2 changes: 1 addition & 1 deletion webapp/src/components/EndpointsTextList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ const EndpointsTextList = ({ type }) => {

return (
<>
{!loading && textList?.length && (
{!loading && !!textList?.length && (
<div className={classes.container}>
<CopyToClipboard text={textList} />
{textList}
Expand Down
6 changes: 4 additions & 2 deletions webapp/src/components/HealthCheck/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState } from 'react'
import { makeStyles } from '@mui/styles'
import { CircularProgress } from '@mui/material'

import Tooltip from '../Tooltip'

Expand All @@ -12,6 +13,9 @@ const HealthCheck = ({ children, status }) => {
const classes = useStyles()
const [anchorEl, setAnchorEl] = useState(null)

if (status === undefined)
return <CircularProgress className={classes.loading} />

const handlePopoverOpen = (target) => {
setAnchorEl(target)
}
Expand All @@ -20,8 +24,6 @@ const HealthCheck = ({ children, status }) => {
setAnchorEl(null)
}

if (status === undefined) return

const openPopOver = (event) => {
handlePopoverOpen(event.target)
}
Expand Down
4 changes: 4 additions & 0 deletions webapp/src/components/HealthCheck/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,8 @@ export default (theme) => ({
test: {
boxShadow: '10px 5px 5px red !important',
},
loading: {
width: '18px !important',
height: '18px !important',
}
})
41 changes: 26 additions & 15 deletions webapp/src/components/NodeCard/EndpointsChips.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,17 @@ const EndpointsChips = ({ node }) => {
const { t } = useTranslation('endpointInfoComponent')
const { totalEndpoints, failingEndpoints, updatedAt } = status
const workingEndpoints = totalEndpoints - failingEndpoints.length
const healthStatus = getHealthStatus(totalEndpoints, workingEndpoints)
let healthStatus

if(!status.isLoading) {
healthStatus = getHealthStatus(totalEndpoints, workingEndpoints)
}

return (
<div className={classes.lightIcon}>
{`${workingEndpoints}/${totalEndpoints}`}
{healthStatus && (
<span>{`${workingEndpoints}/${totalEndpoints}`}</span>
)}
<HealthCheck status={healthStatus}>
<Typography>{t('status')}</Typography>
<Typography>
Expand All @@ -66,29 +72,34 @@ const EndpointsChips = ({ node }) => {
)
}

const defaultStatus = {
const checkedEndpoints = node.endpoints.filter(endpoint => endpoint.type !== 'p2p')
const status = {
totalEndpoints: 0,
failingEndpoints: [],
updatedAt: 'NA',
updatedAt: 'N/A',
isLoading: false
}
const status = node.endpoints.reduce((status, endpoint) => {
if (endpoint?.type !== 'p2p') {
if (endpoint?.response?.status !== 200) {
status.failingEndpoints.push(endpoint.type)
}

status.totalEndpoints += 1
status.updatedAt = endpoint.updated_at

for (const endpoint of checkedEndpoints){
if (endpoint?.response?.status === undefined) {
status.isLoading = true

break
}

return status
}, defaultStatus)
if (endpoint?.response?.status !== 200) {
status.failingEndpoints.push(endpoint.type)
}

status.totalEndpoints += 1
status.updatedAt = endpoint.updated_at
}

return (
<>
<dt className={`${classes.bold} ${classes.endpointsTitle}`}>
{t('endpoints')}
{!!status.totalEndpoints && <EndpointsInfo status={status} />}
{!!checkedEndpoints.length && <EndpointsInfo status={status} />}
</dt>
<ChipList
list={node.endpoints.map(({ type, value }) => {
Expand Down
4 changes: 2 additions & 2 deletions webapp/src/components/NodeCard/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ export default (theme) => ({
display: 'flex',
fontWeight: 'normal',
marginLeft: theme.spacing(3),
'& svg': {
marginLeft: theme.spacing(2),
'& span': {
marginRight: theme.spacing(2),
},
},
keysContainer: {
Expand Down

0 comments on commit 015bab1

Please sign in to comment.