mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
ErrorView: Better detection of no-data responses (#65477)
This commit is contained in:
parent
6f4232bee3
commit
8fb64cbefd
@ -3,7 +3,7 @@ import { defaultsDeep } from 'lodash';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { Provider } from 'react-redux';
|
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 { PanelDataErrorViewProps } from '@grafana/runtime';
|
||||||
import { configureStore } from 'app/store/configureStore';
|
import { configureStore } from 'app/store/configureStore';
|
||||||
|
|
||||||
@ -16,6 +16,41 @@ describe('PanelDataErrorView', () => {
|
|||||||
expect(screen.getByText('No data')).toBeInTheDocument();
|
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', () => {
|
it('show no value field config when there is no data', () => {
|
||||||
renderWithProps({
|
renderWithProps({
|
||||||
fieldConfig: {
|
fieldConfig: {
|
||||||
|
@ -66,8 +66,7 @@ function getMessageFor(
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
// In some cases there is a data frame but with no fields
|
if (!data.series || data.series.length === 0 || data.series.every((frame) => frame.length === 0)) {
|
||||||
if (!data.series || data.series.length === 0 || (data.series.length === 1 && data.series[0].length === 0)) {
|
|
||||||
return fieldConfig?.defaults.noValue ?? 'No data';
|
return fieldConfig?.defaults.noValue ?? 'No data';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user