From 85f3a999f372c0478fc799b4e12ca54cf77c1a6a Mon Sep 17 00:00:00 2001 From: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Date: Wed, 22 Jul 2020 13:29:30 +0200 Subject: [PATCH] Fix matrics comparison to know when to refresh (#26382) --- .../datasource/elasticsearch/query_ctrl.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts index fa5831c8c4e..36b55a43ca2 100644 --- a/public/app/plugins/datasource/elasticsearch/query_ctrl.ts +++ b/public/app/plugins/datasource/elasticsearch/query_ctrl.ts @@ -15,6 +15,7 @@ export class ElasticQueryCtrl extends QueryCtrl { esVersion: any; rawQueryOld: string; + targetMetricsOld: string; /** @ngInject */ constructor( @@ -51,18 +52,17 @@ export class ElasticQueryCtrl extends QueryCtrl { } queryUpdated() { - // As Raw Data and Raw Document have the same request, we need to run refresh if they are updated - const isPossiblyRawDataSwitch = this.target.metrics.some( - (metric: any) => metric.type === 'raw_data' || metric.type === 'raw_document' - ); - const newJson = angular.toJson(this.datasource.queryBuilder.build(this.target), true); - if (this.rawQueryOld && newJson !== this.rawQueryOld) { - this.refresh(); - } else if (isPossiblyRawDataSwitch) { + const newJsonTargetMetrics = angular.toJson(this.target.metrics); + const newJsonRawQuery = angular.toJson(this.datasource.queryBuilder.build(this.target), true); + if ( + (this.rawQueryOld && newJsonRawQuery !== this.rawQueryOld) || + (this.targetMetricsOld && newJsonTargetMetrics !== this.targetMetricsOld) + ) { this.refresh(); } - this.rawQueryOld = newJson; + this.rawQueryOld = newJsonRawQuery; + this.targetMetricsOld = newJsonTargetMetrics; this.$rootScope.appEvent(CoreEvents.elasticQueryUpdated); }