Commit f2415a31 by lzd Committed by Dominik Prokop

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
parent be2bf1a2
...@@ -24,6 +24,7 @@ describe('PanelModel', () => { ...@@ -24,6 +24,7 @@ describe('PanelModel', () => {
}, },
], ],
}, },
arrayWith2Values: [{ value: 'name' }, { value: 'name2' }],
showThresholds: true, showThresholds: true,
}; };
...@@ -43,6 +44,7 @@ describe('PanelModel', () => { ...@@ -43,6 +44,7 @@ describe('PanelModel', () => {
}, },
], ],
}, },
arrayWith2Values: [{ name: 'changed to only one value' }],
}; };
modelJson = { modelJson = {
...@@ -72,6 +74,10 @@ describe('PanelModel', () => { ...@@ -72,6 +74,10 @@ describe('PanelModel', () => {
expect(model.getOptions().showThresholds).toBeTruthy(); 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', () => { it('should set model props on instance', () => {
expect(model.showColumns).toBe(true); expect(model.showColumns).toBe(true);
}); });
......
...@@ -255,7 +255,16 @@ export class PanelModel { ...@@ -255,7 +255,16 @@ export class PanelModel {
if (plugin.angularConfigCtrl) { if (plugin.angularConfigCtrl) {
return; 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) { pluginLoaded(plugin: PanelPlugin) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment