mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Heatmap: Fix null options migration (#79083)
* Fix heatmap null options migration Some dashboard generation libraries, such as grafanalib, may produce heatmaps with a null 'options' attribute. This condition triggers a panic during migration, resulting in a blank heatmap panel. This commit addresses the issue by returning default options if a panel has a null 'options'. Signed-off-by: Neil Shen <overvenus@gmail.com> * Nullish coalescing panel.options Signed-off-by: Neil Shen <overvenus@gmail.com> --------- Signed-off-by: Neil Shen <overvenus@gmail.com>
This commit is contained in:
parent
8af08d0df2
commit
999c9c5ea3
@ -1,6 +1,6 @@
|
|||||||
import { PanelModel, FieldConfigSource } from '@grafana/data';
|
import { PanelModel, FieldConfigSource } from '@grafana/data';
|
||||||
|
|
||||||
import { heatmapChangedHandler } from './migrations';
|
import { heatmapChangedHandler, heatmapMigrationHandler } from './migrations';
|
||||||
|
|
||||||
describe('Heatmap Migrations', () => {
|
describe('Heatmap Migrations', () => {
|
||||||
let prevFieldConfig: FieldConfigSource;
|
let prevFieldConfig: FieldConfigSource;
|
||||||
@ -91,6 +91,63 @@ describe('Heatmap Migrations', () => {
|
|||||||
`);
|
`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('Null Options', () => {
|
||||||
|
const panel = {} as PanelModel;
|
||||||
|
panel.options = null;
|
||||||
|
panel.options = heatmapMigrationHandler(panel);
|
||||||
|
expect(panel).toMatchInlineSnapshot(`
|
||||||
|
{
|
||||||
|
"fieldConfig": {
|
||||||
|
"defaults": {},
|
||||||
|
"overrides": [],
|
||||||
|
},
|
||||||
|
"options": {
|
||||||
|
"calculate": true,
|
||||||
|
"calculation": {},
|
||||||
|
"cellGap": 2,
|
||||||
|
"cellRadius": undefined,
|
||||||
|
"cellValues": {
|
||||||
|
"decimals": undefined,
|
||||||
|
},
|
||||||
|
"color": {
|
||||||
|
"exponent": 0.5,
|
||||||
|
"fill": undefined,
|
||||||
|
"max": undefined,
|
||||||
|
"min": undefined,
|
||||||
|
"mode": "scheme",
|
||||||
|
"reverse": false,
|
||||||
|
"scale": "exponential",
|
||||||
|
"scheme": "Oranges",
|
||||||
|
"steps": 128,
|
||||||
|
},
|
||||||
|
"exemplars": {
|
||||||
|
"color": "rgba(255,0,255,0.7)",
|
||||||
|
},
|
||||||
|
"legend": {
|
||||||
|
"show": false,
|
||||||
|
},
|
||||||
|
"rowsFrame": {
|
||||||
|
"layout": "auto",
|
||||||
|
},
|
||||||
|
"showValue": "never",
|
||||||
|
"tooltip": {
|
||||||
|
"show": false,
|
||||||
|
"yHistogram": false,
|
||||||
|
},
|
||||||
|
"yAxis": {
|
||||||
|
"axisPlacement": "left",
|
||||||
|
"axisWidth": undefined,
|
||||||
|
"decimals": undefined,
|
||||||
|
"max": undefined,
|
||||||
|
"min": undefined,
|
||||||
|
"reverse": false,
|
||||||
|
"unit": undefined,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`);
|
||||||
|
});
|
||||||
|
|
||||||
it('Cell padding defaults', () => {
|
it('Cell padding defaults', () => {
|
||||||
// zero becomes 1
|
// zero becomes 1
|
||||||
expect(
|
expect(
|
||||||
|
@ -14,7 +14,7 @@ import { Options, defaultOptions, HeatmapColorMode } from './types';
|
|||||||
/** Called when the version number changes */
|
/** Called when the version number changes */
|
||||||
export const heatmapMigrationHandler = (panel: PanelModel): Partial<Options> => {
|
export const heatmapMigrationHandler = (panel: PanelModel): Partial<Options> => {
|
||||||
// Migrating from angular
|
// Migrating from angular
|
||||||
if (Object.keys(panel.options).length === 0) {
|
if (Object.keys(panel.options ?? {}).length === 0) {
|
||||||
return heatmapChangedHandler(panel, 'heatmap', { angular: panel }, panel.fieldConfig);
|
return heatmapChangedHandler(panel, 'heatmap', { angular: panel }, panel.fieldConfig);
|
||||||
}
|
}
|
||||||
return panel.options;
|
return panel.options;
|
||||||
|
Loading…
Reference in New Issue
Block a user