Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 26 additions & 19 deletions runtime/src/js/pgadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ let startPageUrl = null;
let serverCheckUrl = null;
let pgAdminMainScreen = null;

let configureWindow = null,
viewLogWindow = null;

let serverPort = 5050;
let appStartTime = (new Date()).getTime();
const __dirname = path.dirname(fileURLToPath(import.meta.url));
Expand Down Expand Up @@ -77,7 +80,8 @@ contextMenu({
Menu.setApplicationMenu(null);

function openConfigure() {
const win = new BrowserWindow({
if (configureWindow === null){
configureWindow = new BrowserWindow({
show: false,
width: 600,
height: 580,
Expand All @@ -88,11 +92,12 @@ function openConfigure() {
preload: path.join(__dirname, 'other_preload.js'),
},
});
win.loadFile('./src/html/configure.html');
win.once('ready-to-show', ()=>{
win.show();
configureWindow.loadFile('./src/html/configure.html');
configureWindow.once('ready-to-show', ()=>{
configureWindow.show();
});
}
}

function showErrorDialog(intervalID) {
if(!splashWindow.isVisible()) {
Expand Down Expand Up @@ -304,21 +309,23 @@ function launchPgAdminWindow() {

setupMenu(pgAdminMainScreen, {
'view_logs': ()=>{
const win = new BrowserWindow({
show: false,
width: 800,
height: 460,
position: 'center',
resizable: false,
icon: '../../assets/pgAdmin4.png',
webPreferences: {
preload: path.join(__dirname, 'other_preload.js'),
},
});
win.loadFile('./src/html/view_log.html');
win.once('ready-to-show', ()=>{
win.show();
});
if(viewLogWindow === null){
viewLogWindow = new BrowserWindow({
show: false,
width: 800,
height: 460,
position: 'center',
resizable: false,
icon: '../../assets/pgAdmin4.png',
webPreferences: {
preload: path.join(__dirname, 'other_preload.js'),
},
});
viewLogWindow.loadFile('./src/html/view_log.html');
viewLogWindow.once('ready-to-show', ()=>{
viewLogWindow.show();
});
}
},
'configure': openConfigure,
'reloadApp': reloadApp,
Expand Down
2 changes: 1 addition & 1 deletion web/pgadmin/about/static/js/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class About {
pgAdmin.Browser.notifier.showModal(gettext('About %s', pgAdmin.Browser.utils.app_name), () => {
return <AboutComponent />;
}, { isFullScreen: false, isResizeable: true, showFullScreen: true,
isFullWidth: true, dialogWidth: dlgWidth, dialogHeight: dlgHeight, minHeight: dlgHeight
isFullWidth: true, dialogWidth: dlgWidth, dialogHeight: dlgHeight, minHeight: dlgHeight, id:'id-about'
});
}
}
Expand Down
1 change: 1 addition & 0 deletions web/pgadmin/browser/static/js/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export const BROWSER_PANELS = {
WELCOME_PSQL_TOOL: 'id-welcome-psql'
};


export const WORKSPACES = {
DEFAULT: 'default_workspace',
QUERY_TOOL: 'query_tool_workspace',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,6 @@ export default function PreferencesComponent({ ...props }) {
const text = `${gettext('All preferences will be reset to their default values.')}<br><br>${gettext('Do you want to proceed?')}<br><br>
${gettext('Note:')}<br> <ul style="padding-left:20px"><li style="list-style-type:disc">${gettext('The object explorer tree will be refreshed automatically to reflect the changes.')}</li>
<li style="list-style-type:disc">${gettext('If the application language changes, a reload of the application will be required. You can choose to reload later at your convenience.')}</li></ul>`;

pgAdmin.Browser.notifier.showModal(
gettext('Reset all preferences'),
(closeModal)=>{
Expand All @@ -710,7 +709,7 @@ ${gettext('Note:')}<br> <ul style="padding-left:20px"><li style="list-style-type
</StyledBox>
);
},
{ isFullScreen: false, isResizeable: false, showFullScreen: false, isFullWidth: false, showTitle: true},
{ isFullScreen: false, isResizeable: false, showFullScreen: false, isFullWidth: false, showTitle: true, id: 'id-reset-preferences'},
);
};

Expand Down
3 changes: 1 addition & 2 deletions web/pgadmin/preferences/static/js/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,13 @@ export default class Preferences {

// This is a callback function to show preferences.
show() {

// Render Preferences component
pgAdmin.Browser.notifier.showModal(gettext('Preferences'), (closeModal) => {
return <PreferencesComponent
renderTree={(prefTreeData) => {
// Render preferences tree component
return <PreferencesTree pgBrowser={this.pgBrowser} data={prefTreeData} />;
}} closeModal={closeModal} />;
}, { isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true, dialogWidth: 900, dialogHeight: 550 });
}, { isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true, dialogWidth: 900, dialogHeight: 550, id: 'id-preferences' });
}
}
7 changes: 5 additions & 2 deletions web/pgadmin/static/js/BrowserComponent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,18 @@ export default function BrowserComponent({pgAdmin}) {
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;},
function() { return true; },
gettext('Yes'),
gettext('No'),
'default',
'id-app-quit'
);
},
isNewTab: true,
Expand Down
10 changes: 5 additions & 5 deletions web/pgadmin/static/js/Dialogs/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export function showServerPassword() {
}}
/>
);
});
}, {id: 'id-connect-server'});
}

function masterPassCallbacks(masterpass_callback_queue) {
Expand Down Expand Up @@ -176,7 +176,7 @@ export function showMasterPassword(isPWDPresent, errmsg, masterpass_callback_que
}}
/>
);
});
}, {id: 'id-master-password'});
}
}

Expand Down Expand Up @@ -275,7 +275,7 @@ export function showChangeUserPassword(url) {
/>;
},
{ isFullScreen: false, isResizeable: true, showFullScreen: false, isFullWidth: true,
dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md});
dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md, id: 'id-change-password'});
}

export function showNamedRestorePoint() {
Expand Down Expand Up @@ -351,7 +351,7 @@ export function showChangeOwnership() {
/>;
},
{ isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true,
dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md});
dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md, id: 'id-change-owner' });
}

export function showUrlDialog() {
Expand Down Expand Up @@ -388,6 +388,6 @@ export function showQuickSearch() {
pgAdmin.Browser.notifier.showModal(gettext('Quick Search'), (closeModal) => {
return <QuickSearch closeModal={closeModal}/>;
},
{ isFullScreen: false, isResizeable: false, showFullScreen: false, isFullWidth: false, showTitle: false}
{ isFullScreen: false, isResizeable: false, showFullScreen: false, isFullWidth: false, showTitle: false, id: 'id-quick-search'}
);
}
25 changes: 16 additions & 9 deletions web/pgadmin/static/js/helpers/ModalProvider.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function alert(title, text, onOkClick, okLabel = gettext('OK')) {
});
}

function confirm(title, text, onOkClick, onCancelClick, okLabel = gettext('Yes'), cancelLabel = gettext('No'), okIcon = 'default') {
function confirm(title, text, onOkClick, onCancelClick, okLabel = gettext('Yes'), cancelLabel = gettext('No'), okIcon = 'default', modalId=null) {
// bind the modal provider before calling
this.showModal(title, (closeModal) => {
const onCancelClickClose = () => {
Expand All @@ -98,7 +98,7 @@ function confirm(title, text, onOkClick, onCancelClick, okLabel = gettext('Yes')
return (
<AlertContent text={text} confirm onOkClick={onOkClickClose} onCancelClick={onCancelClickClose} okLabel={okLabel} cancelLabel={cancelLabel} okIcon={okIcon}/>
);
});
}, {modalId: modalId});
}

function confirmDelete(title, text, onDeleteClick, onCancelClick, deleteLabel = gettext('Delete'), cancelLabel = gettext('Cancel')) {
Expand Down Expand Up @@ -127,16 +127,23 @@ function confirmDelete(title, text, onDeleteClick, onCancelClick, deleteLabel =

export default function ModalProvider({ children }) {
const [modals, setModals] = React.useState([]);

const showModal = (title, content, modalOptions) => {
let id = getEpoch().toString() + crypto.getRandomValues(new Uint8Array(4));
setModals((prev) => [...prev, {
id: id,
title: title,
content: content,
...modalOptions,
}]);
if(modalOptions?.id){
id = modalOptions.id;
}
setModals((prev) => {
if(prev?.find(modal=> modal.id === modalOptions?.id)){
return prev;
}
return [...prev, {
id: id,
title: title,
content: content,
...modalOptions,
}];});
};

const closeModal = (id) => {
setModals((prev) => {
return prev.filter((o) => o.id != id);
Expand Down
4 changes: 2 additions & 2 deletions web/pgadmin/static/js/helpers/Notifier.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ class Notifier {
this.modal.alert(title, text, onOkClick, okLabel);
}

confirm(title, text, onOkClick, onCancelClick, okLabel=gettext('Yes'), cancelLabel=gettext('No'), okIcon='default') {
confirm(title, text, onOkClick, onCancelClick, okLabel=gettext('Yes'), cancelLabel=gettext('No'), okIcon='default', modalId=null) {
/* Use this if you want to use pgAdmin global notifier.
Or else, if you want to use modal inside iframe only then use ModalProvider eg- query tool */
this.modal.confirm(title, text, onOkClick, onCancelClick, okLabel, cancelLabel, okIcon);
this.modal.confirm(title, text, onOkClick, onCancelClick, okLabel, cancelLabel, okIcon, modalId);
}

confirmDelete(title, text, onDeleteClick, onCancelClick, okLabel = gettext('Delete'), cancelLabel = gettext('Cancel')){
Expand Down
3 changes: 1 addition & 2 deletions web/pgadmin/tools/debugger/static/js/debugger_ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import React from 'react';

import gettext from 'sources/gettext';
import pgAdmin from 'sources/pgadmin';

import DebuggerArgumentComponent from './components/DebuggerArgumentComponent';

export default class FunctionArguments {
Expand All @@ -28,6 +27,6 @@ export default class FunctionArguments {
// Render Debugger argument component
pgAdmin.Browser.notifier.showModal(gettext('Debugger'), (closeModal) => {
return <DebuggerArgumentComponent closeModal={closeModal} debuggerInfo={debugInfo} restartDebug={restartDebug} isEdbProc={isEdbProc} transId={transId} pgTreeInfo={treeInfo} pgData={d}></DebuggerArgumentComponent>;
}, { isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true, dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md });
}, { isFullScreen: false, isResizeable: true, showFullScreen: true, isFullWidth: true, dialogWidth: pgAdmin.Browser.stdW.md, dialogHeight: pgAdmin.Browser.stdH.md, id:'id-debugger'});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ export default class ERDTool extends React.Component {
bodyObj.onSaveDiagram(false, true);
}}
/>
));
), {id: 'id-erd-close-confirmation'});
return false;
} else {
this.forceClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ export const CONNECTION_STATUS_MESSAGE = {
[CONNECTION_STATUS.TRANSACTION_STATUS_UNKNOWN]: gettext('The connection with the server is bad.')
};

export const MODAL_DIALOGS = {
QT_CONFIRMATIONS: 'id-qt-close-confirmation',
};

export const PANELS = {
QUERY: 'id-query',
MESSAGES: 'id-messages',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import CustomPropTypes from '../../../../../../static/js/custom_prop_types';
import ConfirmTransactionContent from '../dialogs/ConfirmTransactionContent';
import { LayoutDocker } from '../../../../../../static/js/helpers/Layout';
import CloseRunningDialog from '../dialogs/CloseRunningDialog';
import { MODAL_DIALOGS } from '../QueryToolConstants';

const StyledBox = styled(Box)(({theme}) => ({
padding: '2px 4px',
Expand All @@ -56,6 +57,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
const eventBus = useContext(QueryToolEventsContext);
const queryToolCtx = useContext(QueryToolContext);
const queryToolConnCtx = useContext(QueryToolConnectionContext);
const modalId = MODAL_DIALOGS.QT_CONFIRMATIONS;

const [highlightFilter, setHighlightFilter] = useState(false);
const [limit, setLimit] = useState('-1');
Expand Down Expand Up @@ -237,7 +239,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
eventBus.fireEvent(QUERY_TOOL_EVENTS.FORCE_CLOSE_PANEL);
}}
/>
));
), {id: modalId});
return;
} else {
eventBus.fireEvent(QUERY_TOOL_EVENTS.FORCE_CLOSE_PANEL);
Expand All @@ -258,7 +260,7 @@ export function MainToolBar({containerRef, onFilterClick, onManageMacros, onAddT
onCommitClick();
}}
/>
));
), {id: modalId});
};
useEffect(()=>{
if(isInTxn()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import ConfirmExecuteQueryContent from '../dialogs/ConfirmExecuteQueryContent';
import usePreferences from '../../../../../../preferences/static/js/store';
import { getTitle } from '../../sqleditor_title';
import PropTypes from 'prop-types';
import { MODAL_DIALOGS } from '../QueryToolConstants';


async function registerAutocomplete(editor, api, transId) {
Expand Down Expand Up @@ -65,6 +66,7 @@ export default function Query({onTextSelect, setQtStatePartial}) {
const pgAdmin = usePgAdmin();
const preferencesStore = usePreferences();
const queryToolPref = queryToolCtx.preferences.sqleditor;
const modalId = MODAL_DIALOGS.QT_CONFIRMATIONS;
const highlightError = (cmObj, {errormsg: result, data}, executeCursor)=>{
let errorLineNo = 0,
startMarker = 0,
Expand Down Expand Up @@ -343,7 +345,7 @@ export default function Query({onTextSelect, setQtStatePartial}) {
eventBus.fireEvent(QUERY_TOOL_EVENTS.TRIGGER_SAVE_FILE);
}}
/>
));
), {id:modalId});
};

const formatSQL = ()=>{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { GraphVisualiser } from './GraphVisualiser';
import { usePgAdmin } from '../../../../../../static/js/PgAdminProvider';
import pgAdmin from 'sources/pgadmin';
import ConnectServerContent from '../../../../../../static/js/Dialogs/ConnectServerContent';
import { MODAL_DIALOGS } from '../QueryToolConstants';

const StyledBox = styled(Box)(({theme}) => ({
display: 'flex',
Expand Down Expand Up @@ -832,6 +833,7 @@ export function ResultSet() {
const [selectedColumns, setSelectedColumns] = useState(new Set());
// NONE - no select, PAGE - show select all, ALL - select all.
const [allRowsSelect, setAllRowsSelect] = useState('NONE');
const modalId = MODAL_DIALOGS.QT_CONFIRMATIONS;

// We'll use this track if any changes were saved.
// It will help to decide whether results refresh is required or not on page change.
Expand Down Expand Up @@ -1145,7 +1147,7 @@ export function ResultSet() {
eventBus.fireEvent(QUERY_TOOL_EVENTS.WARN_SAVE_TEXT_CLOSE);
}}
/>
));
), {modalId:modalId});
};
useEffect(()=>{
let isDirty = _.size(dataChangeStore.updated) || _.size(dataChangeStore.added) || _.size(dataChangeStore.deleted);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -457,12 +457,11 @@ UserManagementDialog.propTypes = {

export function showUserManagement() {
const title = gettext('User Management');

pgAdmin.Browser.notifier.showModal(title, (onClose) => {
return <UserManagementDialog
onClose={()=>{onClose();}}
/>;
},
{ isFullScreen: false, isResizeable: true, showFullScreen: false, isFullWidth: true,
dialogWidth: pgAdmin.Browser.stdW.lg, dialogHeight: pgAdmin.Browser.stdH.md});
dialogWidth: pgAdmin.Browser.stdW.lg, dialogHeight: pgAdmin.Browser.stdH.md, id: 'id-user-management'});
}