BarChart: Show "No data" message for zero-length frames (#79844)

This commit is contained in:
Leon Sorokin 2023-12-22 22:04:50 -06:00 committed by GitHub
parent feb7b38fba
commit 36a3508a0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 2 deletions

View File

@ -158,13 +158,29 @@ describe('BarChart utils', () => {
});
describe('prepareGraphableFrames', () => {
it('will warn when there is no data in the response', () => {
it('will warn when there is no frames in the response', () => {
const result = prepareBarChartDisplayValues([], createTheme(), { stacking: StackingMode.None } as Options);
const warning = assertIsDefined('warn' in result ? result : null);
expect(warning.warn).toEqual('No data in response');
});
it('will warn when there is no data in the response', () => {
const result = prepareBarChartDisplayValues(
[
{
length: 0,
fields: [],
},
],
createTheme(),
{ stacking: StackingMode.None } as Options
);
const warning = assertIsDefined('warn' in result ? result : null);
expect(warning.warn).toEqual('No data in response');
});
it('will warn when there is no string or time field', () => {
const df = new MutableDataFrame({
fields: [

View File

@ -375,7 +375,7 @@ export function prepareBarChartDisplayValues(
theme: GrafanaTheme2,
options: Options
): BarChartDisplayValues | BarChartDisplayWarning {
if (!series?.length) {
if (!series.length || series.every((fr) => fr.length === 0)) {
return { warn: 'No data in response' };
}