From f2415a319eac2f8944918475304ad3ba44c8eefc Mon Sep 17 00:00:00 2001 From: lzd <24379844+lzdw@users.noreply.github.com> Date: Fri, 8 Nov 2019 16:46:53 +0800 Subject: [PATCH] Gauge Panel: fix the default value of thresholds cannot be modified (#20190) * Panel: fix the default value of thresholds cannot be modified in Gauge panel * Panel: fix the default value of thresholds cannot be modified in Gauge panel --- .../app/features/dashboard/state/PanelModel.test.ts | 6 ++++++ public/app/features/dashboard/state/PanelModel.ts | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard/state/PanelModel.test.ts b/public/app/features/dashboard/state/PanelModel.test.ts index a5f0e889a6e..e39f9267695 100644 --- a/public/app/features/dashboard/state/PanelModel.test.ts +++ b/public/app/features/dashboard/state/PanelModel.test.ts @@ -24,6 +24,7 @@ describe('PanelModel', () => { }, ], }, + arrayWith2Values: [{ value: 'name' }, { value: 'name2' }], showThresholds: true, }; @@ -43,6 +44,7 @@ describe('PanelModel', () => { }, ], }, + arrayWith2Values: [{ name: 'changed to only one value' }], }; modelJson = { @@ -72,6 +74,10 @@ describe('PanelModel', () => { expect(model.getOptions().showThresholds).toBeTruthy(); }); + it('should apply option defaults but not override if array is changed', () => { + expect(model.getOptions().arrayWith2Values.length).toBe(1); + }); + it('should set model props on instance', () => { expect(model.showColumns).toBe(true); }); diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index 5620d8dd485..a57294e80b0 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -255,7 +255,16 @@ export class PanelModel { if (plugin.angularConfigCtrl) { return; } - this.options = _.defaultsDeep({}, this.options || {}, plugin.defaults); + this.options = _.mergeWith( + {}, + plugin.defaults, + this.options || {}, + (objValue: any, srcValue: any): any => { + if (_.isArray(srcValue)) { + return srcValue; + } + } + ); } pluginLoaded(plugin: PanelPlugin) {