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,
|
dirty: false,
|
||||||
show_details: true,
|
show_details: true,
|
||||||
is_new_tab: false,
|
is_new_tab: false,
|
||||||
|
is_close_tab_warning: true,
|
||||||
preferences: {},
|
preferences: {},
|
||||||
table_dialog_open: true,
|
table_dialog_open: true,
|
||||||
oto_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'),
|
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 || '')
|
is_new_tab: (this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('browser').new_browser_tab_open || '')
|
||||||
.includes('erd_tool'),
|
.includes('erd_tool'),
|
||||||
|
is_close_tab_warning: this.props.pgWindow.pgAdmin.Browser.get_preferences_for_module('browser').confirm_on_refresh_close,
|
||||||
}, ()=>{
|
}, ()=>{
|
||||||
this.registerKeyboardShortcuts();
|
this.registerKeyboardShortcuts();
|
||||||
this.setTitle(this.state.current_file);
|
this.setTitle(this.state.current_file);
|
||||||
@@ -313,6 +315,12 @@ class ERDTool extends React.Component {
|
|||||||
}, ()=>this.registerKeyboardShortcuts());
|
}, ()=>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, () => {
|
this.props.panel?.on(window.wcDocker?.EVENT.CLOSING, () => {
|
||||||
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
window.removeEventListener('beforeunload', this.onBeforeUnload);
|
||||||
if(this.state.dirty) {
|
if(this.state.dirty) {
|
||||||
@@ -342,7 +350,12 @@ class ERDTool extends React.Component {
|
|||||||
await this.loadTablesData();
|
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() {
|
componentWillUnmount() {
|
||||||
@@ -353,6 +366,12 @@ class ERDTool extends React.Component {
|
|||||||
if(this.state.dirty) {
|
if(this.state.dirty) {
|
||||||
this.setTitle(this.state.current_file, true);
|
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() {
|
confirmBeforeClose() {
|
||||||
|
|||||||
@@ -319,6 +319,10 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
reflectPreferences();
|
reflectPreferences();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
pgWindow.pgAdmin.Browser.onPreferencesChange('browser', function() {
|
||||||
|
reflectPreferences();
|
||||||
|
});
|
||||||
|
|
||||||
/* WC docker events */
|
/* WC docker events */
|
||||||
panel?.on(window.wcDocker.EVENT.CLOSING, function() {
|
panel?.on(window.wcDocker.EVENT.CLOSING, function() {
|
||||||
window.removeEventListener('beforeunload', onBeforeUnload);
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
@@ -337,7 +341,6 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL);
|
eventBus.current.fireEvent(QUERY_TOOL_EVENTS.GOTO_LAST_SCROLL);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('beforeunload', onBeforeUnload);
|
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
useEffect(()=>{
|
useEffect(()=>{
|
||||||
@@ -487,6 +490,19 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(()=> {
|
||||||
|
// Add beforeunload event if "Confirm on close or refresh" option is enabled in the preferences.
|
||||||
|
if(qtState.preferences.browser.confirm_on_refresh_close){
|
||||||
|
window.addEventListener('beforeunload', onBeforeUnload);
|
||||||
|
} else {
|
||||||
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener('beforeunload', onBeforeUnload);
|
||||||
|
};
|
||||||
|
}, [qtState.preferences.browser]);
|
||||||
|
|
||||||
const updateQueryToolConnection = (connectionData, isNew=false)=>{
|
const updateQueryToolConnection = (connectionData, isNew=false)=>{
|
||||||
let currSelectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
|
let currSelectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
|
||||||
let currConnected = qtState.connected;
|
let currConnected = qtState.connected;
|
||||||
|
|||||||
Reference in New Issue
Block a user