public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aditya Toshniwal <[email protected]>
To: pgadmin-hackers <[email protected]>
Subject: [pgAdmin][RM6193] Should warn before closing if opened in a new tab
Date: Mon, 1 Feb 2021 14:12:39 +0530
Message-ID: <CAM9w-_mck6GS3-iDeUBspbWiEapEA6uF4MhiyLiTSZvRku4xxQ@mail.gmail.com> (raw)

Hi Hackers,

ERD will now throw warning before closing unsaved changes if opened in a
new tab.
Please review.

-- 
Thanks,
Aditya Toshniwal
pgAdmin hacker | Sr. Software Engineer | *edbpostgres.com*
<http://edbpostgres.com;
"Don't Complain about Heat, Plant a TREE"


Attachments:

  [application/octet-stream] RM6193.patch (1.8K, 3-RM6193.patch)
  download | inline diff:
diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
index f2de8edb9..3935af360 100644
--- a/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
+++ b/web/pgadmin/tools/erd/static/js/erd_tool/ERDCore.js
@@ -355,9 +355,14 @@ export default class ERDCore {
 
   zoomOut() {
     let model = this.getEngine().getModel();
-    let zoomLevel = model.getZoomLevel();
-    if(model && zoomLevel > 25) {
-      model.setZoomLevel(zoomLevel - 25);
+    if(model) {
+      let zoomLevel = model.getZoomLevel();
+      zoomLevel -= 25;
+      /* Don't go belo zoom level 10 */
+      if(zoomLevel <= 10) {
+        zoomLevel = 10;
+      }
+      model.setZoomLevel(zoomLevel);
       this.repaint();
     }
   }
diff --git a/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx b/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx
index 90c284ab8..5451e868f 100644
--- a/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx
+++ b/web/pgadmin/tools/erd/static/js/erd_tool/ui_components/BodyWidget.jsx
@@ -235,6 +235,12 @@ export default class BodyWidget extends React.Component {
     if(this.props.params.gen) {
       await this.loadTablesData();
     }
+
+    window.addEventListener('beforeunload', this.onBeforeUnload.bind(this));
+  }
+
+  componentWillUnmount() {
+    window.removeEventListener('beforeunload', this.onBeforeUnload.bind(this));
   }
 
   componentDidUpdate() {
@@ -348,6 +354,15 @@ export default class BodyWidget extends React.Component {
     }
   }
 
+  onBeforeUnload(e) {
+    if(this.state.dirty) {
+      e.preventDefault();
+      e.returnValue = 'prevent';
+    } else {
+      delete e['returnValue'];
+    }
+  }
+
   onEditNode() {
     const selected = this.diagram.getSelectedNodes();
     if(selected.length == 1) {


view thread (2+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected]
  Subject: Re: [pgAdmin][RM6193] Should warn before closing if opened in a new tab
  In-Reply-To: <CAM9w-_mck6GS3-iDeUBspbWiEapEA6uF4MhiyLiTSZvRku4xxQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox