PanelEditor: Fixed issue changing a panel from transparent back to normal (#24483)

* PanelModel: Fixed issues with persisting some changes

* Fixed other issues
This commit is contained in:
Torkel Ödegaard
2020-05-11 22:03:43 +02:00
committed by GitHub
parent 3f31028bf8
commit 5caf7f59e6
5 changed files with 50 additions and 35 deletions

View File

@@ -82,6 +82,8 @@ const mustKeepProps: { [str: string]: boolean } = {
transformations: true,
fieldConfig: true,
editSourceId: true,
maxDataPoints: true,
interval: true,
};
const defaults: any = {
@@ -90,6 +92,7 @@ const defaults: any = {
cachedPluginOptions: {},
transparent: false,
options: {},
datasource: null,
};
export class PanelModel implements DataConfigSource {
@@ -146,9 +149,6 @@ export class PanelModel implements DataConfigSource {
constructor(model: any) {
this.events = new Emitter();
// should not be part of defaults as defaults are removed in save model and
// this should not be removed in save model as exporter needs to templatize it
this.datasource = null;
this.restoreModel(model);
this.replaceVariables = this.replaceVariables.bind(this);
}
@@ -156,12 +156,8 @@ export class PanelModel implements DataConfigSource {
/** Given a persistened PanelModel restores property values */
restoreModel(model: any) {
// Start with clean-up
for (const property of Object.keys(this)) {
if (notPersistedProperties[property]) {
continue;
}
if (mustKeepProps[property]) {
for (const property in this) {
if (notPersistedProperties[property] || !this.hasOwnProperty(property)) {
continue;
}
@@ -169,10 +165,6 @@ export class PanelModel implements DataConfigSource {
continue;
}
if (!this.hasOwnProperty(property)) {
continue;
}
if (typeof (this as any)[property] === 'function') {
continue;
}
@@ -215,7 +207,6 @@ export class PanelModel implements DataConfigSource {
updateOptions(options: object) {
this.options = options;
this.render();
}
@@ -228,6 +219,7 @@ export class PanelModel implements DataConfigSource {
getSaveModel() {
const model: any = {};
for (const property in this) {
if (notPersistedProperties[property] || !this.hasOwnProperty(property)) {
continue;
@@ -239,6 +231,13 @@ export class PanelModel implements DataConfigSource {
model[property] = _.cloneDeep(this[property]);
}
if (model.datasource === undefined) {
// This is part of defaults as defaults are removed in save model and
// this should not be removed in save model as exporter needs to templatize it
model.datasource = null;
}
return model;
}