Fix query tool, ERD closing issue in Electron. #7494

pull/7680/head
Aditya Toshniwal 2024-07-10 15:01:35 +05:30
parent dbdea181a9
commit cd6ff48cc0
5 changed files with 41 additions and 28 deletions

View File

@ -34,13 +34,15 @@ Housekeeping
Bug fixes
*********
| `Issue #3199 <https://github.com/pgadmin-org/pgadmin4/issues/3199>`_ - Fixed an issue where paste operation in query tool data grid should skip bytea columns and put the value as NULL instead.
| `Issue #4165 <https://github.com/pgadmin-org/pgadmin4/issues/4165>`_ - Fixed an issue where the taskbar icon appeared as a red square for the query tool and schema diff when opened in a new window.
| `Issue #5345 <https://github.com/pgadmin-org/pgadmin4/issues/5345>`_ - Fix issue with missing new added records in download file.
| `Issue #5610 <https://github.com/pgadmin-org/pgadmin4/issues/5610>`_ - Fixed an issue where the File Open dialog did not show files without a dot extension.
| `Issue #6548 <https://github.com/pgadmin-org/pgadmin4/issues/6548>`_ - Ensure pgAdmin never makes network requests to Google etc.
| `Issue #6571 <https://github.com/pgadmin-org/pgadmin4/issues/6571>`_ - Fixed an issue where pop-up notifications from Object Explorer wouldn't get dismissed automatically if the Query Tool was open.
| `Issue #6571 <https://github.com/pgadmin-org/pgadmin4/issues/6571>`_ - Fixed an issue where pop-up notifications from Object Explorer wouldn't get dismissed automatically if the Query Tool was opened.
| `Issue #7035 <https://github.com/pgadmin-org/pgadmin4/issues/7035>`_ - Fixed the permission denied issue for functions of the pgstattuple extension when accessing statistics with a non-admin user.
| `Issue #7511 <https://github.com/pgadmin-org/pgadmin4/issues/7511>`_ - Fixed an issue where users could not insert characters at the desired location, as it was added to the end of the line.
| `Issue #7554 <https://github.com/pgadmin-org/pgadmin4/issues/7554>`_ - Fixed an issue where sorting the database activity table on the dashboard by any column caused the details to expand in the wrong position.
| `Issue #7618 <https://github.com/pgadmin-org/pgadmin4/issues/7618>`_ - Fix an issue where the preferences JSON file has no effect when an external database is used.
| `Issue #7627 <https://github.com/pgadmin-org/pgadmin4/issues/7627>`_ - Fixed an issue where users could not autofill their saved passwords in the connect server dialog in the browser.
| `Issue #7638 <https://github.com/pgadmin-org/pgadmin4/issues/7638>`_ - Fixed an issue where Generate Script button should be disabled if no objects are selected in the schema diff result.

View File

@ -21,6 +21,7 @@ import usePreferences from '../../preferences/static/js/store';
import { getBrowser } from './utils';
import PropTypes from 'prop-types';
import Processes from '../../misc/bgprocess/static/js/Processes';
import { useBeforeUnload } from './custom_hooks';
const objectExplorerGroup = {
@ -90,9 +91,23 @@ export default function BrowserComponent({pgAdmin}) {
]
},
};
const {isLoading, failed} = usePreferences();
const {isLoading, failed, getPreferencesForModule} = usePreferences();
let { name: browser } = useMemo(()=>getBrowser(), []);
const [uiReady, setUiReady] = useState(false);
const confirmOnClose = getPreferencesForModule('browser').confirm_on_refresh_close;
useBeforeUnload({
enabled: confirmOnClose,
beforeClose: (forceClose)=>{
pgAdmin.Browser.notifier.confirm(
gettext('Quit pgAdmin 4'),
gettext('Are you sure you want to quit the application?'),
function() { forceClose(); },
function() { return true;},
);
},
isNewTab: true,
});
useEffect(()=>{
if(uiReady) {

View File

@ -220,13 +220,24 @@ export function useBeforeUnload({enabled, isNewTab, beforeClose, closePanel }) {
const onBeforeUnloadElectron = useCallback((e)=>{
e.preventDefault();
e.returnValue = 'prevent';
beforeClose?.();
beforeClose?.(forceClose);
}, []);
useEffect(()=>{
if(getBrowser().name == 'Electron') {
window.addEventListener('beforeunload', onBeforeUnloadElectron);
function forceClose() {
if(getBrowser().name == 'Electron' && isNewTab) {
window.removeEventListener('beforeunload', onBeforeUnloadElectron);
// somehow window.close was not working may becuase the removeEventListener
// was not completely executed. Add timeout.
setTimeout(()=>window.close(), 50);
} else {
closePanel?.();
}
}
useEffect(()=>{
if(getBrowser().name == 'Electron' && isNewTab) {
window.addEventListener('beforeunload', onBeforeUnloadElectron);
} else if(getBrowser().name != 'Electron') {
if(enabled){
window.addEventListener('beforeunload', onBeforeUnload);
} else {
@ -240,17 +251,5 @@ export function useBeforeUnload({enabled, isNewTab, beforeClose, closePanel }) {
};
}, [enabled]);
function forceClose() {
if(getBrowser().name == 'Electron' && isNewTab) {
window.removeEventListener('beforeunload', onBeforeUnloadElectron);
// somehow window.close was not working may becuase the removeEventListener
// was not completely executed. Add timeout.
setTimeout(()=>window.close(), 50);
} else {
closePanel?.();
}
}
return {forceClose};
}

View File

@ -2,13 +2,11 @@ import React from 'react';
import PropTypes from 'prop-types';
import { useBeforeUnload } from '../../../../../../static/js/custom_hooks';
export default function BeforeUnload({enabled, isNewTab, beforeClose, closePanel, getForceClose}) {
const {forceClose} = useBeforeUnload(
export default function BeforeUnload({enabled, isNewTab, beforeClose, closePanel}) {
useBeforeUnload(
{enabled, isNewTab, beforeClose, closePanel}
);
getForceClose(forceClose);
return <></>;
}

View File

@ -357,7 +357,7 @@ export default class ERDTool extends React.Component {
}
}
confirmBeforeClose() {
confirmBeforeClose(forceClose) {
let bodyObj = this;
if(this.state.dirty) {
this.closeOnSave = false;
@ -366,7 +366,7 @@ export default class ERDTool extends React.Component {
closeModal={closeModal}
text={gettext('The diagram has changed. Do you want to save changes?')}
onDontSave={()=>{
bodyObj.forceClose();
forceClose();
}}
onSave={()=>{
bodyObj.onSaveDiagram(false, true);
@ -375,7 +375,7 @@ export default class ERDTool extends React.Component {
));
return false;
} else {
this.forceClose();
forceClose();
}
}
@ -888,11 +888,10 @@ export default class ERDTool extends React.Component {
<BeforeUnload
enabled={this.state.is_close_tab_warning}
isNewTab={this.state.is_new_tab}
beforeClose={()=>{
this.confirmBeforeClose();
beforeClose={(forceClose)=>{
this.confirmBeforeClose(forceClose);
}}
closePanel={this.closePanel}
getForceClose={(fn)=>this.forceClose = fn}
/>
<ConnectionBar status={this.state.conn_status} bgcolor={this.props.params.bgcolor}
fgcolor={this.props.params.fgcolor} title={_.unescape(this.props.params.title)}/>