mirror of
https://github.com/grafana/grafana.git
synced 2024-11-29 04:04:00 -06:00
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:
parent
beca793008
commit
81511e34d9
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
// Protect against no overrides
|
||||
if (Array.isArray(fieldConfig.overrides)) {
|
||||
|
Loading…
Reference in New Issue
Block a user