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
parent
16e28bb998
commit
1979ea53c7
|
@ -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() {
|
||||
|
|
|
@ -319,6 +319,10 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
|
|||
reflectPreferences();
|
||||
});
|
||||
|
||||
pgWindow.pgAdmin.Browser.onPreferencesChange('browser', function() {
|
||||
reflectPreferences();
|
||||
});
|
||||
|
||||
/* WC docker events */
|
||||
panel?.on(window.wcDocker.EVENT.CLOSING, function() {
|
||||
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);
|
||||
}
|
||||
});
|
||||
window.addEventListener('beforeunload', onBeforeUnload);
|
||||
}, []);
|
||||
|
||||
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)=>{
|
||||
let currSelectedConn = _.find(qtState.connection_list, (c)=>c.is_selected);
|
||||
let currConnected = qtState.connected;
|
||||
|
|
Loading…
Reference in New Issue