Fix broker statistic updates
This commit is contained in:
@@ -7,6 +7,7 @@ import { Theme, withStyles } from '@material-ui/core/styles'
|
|||||||
import { TopicViewModel } from '../../model/TopicViewModel'
|
import { TopicViewModel } from '../../model/TopicViewModel'
|
||||||
import { Typography } from '@material-ui/core'
|
import { Typography } from '@material-ui/core'
|
||||||
import { usePollingToFetchTreeNode } from '../helper/usePollingToFetchTreeNode'
|
import { usePollingToFetchTreeNode } from '../helper/usePollingToFetchTreeNode'
|
||||||
|
import { useUpdateComponentWhenNodeUpdates } from '../helper/useUpdateComponentWhenNodeUpdates'
|
||||||
const abbreviate = require('number-abbreviate')
|
const abbreviate = require('number-abbreviate')
|
||||||
|
|
||||||
interface Stats {
|
interface Stats {
|
||||||
@@ -32,6 +33,7 @@ interface Props {
|
|||||||
function BrokerStatistics(props: Props) {
|
function BrokerStatistics(props: Props) {
|
||||||
const { tree, classes } = props
|
const { tree, classes } = props
|
||||||
const sysTopic = usePollingToFetchTreeNode(props.tree, '$SYS')
|
const sysTopic = usePollingToFetchTreeNode(props.tree, '$SYS')
|
||||||
|
useUpdateComponentWhenNodeUpdates(sysTopic)
|
||||||
|
|
||||||
return useMemo(() => {
|
return useMemo(() => {
|
||||||
if (!Boolean(sysTopic)) {
|
if (!Boolean(sysTopic)) {
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
import * as q from '../../../../backend/src/Model'
|
||||||
|
import { useEffect, useState } from 'react'
|
||||||
|
|
||||||
|
export function useUpdateComponentWhenNodeUpdates(node?: q.TreeNode<any>): number {
|
||||||
|
const [lastUpdate, setLastUpdate] = useState(0)
|
||||||
|
useEffect(() => {
|
||||||
|
if (!node) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const updateComponent = () => setLastUpdate(Date.now())
|
||||||
|
node.onMerge.subscribe(updateComponent)
|
||||||
|
return function cleanup() {
|
||||||
|
node.onMerge.unsubscribe(updateComponent)
|
||||||
|
}
|
||||||
|
}, [node])
|
||||||
|
return lastUpdate
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user