From eea3ea9755177bf422060bbd4a4fcae590af734d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 17 Jun 2021 18:27:13 +0200 Subject: [PATCH] Postgres/MySQL: Fixes issue with toggle query editor mode (#35890) * Postgres/MySQL: Fixes issue with toggle query editor mode * PostGres/MySQL: Use $evalAsync instead of manual $digest Co-authored-by: Ashley Harrison --- 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; + }); } }