Skip to content

Commit

Permalink
simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
mbondyra committed Aug 15, 2024
1 parent 5d2cbcf commit 86b92f3
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions src/plugins/vis_types/vislib/public/vis_wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,24 @@ const extractContainerType = (context?: KibanaExecutionContext): string | undefi
const VislibWrapper = ({ core, charts, visData, visConfig, handlers }: VislibWrapperProps) => {
const chartDiv = useRef<HTMLDivElement>(null);
const visController = useRef<VislibVisController | null>(null);
const shouldCountRender = useRef<boolean>(false);
const skipRenderComplete = useRef<boolean>(true);

const renderComplete = useCallback(() => {
if (shouldCountRender.current) {
const usageCollection = getUsageCollectionStart();
const containerType = extractContainerType(handlers.getExecutionContext());

if (usageCollection && containerType) {
usageCollection.reportUiCounter(
containerType,
METRIC_TYPE.COUNT,
`render_agg_based_${visConfig!.type}`
);
}
handlers.done();
shouldCountRender.current = false;
if (skipRenderComplete.current) {
return;
}
const usageCollection = getUsageCollectionStart();
const containerType = extractContainerType(handlers.getExecutionContext());

if (usageCollection && containerType) {
usageCollection.reportUiCounter(
containerType,
METRIC_TYPE.COUNT,
`render_agg_based_${visConfig!.type}`
);
}
handlers.done();
skipRenderComplete.current = true;
}, [handlers, visConfig]);

const renderChart = useMemo(
Expand All @@ -80,7 +81,7 @@ const VislibWrapper = ({ core, charts, visData, visConfig, handlers }: VislibWra
}, [renderChart]);

useEffect(() => {
shouldCountRender.current = true;
skipRenderComplete.current = false;
renderChart();
}, [renderChart]);

Expand Down

0 comments on commit 86b92f3

Please sign in to comment.