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:
@@ -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[]) {
|
function createRow(options: any, panelDescriptions: any[]) {
|
||||||
|
|||||||
@@ -955,7 +955,12 @@ function upgradeValueMappingsForPanel(panel: PanelModel) {
|
|||||||
return panel;
|
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
|
// Protect against no overrides
|
||||||
if (Array.isArray(fieldConfig.overrides)) {
|
if (Array.isArray(fieldConfig.overrides)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user