Browse Source

add warning when switching from raw sql mode

Sven Klemm 7 years ago
parent
commit
7e9c9199c1
1 changed files with 14 additions and 1 deletions
  1. 14 1
      public/app/plugins/datasource/postgres/query_ctrl.ts

+ 14 - 1
public/app/plugins/datasource/postgres/query_ctrl.ts

@@ -1,4 +1,5 @@
 import _ from 'lodash';
+import appEvents from 'app/core/app_events';
 import { PostgresMetaQuery } from './meta_query';
 import { QueryCtrl } from 'app/plugins/sdk';
 import { SqlPart } from 'app/core/components/sql_part/sql_part';
@@ -146,7 +147,19 @@ export class PostgresQueryCtrl extends QueryCtrl {
   }
 
   toggleEditorMode() {
-    this.target.rawQuery = !this.target.rawQuery;
+    if (this.target.rawQuery) {
+      appEvents.emit('confirm-modal', {
+        title: 'Warning',
+        text2: 'Switching to query builder may overwrite your raw SQL.',
+        icon: 'fa-exclamation',
+        yesText: 'Switch',
+        onConfirm: () => {
+          this.target.rawQuery = !this.target.rawQuery;
+        },
+      });
+    } else {
+      this.target.rawQuery = !this.target.rawQuery;
+    }
   }
 
   resetPlusButton(button) {