mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
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:
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user