From 8fb64cbefde4120137fe6f7e7949e31ba12ab805 Mon Sep 17 00:00:00 2001 From: Leon Sorokin Date: Tue, 28 Mar 2023 17:55:13 -0500 Subject: [PATCH] ErrorView: Better detection of no-data responses (#65477) --- .../components/PanelDataErrorView.test.tsx | 37 ++++++++++++++++++- .../panel/components/PanelDataErrorView.tsx | 3 +- 2 files changed, 37 insertions(+), 3 deletions(-) diff --git a/public/app/features/panel/components/PanelDataErrorView.test.tsx b/public/app/features/panel/components/PanelDataErrorView.test.tsx index 3d8ed667d61..a55025757ca 100644 --- a/public/app/features/panel/components/PanelDataErrorView.test.tsx +++ b/public/app/features/panel/components/PanelDataErrorView.test.tsx @@ -3,7 +3,7 @@ import { defaultsDeep } from 'lodash'; import React from 'react'; import { Provider } from 'react-redux'; -import { getDefaultTimeRange, LoadingState } from '@grafana/data'; +import { ArrayVector, FieldType, getDefaultTimeRange, LoadingState } from '@grafana/data'; import { PanelDataErrorViewProps } from '@grafana/runtime'; import { configureStore } from 'app/store/configureStore'; @@ -16,6 +16,41 @@ describe('PanelDataErrorView', () => { expect(screen.getByText('No data')).toBeInTheDocument(); }); + it('show No data when there is no data', () => { + renderWithProps({ + data: { + state: LoadingState.Done, + timeRange: getDefaultTimeRange(), + series: [ + { + fields: [ + { + name: 'time', + type: FieldType.time, + config: {}, + values: new ArrayVector([]), + }, + ], + length: 0, + }, + { + fields: [ + { + name: 'value', + type: FieldType.number, + config: {}, + values: new ArrayVector([]), + }, + ], + length: 0, + }, + ], + }, + }); + + expect(screen.getByText('No data')).toBeInTheDocument(); + }); + it('show no value field config when there is no data', () => { renderWithProps({ fieldConfig: { diff --git a/public/app/features/panel/components/PanelDataErrorView.tsx b/public/app/features/panel/components/PanelDataErrorView.tsx index 73d8b7ae064..35dea163502 100644 --- a/public/app/features/panel/components/PanelDataErrorView.tsx +++ b/public/app/features/panel/components/PanelDataErrorView.tsx @@ -66,8 +66,7 @@ function getMessageFor( return message; } - // In some cases there is a data frame but with no fields - if (!data.series || data.series.length === 0 || (data.series.length === 1 && data.series[0].length === 0)) { + if (!data.series || data.series.length === 0 || data.series.every((frame) => frame.length === 0)) { return fieldConfig?.defaults.noValue ?? 'No data'; }