Avoid breaking on fieldConfig without defaults field (#36666) (#36690)

This would result in a `Dashboard init failed` error when migrating
dashboards with a folded panel that has a `fieldConfig` but has not
defined `fieldConfig.defaults`.

(cherry picked from commit 81511e34d9)

Co-authored-by: Gustaf Lindstedt <gustaflindstedt@protonmail.com>
This commit is contained in:
Grot (@grafanabot)
2021-07-13 10:14:05 +02:00
committed by GitHub
co-authored by Gustaf Lindstedt
parent fb60ab66f1
commit 68374a988a
2 changed files with 44 additions and 1 deletions
@@ -1382,6 +1382,44 @@ describe('DashboardModel', () => {
`);
});
});
describe('when migrating folded panel without fieldConfig.defaults', () => {
let model: DashboardModel;
beforeEach(() => {
model = new DashboardModel({
schemaVersion: 29,
panels: [
{
id: 1,
type: 'timeseries',
panels: [
{
id: 2,
fieldConfig: {
overrides: [
{
matcher: { id: 'byName', options: 'D-series' },
properties: [
{
id: 'displayName',
value: 'foobar',
},
],
},
],
},
},
],
},
],
});
});
it('should ignore fieldConfig.defaults', () => {
expect(model.panels[0].panels[0].fieldConfig.defaults).toEqual(undefined);
});
});
});
function createRow(options: any, panelDescriptions: any[]) {
@@ -955,7 +955,12 @@ function upgradeValueMappingsForPanel(panel: PanelModel) {
return panel;
}
fieldConfig.defaults.mappings = upgradeValueMappings(fieldConfig.defaults.mappings, fieldConfig.defaults.thresholds);
if (fieldConfig.defaults) {
fieldConfig.defaults.mappings = upgradeValueMappings(
fieldConfig.defaults.mappings,
fieldConfig.defaults.thresholds
);
}
for (const override of fieldConfig.overrides) {
for (const prop of override.properties) {