Skip to content

Commit

Permalink
feat(webapp): add link to endpoints stats in the endpoints list
Browse files Browse the repository at this point in the history
  • Loading branch information
Torresmorah committed Mar 22, 2023
1 parent f479235 commit 239777a
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 28 deletions.
45 changes: 32 additions & 13 deletions webapp/src/components/EndpointsTable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ import TableRow from '@mui/material/TableRow'
import Typography from '@mui/material/Typography'
import { Tooltip as MUITooltip } from '@mui/material'
import ListAltIcon from '@mui/icons-material/ListAlt'
import { Link as RouterLink } from 'react-router-dom'
import Link from '@mui/material/Link'
import QueryStatsIcon from '@mui/icons-material/QueryStats';

import HealthCheck from '../HealthCheck'
import HealthCheckInfo from 'components/HealthCheck/HealthCheckInfo'
Expand Down Expand Up @@ -42,7 +45,8 @@ const EndpointsTable = ({ producers }) => {
const getStatus = (endpoint) => {
if (endpoint.response.status === undefined) return

const diffBlockTimems = new Date(endpoint.updated_at) - new Date(endpoint.head_block_time)
const diffBlockTimems =
new Date(endpoint.updated_at) - new Date(endpoint.head_block_time)

if (diffBlockTimems <= syncToleranceInterval) {
return 'greenLight'
Expand Down Expand Up @@ -122,23 +126,38 @@ const EndpointsTable = ({ producers }) => {
</div>
</TableCell>
<TableCell>
<div className={classes.titleCell}>
{t('p2p')}
<MUITooltip title={t('showList')} arrow>
<ListAltIcon
onClick={(e) => {
handlePopoverOpen(e.target, 'p2p')
}}
/>
</MUITooltip>
</div>
</TableCell>
<div className={classes.titleCell}>
{t('p2p')}
<MUITooltip title={t('showList')} arrow>
<ListAltIcon
onClick={(e) => {
handlePopoverOpen(e.target, 'p2p')
}}
/>
</MUITooltip>
</div>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
{producers.map((producer, index) => (
<TableRow key={`${producer.name}-${index}`}>
<TableCell>{producer.name}</TableCell>
<TableCell>
<div className={classes.healthContainer}>
{producer.name}
{!!producer.endpoints.api.length +
producer.endpoints.ssl.length && (
<Link
component={RouterLink}
state={{ producerId: producer.id }}
to="/endpoints-stats"
color="secondary"
>
<QueryStatsIcon />
</Link>
)}
</div>
</TableCell>
<CellList producer={producer} endpointType={'api'} />
<CellList producer={producer} endpointType={'ssl'} />
<CellList producer={producer} endpointType={'p2p'} />
Expand Down
1 change: 1 addition & 0 deletions webapp/src/hooks/customHooks/useEndpointsState.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const useEndpointsState = () => {
})

return {
id: producer.id,
name:
producer.bp_json?.org?.candidate_name ||
producer?.bp_json?.org?.organization_name ||
Expand Down
16 changes: 11 additions & 5 deletions webapp/src/hooks/customHooks/useHealthCheckHistoryState.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useState, useEffect } from 'react'
import { useLazyQuery } from '@apollo/client'
import { useLocation } from 'react-router-dom'

import {
FASTEST_ENDPOINTS_QUERY,
Expand All @@ -25,11 +26,13 @@ const useHealthCheckState = () => {
const [historyData, setHistoryData] = useState()
const [statsAverage, setStatsAverage] = useState()
const [dates, setDates] = useState()
const location = useLocation()

useEffect(() => {
const endpointFilter = {
_and: [{ type: { _in: ['ssl', 'api'] } }, { value: { _gt: '' } }],
}

loadProducers({
variables: {
where: { nodes: { endpoints: endpointFilter } },
Expand All @@ -49,8 +52,9 @@ const useHealthCheckState = () => {
name: producer?.bp_json?.org?.candidate_name,
})),
)
setSelected(producers[0]?.id)
}, [producers])
setSelected(location?.state?.producerId || producers[0]?.id)
window.history.replaceState({}, document.title)
}, [producers, location])

useEffect(() => {
if (!selected) return
Expand All @@ -62,7 +66,8 @@ const useHealthCheckState = () => {
if (!history) return

const data = history.reduce((aux, curr) => {
const index = aux.findIndex(x => x.name === curr.value)
const index = aux.findIndex((x) => x.name === curr.value)

if (index < 0) {
aux.push({
name: curr.value,
Expand All @@ -80,10 +85,11 @@ const useHealthCheckState = () => {

return aux
}, [])

setDates(data[0]?.dates || [])
setHistoryData(data)
setStatsAverage(
data.map(x => ({
data.map((x) => ({
value: x.name,
avg_time: x.avg_time / x.data.length,
availability: x.availability / x.data.length,
Expand All @@ -101,7 +107,7 @@ const useHealthCheckState = () => {
dates,
loading,
loadingHistory,
loadingProducers
loadingProducers,
},
{ setSelected },
]
Expand Down
6 changes: 5 additions & 1 deletion webapp/src/routes/EndpointsStats/EndpointStatsTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import TableRow from '@mui/material/TableRow'
const EndpointsTable = ({endpoints, title}) => {
const { t } = useTranslation('EndpointsStatsRoute')

const formatPercentage = value => {
return Number.isInteger(value) ? value : value.toFixed(2)
}

return (
<>
<Typography component="p" variant="h6">
Expand All @@ -30,7 +34,7 @@ const EndpointsTable = ({endpoints, title}) => {
{endpoints.map((item, index) => (
<TableRow key={index}>
<TableCell>{item.value}</TableCell>
<TableCell align="right">{`${item.availability}%`}</TableCell>
<TableCell align="right">{`${formatPercentage(item.availability)}%`}</TableCell>
<TableCell align="right">{`${item.avg_time.toFixed(3)} s`}</TableCell>
</TableRow>
))}
Expand Down
27 changes: 18 additions & 9 deletions webapp/src/routes/EndpointsStats/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import LinearProgress from '@mui/material/LinearProgress'
import MenuItem from '@mui/material/MenuItem'
import Highcharts from 'highcharts'
import HighchartsReact from 'highcharts-react-official'
import FormControl from '@mui/material/FormControl'
import moment from 'moment'
import Select from '@mui/material/Select'
import { makeStyles } from '@mui/styles'
Expand Down Expand Up @@ -67,11 +68,19 @@ const EndpointsStats = () => {
</Typography>
<br />
{producersNames?.length && (
<Select value={selected} onChange={(event) => setSelected(event.target.value)}>
{producersNames.map(producer => (
<MenuItem key={producer.id} value={producer.id}>{producer.name}</MenuItem>
))}
</Select>
<FormControl variant="standard">
<Select
value={selected}
onChange={(event) => setSelected(event.target.value)}
fullWidth
>
{producersNames.map((producer) => (
<MenuItem key={producer.id} value={producer.id}>
{producer.name}
</MenuItem>
))}
</Select>
</FormControl>
)}
{historyData && (
<HighchartsReact
Expand All @@ -82,10 +91,10 @@ const EndpointsStats = () => {
/>
)}
{statsAverage && (
<EndpointsTable
title={t('list')}
endpoints={statsAverage}
/>
<EndpointsTable
title={t('list')}
endpoints={statsAverage}
/>
)}
</CardContent>
</Card>
Expand Down

0 comments on commit 239777a

Please sign in to comment.