From 13948c0b7620cd8a23a2838078a1693f768167d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Wed, 29 Jan 2020 19:42:07 +0000 Subject: [PATCH] StatPanels: Fixed migration from old singlestat and default min & max being copied even when gauge was disbled (#21820) --- .../SingleStatShared/SingleStatBaseOptions.ts | 2 +- .../panel/gauge/GaugeMigrations.test.ts | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts b/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts index 21e7e5912f0..559279afa83 100644 --- a/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts +++ b/packages/grafana-ui/src/components/SingleStatShared/SingleStatBaseOptions.ts @@ -86,7 +86,7 @@ export function sharedSingleStatPanelChangedHandler( defaults.mappings = mappings; } - if (panel.gauge) { + if (panel.gauge && panel.gauge.show) { defaults.min = panel.gauge.minValue; defaults.max = panel.gauge.maxValue; } diff --git a/public/app/plugins/panel/gauge/GaugeMigrations.test.ts b/public/app/plugins/panel/gauge/GaugeMigrations.test.ts index 8def4a8b341..3265549af10 100644 --- a/public/app/plugins/panel/gauge/GaugeMigrations.test.ts +++ b/public/app/plugins/panel/gauge/GaugeMigrations.test.ts @@ -103,4 +103,23 @@ describe('Gauge Panel Migrations', () => { expect(newOptions.showThresholdMarkers).toBe(true); expect(newOptions.showThresholdLabels).toBe(true); }); + + it('change from angular singlestatt with no enabled gauge', () => { + const old: any = { + angular: { + format: 'ms', + decimals: 7, + gauge: { + maxValue: 150, + minValue: -10, + show: false, + }, + }, + }; + + const newOptions = gaugePanelChangedHandler({} as any, 'singlestat', old); + expect(newOptions.fieldOptions.defaults.unit).toBe('ms'); + expect(newOptions.fieldOptions.defaults.min).toBe(undefined); + expect(newOptions.fieldOptions.defaults.max).toBe(undefined); + }); });