Fix broker stats
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import * as q from '../../../../backend/src/Model'
|
||||
import * as React from 'react'
|
||||
import React from 'react'
|
||||
import Chart from './Chart'
|
||||
import { ChartParameters } from '../../reducers/Charts'
|
||||
import { usePollingToFetchTreeNode } from '../helper/usePollingToFetchTreeNode'
|
||||
|
||||
interface Props {
|
||||
tree?: q.Tree<any>
|
||||
@@ -14,37 +15,6 @@ export function ChartWithTreeNode(props: Props) {
|
||||
return null
|
||||
}
|
||||
|
||||
const initialTreeNode = tree.findNode(parameters.topic)
|
||||
const [treeNode, setTreeNode] = React.useState<q.TreeNode<any> | undefined>(initialTreeNode)
|
||||
|
||||
usePollingToFetchTreeNode(treeNode, tree, parameters.topic, setTreeNode)
|
||||
const treeNode = usePollingToFetchTreeNode(tree, parameters.topic)
|
||||
return <Chart treeNode={treeNode} parameters={parameters} />
|
||||
}
|
||||
|
||||
/**
|
||||
* If a node is not available when the plot is shown, keep polling until it has been created
|
||||
*/
|
||||
function usePollingToFetchTreeNode(
|
||||
treeNode: q.TreeNode<any> | undefined,
|
||||
tree: q.Tree<any>,
|
||||
path: string,
|
||||
setTreeNode: React.Dispatch<React.SetStateAction<q.TreeNode<any> | undefined>>
|
||||
) {
|
||||
function pollUntilTreeNodeHasBeenFound() {
|
||||
let intervalTimer: any
|
||||
if (!treeNode) {
|
||||
intervalTimer = setInterval(() => {
|
||||
const node = tree.findNode(path)
|
||||
if (node) {
|
||||
setTreeNode(node)
|
||||
clearInterval(intervalTimer)
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
return function cleanup() {
|
||||
intervalTimer && clearInterval(intervalTimer)
|
||||
}
|
||||
}
|
||||
|
||||
React.useEffect(pollUntilTreeNodeHasBeenFound, [])
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user