DataSourceRef: Fix migration for panels inside collapsed rows (#41590)

This commit is contained in:
Torkel Ödegaard 2021-11-11 12:06:17 +01:00 committed by GitHub
parent 69c5370e94
commit 175c39a976
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -1801,6 +1801,16 @@ describe('DashboardModel', () => {
},
],
},
{
type: 'row',
id: 5,
panels: [
{
id: 6,
datasource: 'prom',
},
],
},
],
});
});
@ -1824,6 +1834,10 @@ describe('DashboardModel', () => {
it('should update target datasource props to refs', () => {
expect(model.panels[2].targets[0].datasource).toEqual({ type: 'prometheus', uid: 'mock-ds-2' });
});
it('should update datasources in panels collapsed rows', () => {
expect(model.panels[3].panels[0].datasource).toEqual({ type: 'prometheus', uid: 'mock-ds-2' });
});
});
});

View File

@ -708,12 +708,11 @@ export class DashboardMigrator {
variable.datasource = migrateDatasourceNameToRef(variable.datasource);
}
// Mutate panel models
for (const panel of this.dashboard.panels) {
panelUpgrades.push((panel) => {
panel.datasource = migrateDatasourceNameToRef(panel.datasource);
if (!panel.targets) {
continue;
return panel;
}
for (const target of panel.targets) {
@ -722,7 +721,9 @@ export class DashboardMigrator {
target.datasource = targetRef;
}
}
}
return panel;
});
}
if (panelUpgrades.length === 0) {