ErrorView: Better detection of no-data responses (#65477)

This commit is contained in:
Leon Sorokin 2023-03-28 17:55:13 -05:00 committed by GitHub
parent 6f4232bee3
commit 8fb64cbefd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 37 additions and 3 deletions

View File

@ -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: {

View File

@ -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';
}