[UI] Metrics polling
This commit is contained in:
parent
97a7bc781a
commit
9c0d4ef2c2
2 changed files with 40 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import PageLoader from 'components/common/PageLoader/PageLoader';
|
import PageLoader from 'components/common/PageLoader/PageLoader';
|
||||||
import { ClusterId } from 'types';
|
import { ClusterId } from 'types';
|
||||||
|
import useInterval from 'lib/hooks/useInterval';
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
clusterId: string;
|
clusterId: string;
|
||||||
|
@ -15,8 +16,15 @@ const Topics: React.FC<Props> = ({
|
||||||
fetchBrokers,
|
fetchBrokers,
|
||||||
fetchBrokerMetrics,
|
fetchBrokerMetrics,
|
||||||
}) => {
|
}) => {
|
||||||
React.useEffect(() => { fetchBrokers(clusterId); }, [fetchBrokers, clusterId]);
|
React.useEffect(
|
||||||
React.useEffect(() => { fetchBrokerMetrics(clusterId); }, [fetchBrokerMetrics, clusterId]);
|
() => {
|
||||||
|
fetchBrokers(clusterId);
|
||||||
|
fetchBrokerMetrics(clusterId);
|
||||||
|
},
|
||||||
|
[fetchBrokers, fetchBrokerMetrics, clusterId],
|
||||||
|
);
|
||||||
|
|
||||||
|
useInterval(() => { fetchBrokerMetrics(clusterId); }, 5000);
|
||||||
|
|
||||||
if (isFetched) {
|
if (isFetched) {
|
||||||
return (
|
return (
|
||||||
|
|
30
frontend/src/lib/hooks/useInterval.ts
Normal file
30
frontend/src/lib/hooks/useInterval.ts
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
type Callback = () => any;
|
||||||
|
|
||||||
|
const useInterval = (callback: Callback, delay: number) => {
|
||||||
|
const savedCallback = React.useRef<Callback>();
|
||||||
|
|
||||||
|
React.useEffect(
|
||||||
|
() => {
|
||||||
|
savedCallback.current = callback;
|
||||||
|
},
|
||||||
|
[callback],
|
||||||
|
);
|
||||||
|
|
||||||
|
React.useEffect(
|
||||||
|
() => {
|
||||||
|
const tick = () => {
|
||||||
|
savedCallback.current && savedCallback.current()
|
||||||
|
};
|
||||||
|
|
||||||
|
if (delay !== null) {
|
||||||
|
const id = setInterval(tick, delay);
|
||||||
|
return () => clearInterval(id);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
[delay],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default useInterval;
|
Loading…
Add table
Reference in a new issue