Avoid breaking on fieldConfig without defaults field (#36666)

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`.
This commit is contained in:
Gustaf Lindstedt 2021-07-13 09:43:09 +02:00 committed by GitHub
parent beca793008
commit 81511e34d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 44 additions and 1 deletions

View File

@ -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[]) {

View File

@ -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
);
}
// Protect against no overrides
if (Array.isArray(fieldConfig.overrides)) {