From 43ab6bee9c97fa6d878996ae4ab3c69eac37f125 Mon Sep 17 00:00:00 2001 From: "Grot (@grafanabot)" <43478413+grafanabot@users.noreply.github.com> Date: Thu, 17 Jun 2021 12:53:52 -0400 Subject: [PATCH] Postgres/MySQL: Fixes issue with toggle query editor mode (#35890) (#35894) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Postgres/MySQL: Fixes issue with toggle query editor mode * PostGres/MySQL: Use $evalAsync instead of manual $digest Co-authored-by: Ashley Harrison (cherry picked from commit eea3ea9755177bf422060bbd4a4fcae590af734d) Co-authored-by: Torkel Ödegaard --- public/app/plugins/datasource/mysql/query_ctrl.ts | 12 ++++++++++-- public/app/plugins/datasource/postgres/query_ctrl.ts | 12 ++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/public/app/plugins/datasource/mysql/query_ctrl.ts b/public/app/plugins/datasource/mysql/query_ctrl.ts index c33f709d076..67ca7b6d694 100644 --- a/public/app/plugins/datasource/mysql/query_ctrl.ts +++ b/public/app/plugins/datasource/mysql/query_ctrl.ts @@ -164,12 +164,20 @@ export class MysqlQueryCtrl extends QueryCtrl { icon: 'exclamation-triangle', yesText: 'Switch', onConfirm: () => { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); }, }) ); } else { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); } } diff --git a/public/app/plugins/datasource/postgres/query_ctrl.ts b/public/app/plugins/datasource/postgres/query_ctrl.ts index 39743775032..4327b3ae8db 100644 --- a/public/app/plugins/datasource/postgres/query_ctrl.ts +++ b/public/app/plugins/datasource/postgres/query_ctrl.ts @@ -196,12 +196,20 @@ export class PostgresQueryCtrl extends QueryCtrl { icon: 'exclamation-triangle', yesText: 'Switch', onConfirm: () => { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); }, }) ); } else { - this.target.rawQuery = !this.target.rawQuery; + // This could be called from React, so wrap in $evalAsync. + // Will then either run as part of the current digest cycle or trigger a new one. + this.$scope.$evalAsync(() => { + this.target.rawQuery = !this.target.rawQuery; + }); } }