Commit 5617db36 by Torkel Ödegaard Committed by GitHub

Merge pull request #16014 from alexanderzobnin/fix-15993

Panels: fix loading panels with non-array targets
parents 8859d16a c028d410
......@@ -3,9 +3,10 @@ import { PanelModel } from './PanelModel';
describe('PanelModel', () => {
describe('when creating new panel model', () => {
let model;
let modelJson;
beforeEach(() => {
model = new PanelModel({
modelJson = {
type: 'table',
showColumns: true,
targets: [{ refId: 'A' }, { noRefId: true }],
......@@ -23,7 +24,8 @@ describe('PanelModel', () => {
},
],
},
});
};
model = new PanelModel(modelJson);
});
it('should apply defaults', () => {
......@@ -38,6 +40,15 @@ describe('PanelModel', () => {
expect(model.targets[1].refId).toBe('B');
});
it("shouldn't break panel with non-array targets", () => {
modelJson.targets = {
0: { refId: 'A' },
foo: { bar: 'baz' },
};
model = new PanelModel(modelJson);
expect(model.targets[0].refId).toBe('A');
});
it('getSaveModel should remove defaults', () => {
const saveModel = model.getSaveModel();
expect(saveModel.gridPos).toBe(undefined);
......
......@@ -125,7 +125,7 @@ export class PanelModel {
}
ensureQueryIds() {
if (this.targets) {
if (this.targets && _.isArray(this.targets)) {
for (const query of this.targets) {
if (!query.refId) {
query.refId = this.getNextQueryLetter();
......
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