From 175c39a976b81da6eea82d56380e6100e3b54a47 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 11 Nov 2021 12:06:17 +0100 Subject: [PATCH] DataSourceRef: Fix migration for panels inside collapsed rows (#41590) --- .../dashboard/state/DashboardMigrator.test.ts | 14 ++++++++++++++ .../features/dashboard/state/DashboardMigrator.ts | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/public/app/features/dashboard/state/DashboardMigrator.test.ts b/public/app/features/dashboard/state/DashboardMigrator.test.ts index d4e34e7fcbf..ce67c1410aa 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.test.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.test.ts @@ -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' }); + }); }); }); diff --git a/public/app/features/dashboard/state/DashboardMigrator.ts b/public/app/features/dashboard/state/DashboardMigrator.ts index 216eb4115a6..323428eb191 100644 --- a/public/app/features/dashboard/state/DashboardMigrator.ts +++ b/public/app/features/dashboard/state/DashboardMigrator.ts @@ -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) {