Skip to content

Commit

Permalink
[#7758] Apply lazy loading to OpenTelemetryMetricFetcher
Browse files Browse the repository at this point in the history
  • Loading branch information
jihea-park committed Dec 9, 2024
1 parent dd49d15 commit a8885b1
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useOpenTelemetrySearchParameters, usePostOtlpMetricData } from '@pinpoi
import React from 'react';
import { assign } from 'lodash';
import { ReChart } from '../../../components/ReChart';
import { useInView } from 'react-intersection-observer';

export interface OpenTelemetryMetricFetcherProps {
metricDefinition: OtlpMetricDefUserDefined.Metric;
Expand All @@ -13,12 +14,15 @@ export interface OpenTelemetryMetricFetcherProps {
export const OpenTelemetryMetricFetcher = ({
metricDefinition,
dashboardId,
inView,
}: OpenTelemetryMetricFetcherProps) => {
const { mutate, data } = usePostOtlpMetricData();
const { dateRange, agentId } = useOpenTelemetrySearchParameters();
const prevDateRange = React.useRef<{ from: Date; to: Date }>();
const prevAgentId = React.useRef<string>();
const { ref, inView } = useInView({
initialInView: false,
threshold: 0.1,
});

React.useEffect(() => {
if (!inView) {
Expand Down Expand Up @@ -71,29 +75,31 @@ export const OpenTelemetryMetricFetcher = ({
const { stack, stackDetails } = metricDefinition;

return (
<ReChart
syncId={dashboardId}
chartData={{
title: '',
timestamp: data?.timestamp || [],
metricValueGroups: [
{
groupName: '',
chartType: data?.chartType || '',
unit: data?.unit || '',
metricValues: (data?.metricValues || [])?.map((mv) => {
return {
fieldName: mv?.legendName,
values: mv?.values,
};
}),
},
],
}}
unit={data?.unit}
tooltipConfig={{
showTotal: stack && stackDetails?.showTotal,
}}
/>
<div ref={ref} className="w-full h-full">
<ReChart
syncId={dashboardId}
chartData={{
title: '',
timestamp: data?.timestamp || [],
metricValueGroups: [
{
groupName: '',
chartType: data?.chartType || '',
unit: data?.unit || '',
metricValues: (data?.metricValues || [])?.map((mv) => {
return {
fieldName: mv?.legendName,
values: mv?.values,
};
}),
},
],
}}
unit={data?.unit}
tooltipConfig={{
showTotal: stack && stackDetails?.showTotal,
}}
/>
</div>
);
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -224,27 +224,28 @@ export const OpenTelemetryDashboardFetcher = () => {
</div>
</div>
<DashBoard layouts={state.layouts} onLayoutChange={onLayoutChange}>
{metrics.map((metric) => {
return (
<div key={metric?.id}>
<Widget
title={metric.title}
onClickDelete={() => {
setCurrentDeletingTarget(metric);
}}
onClickEdit={() => {
setCurrentEditingTarget(metric);
}}
>
<OpenTelemetryMetric
inView={true}
metricDefinition={metric}
dashboardId={applicationName}
/>
</Widget>
</div>
);
})}
{state.layouts.sm.length > 0 &&
metrics.map((metric) => {
return (
<div key={metric?.id}>
<Widget
title={metric.title}
onClickDelete={() => {
setCurrentDeletingTarget(metric);
}}
onClickEdit={() => {
setCurrentEditingTarget(metric);
}}
>
<OpenTelemetryMetric
inView={true}
metricDefinition={metric}
dashboardId={applicationName}
/>
</Widget>
</div>
);
})}
</DashBoard>
</div>
) : (
Expand Down

0 comments on commit a8885b1

Please sign in to comment.