({
+ minValue: 0,
+ maxValue: 0,
+ });
+
+ useEffect(() => {
+ const timer = window.setInterval(() => {
+ setEpoch((val) => val + 1);
+ }, 5 * 60 * 1000);
+ return () => clearInterval(timer);
+ }, [inView]);
useEffect(() => {
if (response !== null) {
- setMaxValue(Math.max(...response.samples.map((s) => s.value)));
+ setCachedResponse(response);
+ const max = Math.max(...response.samples.map((s) => s.value));
+ const min = Math.min(
+ ...response.samples.filter((s) => s.value > 0).map((s) => s.value)
+ );
+ setMinMaxValue({ minValue: min === Infinity ? 0 : min, maxValue: max });
}
}, [response]);
@@ -60,7 +82,7 @@ export const AlertHistory: FC<{ group: APIAlertGroupT }> = ({ group }) => {
},
},
]);
- }, [inView, labels, sources]);
+ }, [inView, labels, sources, epoch]);
return (
@@ -68,9 +90,9 @@ export const AlertHistory: FC<{ group: APIAlertGroupT }> = ({ group }) => {
ref={ref}
className="w-100 d-flex justify-content-between align-self-center"
>
- {error || (response && response.error !== "") ? (
+ {error || (cachedResponse && cachedResponse.error !== "") ? (
) : (
- (response || responseStub).samples.map((sample, i) => (
+ (cachedResponse || responseStub).samples.map((sample, i) => (