From 264f79072899746129d7bbb1c5554e0fb092d72d Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Mon, 1 Feb 2021 05:18:17 -0600 Subject: [PATCH] PanelEdit: Trigger refresh when changing data source (#30744) (#30767) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit a8a3e02699e48affc766617f636e12a089000c71) Co-authored-by: Torkel Ödegaard --- .../components/PanelEditor/PanelEditorQueries.tsx | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx index 3da8317592b..310a6314b96 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx @@ -49,7 +49,10 @@ export class PanelEditorQueries extends PureComponent { onOptionsChange = (options: QueryGroupOptions) => { const { panel } = this.props; - panel.datasource = options.dataSource.default ? null : options.dataSource.name!; + const newDataSourceName = options.dataSource.default ? null : options.dataSource.name!; + const dataSourceChanged = newDataSourceName !== panel.datasource; + + panel.datasource = newDataSourceName; panel.targets = options.queries; panel.timeFrom = options.timeRange?.from; panel.timeShift = options.timeRange?.shift; @@ -57,6 +60,11 @@ export class PanelEditorQueries extends PureComponent { panel.interval = options.minInterval; panel.maxDataPoints = options.maxDataPoints; + if (dataSourceChanged) { + // trigger queries when changing data source + setTimeout(this.onRunQueries, 10); + } + this.setState({ options: options }); };