Fixed an issue where the 'Confirm on close or refresh' setting was ignored when closing the query/ERD tool opened in the new tab. #5475

This commit is contained in:
Nikhil Mohite
2022-11-02 14:03:52 +05:30
committed by GitHub
parent 16e28bb998
commit 1979ea53c7
2 changed files with 37 additions and 2 deletions

View File

@@ -114,6 +114,7 @@ class ERDTool extends React.Component {
dirty: false,
show_details: true,
is_new_tab: false,
is_close_tab_warning: true,
preferences: {},
table_dialog_open: true,
oto_dialog_open: true,
@@ -297,6 +298,7 @@ class ERDTool extends React.Component {
preferences: this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('erd'),
is_new_tab: (this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('browser').new_browser_tab_open || '')
.includes('erd_tool'),
is_close_tab_warning: this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('browser').confirm_on_refresh_close,
}, ()=>{
this.registerKeyboardShortcuts();
this.setTitle(this.state.current_file);
@@ -313,6 +315,12 @@ class ERDTool extends React.Component {
}, ()=>this.registerKeyboardShortcuts());
});
this.props.pgWindow.pgAdmin.Browser.onPreferencesChange('browser', () => {
this.setState({
is_close_tab_warning: this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('browser').confirm_on_refresh_close,
});
});
this.props.panel?.on(window.wcDocker?.EVENT.CLOSING, () => {
window.removeEventListener('beforeunload', this.onBeforeUnload);
if(this.state.dirty) {
@@ -342,7 +350,12 @@ class ERDTool extends React.Component {
await this.loadTablesData();
}
window.addEventListener('beforeunload', this.onBeforeUnload);
if(this.state.is_close_tab_warning) {
window.addEventListener('beforeunload', this.onBeforeUnload);
} else {
window.removeEventListener('beforeunload', this.onBeforeUnload);
}
}
componentWillUnmount() {
@@ -353,6 +366,12 @@ class ERDTool extends React.Component {
if(this.state.dirty) {
this.setTitle(this.state.current_file, true);
}
// Add beforeunload event if "Confirm on close or refresh" option is enabled in the preferences.
if(this.state.is_close_tab_warning){
window.addEventListener('beforeunload', this.onBeforeUnload);
} else {
window.removeEventListener('beforeunload', this.onBeforeUnload);
}
}
confirmBeforeClose() {