PanelEditor: fixes save/apply for undefined props in restoreModel (#23939)

* PanelEditor: fixes save/apply for undefined props in restoreModel

* Refactor: changes after PR comments

* Refactor: changes sourcePanel refresh strategy

* Added unit tests and minor refactoring of method, starting with cleanup, then setting properties from model

* Update public/app/features/dashboard/state/PanelModel.test.ts

Co-authored-by: Torkel Ödegaard <torkel@grafana.com>
Co-authored-by: Dominik Prokop <dominik.prokop@grafana.com>
This commit is contained in:
Hugo Häggmark
2020-04-27 20:50:33 +02:00
committed by GitHub
parent 0dc8f4ea89
commit d91c0d1dec
5 changed files with 90 additions and 14 deletions

View File

@@ -12,10 +12,10 @@ import {
DataQueryResponseData,
DataTransformerConfig,
eventFactory,
FieldConfigSource,
PanelEvents,
PanelPlugin,
ScopedVars,
FieldConfigSource,
} from '@grafana/data';
import { EDIT_PANEL_ID } from 'app/core/constants';
@@ -158,6 +158,35 @@ 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]) {
continue;
}
if (model[property]) {
continue;
}
if (!this.hasOwnProperty(property)) {
continue;
}
if (typeof (this as any)[property] === 'function') {
continue;
}
if (typeof (this as any)[property] === 'symbol') {
continue;
}
delete (this as any)[property];
}
// copy properties from persisted model
for (const property in model) {
(this as any)[property] = model[property];