Compare commits
2 Commits
46484efdea
...
9ee15160e5
| Author | SHA1 | Date |
|---|---|---|
|
|
9ee15160e5 | |
|
|
e56b82bb66 |
|
|
@ -490,4 +490,5 @@ const PrometheusChart = ({ metricName }) => {
|
|||
);
|
||||
};
|
||||
|
||||
export default React.memo(PrometheusChart);
|
||||
export default React.memo(PrometheusChart);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import React, { lazy, Suspense } from "react";
|
||||
|
||||
const PrometheusChart = lazy(() => import('../../Charts/PrometheusChart'));
|
||||
import LazyChartBatchRenderer from "../hooks/LazyChartBatchRender";
|
||||
|
||||
// Функция для генерации названия метрики на основе id
|
||||
const getMetricName = (id) => {
|
||||
|
|
@ -35,6 +36,7 @@ const tabContent = (data) => {
|
|||
const content = (
|
||||
<div>
|
||||
<h2>{node.title}</h2>
|
||||
<LazyChartBatchRenderer charts={node.items.map((child) => tabContent[child.id].content)} />
|
||||
<p>Контент для {node.title}.</p>
|
||||
{childrenContent}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
const LazyChartBatchRenderer = ({ charts, batchSize = 3, delay = 150 }) => {
|
||||
const [visibleCharts, setVisibleCharts] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
let index = 0;
|
||||
const timer = setInterval(() => {
|
||||
setVisibleCharts((prev) => [
|
||||
...prev,
|
||||
...charts.slice(index, index + batchSize),
|
||||
]);
|
||||
index += batchSize;
|
||||
if (index >= charts.length) clearInterval(timer);
|
||||
}, delay);
|
||||
|
||||
return () => clearInterval(timer);
|
||||
}, [charts]);
|
||||
|
||||
return (
|
||||
<>
|
||||
{visibleCharts.map((chart, idx) => (
|
||||
<div key={idx}>{chart}</div>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default LazyChartBatchRenderer;
|
||||
Loading…
Reference in New Issue