mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user