Skip to content

Commit 9ffb984

Browse files
Update the server list on ad-hoc connection page when workpace is changed to get the latest server connection info. #7708
1 parent cd86ce0 commit 9ffb984

File tree

5 files changed

+39
-21
lines changed

5 files changed

+39
-21
lines changed

web/pgadmin/browser/templates/browser/index.html

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,17 @@
1515
return retData?.join(' ');
1616
}
1717

18-
for (const method of ['log', 'error']) {
19-
const nativeMethod = window.console[method];
20-
window.console[method] = function () {
21-
nativeMethod.apply(this, arguments);
22-
setTimeout(()=>{
23-
window.electronUI?.log(`--------------[UI ${method}]---------------
24-
${parseConsoleArgs(arguments)}
25-
------------[UI End]----------------`);
26-
});
18+
if(window.electronUI) {
19+
for (const method of ['log', 'error']) {
20+
const nativeMethod = window.console[method];
21+
window.console[method] = function () {
22+
nativeMethod.apply(this, arguments);
23+
setTimeout(()=>{
24+
window.electronUI?.log(`--------------[UI ${method}]---------------
25+
${parseConsoleArgs(arguments)}
26+
------------[UI End]----------------`);
27+
});
28+
}
2729
}
2830
}
2931
try {

web/pgadmin/misc/workspaces/static/js/AdHocConnection.jsx

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//
88
//////////////////////////////////////////////////////////////
99

10-
import React, { useMemo, useState } from 'react';
10+
import React, { useEffect, useMemo, useState } from 'react';
1111
import gettext from 'sources/gettext';
1212
import url_for from 'sources/url_for';
1313
import _ from 'lodash';
@@ -27,8 +27,10 @@ import * as commonUtils from 'sources/utils';
2727
import * as showQueryTool from '../../../../tools/sqleditor/static/js/show_query_tool';
2828
import { getTitle, generateTitle } from '../../../../tools/sqleditor/static/js/sqleditor_title';
2929
import usePreferences from '../../../../preferences/static/js/store';
30-
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
30+
import { BROWSER_PANELS, WORKSPACES } from '../../../../browser/static/js/constants';
3131
import { isEmptyString } from '../../../../static/js/validators';
32+
import { getRandomInt } from '../../../../static/js/utils';
33+
import { useWorkspace } from './WorkspaceProvider';
3234

3335
class AdHocConnectionSchema extends BaseUISchema {
3436
constructor(connectExistingServer, initValues={}) {
@@ -49,6 +51,7 @@ class AdHocConnectionSchema extends BaseUISchema {
4951
{'name': 'sslmode', 'value': 'prefer', 'keyword': 'sslmode'},
5052
{'name': 'connect_timeout', 'value': 10, 'keyword': 'connect_timeout'}],
5153
...initValues,
54+
connection_refresh: 0,
5255
});
5356
this.flatServers = [];
5457
this.groupedServers = [];
@@ -58,6 +61,12 @@ class AdHocConnectionSchema extends BaseUISchema {
5861
this.paramSchema = new VariableSchema(getConnectionParameters, null, null, ['name', 'keyword', 'value']);
5962
}
6063

64+
refreshServerList() {
65+
// its better to refresh the server list than monkey patching server connected status.
66+
this.groupedServers = [];
67+
this.state.setUnpreparedData(['connection_refresh'], getRandomInt(1, 9999));
68+
}
69+
6170
setServerConnected(sid, icon) {
6271
for(const group of this.groupedServers) {
6372
for(const opt of group.options) {
@@ -132,12 +141,12 @@ class AdHocConnectionSchema extends BaseUISchema {
132141
let self = this;
133142
return [
134143
{
135-
id: 'sid', label: gettext('Existing Server (Optional)'), deps: ['connected'],
136-
type: () => ({
144+
id: 'sid', label: gettext('Existing Server (Optional)'), deps: ['connected', 'connection_refresh'],
145+
type: (state) => ({
137146
type: 'select',
138147
options: () => self.getServerList(),
139148
optionsLoaded: (res) => self.flatServers = flattenSelectOptions(res),
140-
optionsReloadBasis: self.flatServers.map((s) => s.connected).join(''),
149+
optionsReloadBasis: `${self.flatServers.map((s) => s.connected).join('')}${state.connection_refresh}`,
141150
}),
142151
depChange: (state)=>{
143152
/* Once the option is selected get the name */
@@ -160,6 +169,7 @@ class AdHocConnectionSchema extends BaseUISchema {
160169
};
161170
},
162171
deferredDepChange: (state, source, topState, actionObj) => {
172+
if(source.includes('connection_refresh')) return;
163173
return new Promise((resolve) => {
164174
let sid = actionObj.value;
165175
let selectedServer = _.find(self.flatServers, (s)=>s.value==sid);
@@ -323,6 +333,7 @@ export default function AdHocConnection({mode}) {
323333
const modal = useModal();
324334
const pgAdmin = usePgAdmin();
325335
const preferencesStore = usePreferences();
336+
const {currentWorkspace} = useWorkspace();
326337

327338
const connectExistingServer = async (sid, user, formData, connectCallback) => {
328339
setConnecting(true);
@@ -447,9 +458,9 @@ export default function AdHocConnection({mode}) {
447458
data: JSON.stringify(formData)
448459
});
449460
setConnecting(false);
450-
if (mode == 'Query Tool') {
461+
if (mode == WORKSPACES.QUERY_TOOL) {
451462
openQueryTool(respData, formData);
452-
} else if (mode == 'PSQL') {
463+
} else if (mode == WORKSPACES.PSQL_TOOL) {
453464
openPSQLTool(respData, formData);
454465
}
455466
} catch (error) {
@@ -478,12 +489,16 @@ export default function AdHocConnection({mode}) {
478489
};
479490

480491
let saveBtnName = gettext('Connect & Open Query Tool');
481-
if (mode == 'PSQL') {
492+
if (mode == WORKSPACES.PSQL_TOOL) {
482493
saveBtnName = gettext('Connect & Open PSQL');
483494
}
484495

485496
let adHocConObj = useMemo(() => new AdHocConnectionSchema(connectExistingServer), []);
486497

498+
useEffect(()=>{
499+
if(currentWorkspace == mode) adHocConObj.refreshServerList();
500+
}, [currentWorkspace]);
501+
487502
return <SchemaView
488503
formType={'dialog'}
489504
getInitData={() => { /*This is intentional (SonarQube)*/ }}

web/pgadmin/misc/workspaces/static/js/WorkspaceWelcomePage.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import WelcomeBG from '../img/welcome_background.svg?svgr';
1717
import { QueryToolIcon } from '../../../../static/js/components/ExternalIcon';
1818
import TerminalRoundedIcon from '@mui/icons-material/TerminalRounded';
1919
import { renderToStaticMarkup } from 'react-dom/server';
20+
import { WORKSPACES } from '../../../../browser/static/js/constants';
2021

2122
const welcomeBackgroundString = encodeURIComponent(renderToStaticMarkup(<WelcomeBG />));
2223
const welcomeBackgroundURI = `url("data:image/svg+xml,${welcomeBackgroundString}")`;
@@ -91,7 +92,7 @@ export default function WorkspaceWelcomePage({ mode }) {
9192
let welcomeFirst = gettext('The Query Tool is a robust and versatile environment designed for executing SQL commands and reviewing result sets efficiently.');
9293
let welcomeSecond = gettext('In this workspace, you can seamlessly open and manage multiple query tabs, making it easier to organize your work. You can select the existing servers or create a completely new ad-hoc connection to any database server as needed.');
9394

94-
if (mode == 'PSQL') {
95+
if (mode == WORKSPACES.PSQL_TOOL) {
9596
welcomeIcon = <TerminalRoundedIcon style={{height: '2rem', width: 'unset'}} />;
9697
welcomeTitle = gettext('Welcome to the PSQL Workspace!');
9798
welcomeFirst = gettext('The PSQL tool allows users to connect to PostgreSQL or EDB Advanced server using the psql command line interface.');

web/pgadmin/misc/workspaces/static/js/config.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ import WorkspaceWelcomePage from './WorkspaceWelcomePage';
1313
import React from 'react';
1414

1515
const welcomeQueryToolPanelData = {
16-
id: BROWSER_PANELS.WELCOME_QUERY_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={'Query Tool'} />, closable: false, group: 'playground'
16+
id: BROWSER_PANELS.WELCOME_QUERY_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={WORKSPACES.QUERY_TOOL} />, closable: false, group: 'playground'
1717
};
1818

1919
const welcomePSQLPanelData = {
20-
id: BROWSER_PANELS.WELCOME_PSQL_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={'PSQL'} />, closable: false, group: 'playground'
20+
id: BROWSER_PANELS.WELCOME_PSQL_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={WORKSPACES.PSQL_TOOL} />, closable: false, group: 'playground'
2121
};
2222

2323
export const config = [

web/pgadmin/tools/psql/static/js/PsqlModule.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export default class Psql {
189189
<PgAdminProvider value={pgAdmin}>
190190
<ModalProvider>
191191
<NotifierProvider pgAdmin={pgAdmin} pgWindow={pgWindow} />
192-
<PsqlComponent params={JSON.parse(params)} pgAdmin={pgAdmin} />
192+
<PsqlComponent params={params} pgAdmin={pgAdmin} />
193193
</ModalProvider>
194194
</PgAdminProvider>
195195
</Theme>

0 commit comments

Comments
 (0)