Skip to content

Commit

Permalink
Dashboard: Fix export for sharing when panels use default data source (
Browse files Browse the repository at this point in the history
…#19315)

* PanelModel: moved datasource: null away from defaults that are removed

* Added unit test
  • Loading branch information
torkelo committed Sep 24, 2019
1 parent 4dbedb8 commit ac3fb64
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 5 additions & 0 deletions public/app/features/dashboard/state/PanelModel.test.ts
Expand Up @@ -93,6 +93,11 @@ describe('PanelModel', () => {
expect(saveModel.gridPos).toBe(undefined);
});

it('getSaveModel should not remove datasource default', () => {
const saveModel = model.getSaveModel();
expect(saveModel.datasource).toBe(null);
});

it('getSaveModel should remove nonPersistedProperties', () => {
const saveModel = model.getSaveModel();
expect(saveModel.events).toBe(undefined);
Expand Down
5 changes: 4 additions & 1 deletion public/app/features/dashboard/state/PanelModel.ts
Expand Up @@ -69,7 +69,6 @@ const mustKeepProps: { [str: string]: boolean } = {

const defaults: any = {
gridPos: { x: 0, y: 0, h: 3, w: 6 },
datasource: null,
targets: [{ refId: 'A' }],
cachedPluginOptions: {},
transparent: false,
Expand Down Expand Up @@ -126,6 +125,10 @@ export class PanelModel {
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;

// copy properties from persisted model
for (const property in model) {
(this as any)[property] = model[property];
Expand Down

0 comments on commit ac3fb64

Please sign in to comment.