Ensure that ERD throws a warning before closing unsaved changes if open in a new tab. Fixes #6193

This commit is contained in:
Aditya Toshniwal 2021-02-02 11:47:10 +05:30 committed by Akshay Joshi
parent e10dd6a80f
commit 75f887f5dc
3 changed files with 24 additions and 3 deletions

View File

@ -30,3 +30,4 @@ Bug fixes
| `Issue #6179 <https://redmine.postgresql.org/issues/6179>`_ - Fixed an issue where Generate SQL displayed twice in the ERD tool.
| `Issue #6180 <https://redmine.postgresql.org/issues/6180>`_ - Updated missing documentation for the 'Download Image' option in ERD.
| `Issue #6187 <https://redmine.postgresql.org/issues/6187>`_ - Limit the upgrade check to run once per day.
| `Issue #6193 <https://redmine.postgresql.org/issues/6193>`_ - Ensure that ERD throws a warning before closing unsaved changes if open in a new tab.

View File

@ -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();
}
}

View File

@ -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) {