Do not crash timeseries panel if there is no time series data in the response (#33993)

This commit is contained in:
Dominik Prokop
2021-05-12 14:14:39 +02:00
committed by GitHub
parent f2fcf721eb
commit baa5ceb4c0
4 changed files with 110 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
import { DashboardCursorSync, Field, PanelProps } from '@grafana/data';
import { anySeriesWithTimeField, DashboardCursorSync, Field, PanelProps } from '@grafana/data';
import { TooltipDisplayMode, usePanelContext, TimeSeries, TooltipPlugin, ZoomPlugin } from '@grafana/ui';
import { getFieldLinksForExplore } from 'app/features/explore/utils/links';
import React from 'react';
@@ -19,12 +19,12 @@ export const TimeSeriesPanel: React.FC<TimeSeriesPanelProps> = ({
onChangeTimeRange,
replaceVariables,
}) => {
const { sync } = usePanelContext();
const getFieldLinks = (field: Field, rowIndex: number) => {
return getFieldLinksForExplore({ field, rowIndex, range: timeRange });
};
const { sync } = usePanelContext();
if (!data || !data.series?.length) {
return (
<div className="panel-empty">
@@ -33,6 +33,14 @@ export const TimeSeriesPanel: React.FC<TimeSeriesPanelProps> = ({
);
}
if (!anySeriesWithTimeField(data.series)) {
return (
<div className="panel-empty">
<p>Missing time field in the data</p>
</div>
);
}
return (
<TimeSeries
frames={data.series}