Update the server list on welcome page when workspace is changed to get the latest server connection info. #7708
parent
74e776ba21
commit
168aaa227a
|
@ -15,6 +15,7 @@ function parseConsoleArgs(args) {
|
||||||
return retData?.join(' ');
|
return retData?.join(' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(window.electronUI) {
|
||||||
for (const method of ['log', 'error']) {
|
for (const method of ['log', 'error']) {
|
||||||
const nativeMethod = window.console[method];
|
const nativeMethod = window.console[method];
|
||||||
window.console[method] = function () {
|
window.console[method] = function () {
|
||||||
|
@ -26,6 +27,7 @@ for (const method of ['log', 'error']) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
require(
|
require(
|
||||||
['sources/generated/app.bundle', 'sources/generated/browser_nodes'],
|
['sources/generated/app.bundle', 'sources/generated/browser_nodes'],
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
//
|
//
|
||||||
//////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
import React, { useMemo, useState } from 'react';
|
import React, { useEffect, useMemo, useState } from 'react';
|
||||||
import gettext from 'sources/gettext';
|
import gettext from 'sources/gettext';
|
||||||
import url_for from 'sources/url_for';
|
import url_for from 'sources/url_for';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
@ -27,8 +27,10 @@ import * as commonUtils from 'sources/utils';
|
||||||
import * as showQueryTool from '../../../../tools/sqleditor/static/js/show_query_tool';
|
import * as showQueryTool from '../../../../tools/sqleditor/static/js/show_query_tool';
|
||||||
import { getTitle, generateTitle } from '../../../../tools/sqleditor/static/js/sqleditor_title';
|
import { getTitle, generateTitle } from '../../../../tools/sqleditor/static/js/sqleditor_title';
|
||||||
import usePreferences from '../../../../preferences/static/js/store';
|
import usePreferences from '../../../../preferences/static/js/store';
|
||||||
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
|
import { BROWSER_PANELS, WORKSPACES } from '../../../../browser/static/js/constants';
|
||||||
import { isEmptyString } from '../../../../static/js/validators';
|
import { isEmptyString } from '../../../../static/js/validators';
|
||||||
|
import { getRandomInt } from '../../../../static/js/utils';
|
||||||
|
import { useWorkspace } from './WorkspaceProvider';
|
||||||
|
|
||||||
class AdHocConnectionSchema extends BaseUISchema {
|
class AdHocConnectionSchema extends BaseUISchema {
|
||||||
constructor(connectExistingServer, initValues={}) {
|
constructor(connectExistingServer, initValues={}) {
|
||||||
|
@ -49,6 +51,7 @@ class AdHocConnectionSchema extends BaseUISchema {
|
||||||
{'name': 'sslmode', 'value': 'prefer', 'keyword': 'sslmode'},
|
{'name': 'sslmode', 'value': 'prefer', 'keyword': 'sslmode'},
|
||||||
{'name': 'connect_timeout', 'value': 10, 'keyword': 'connect_timeout'}],
|
{'name': 'connect_timeout', 'value': 10, 'keyword': 'connect_timeout'}],
|
||||||
...initValues,
|
...initValues,
|
||||||
|
connection_refresh: 0,
|
||||||
});
|
});
|
||||||
this.flatServers = [];
|
this.flatServers = [];
|
||||||
this.groupedServers = [];
|
this.groupedServers = [];
|
||||||
|
@ -58,6 +61,12 @@ class AdHocConnectionSchema extends BaseUISchema {
|
||||||
this.paramSchema = new VariableSchema(getConnectionParameters, null, null, ['name', 'keyword', 'value']);
|
this.paramSchema = new VariableSchema(getConnectionParameters, null, null, ['name', 'keyword', 'value']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
refreshServerList() {
|
||||||
|
// its better to refresh the server list than monkey patching server connected status.
|
||||||
|
this.groupedServers = [];
|
||||||
|
this.state.setUnpreparedData(['connection_refresh'], getRandomInt(1, 9999));
|
||||||
|
}
|
||||||
|
|
||||||
setServerConnected(sid, icon) {
|
setServerConnected(sid, icon) {
|
||||||
for(const group of this.groupedServers) {
|
for(const group of this.groupedServers) {
|
||||||
for(const opt of group.options) {
|
for(const opt of group.options) {
|
||||||
|
@ -132,12 +141,12 @@ class AdHocConnectionSchema extends BaseUISchema {
|
||||||
let self = this;
|
let self = this;
|
||||||
return [
|
return [
|
||||||
{
|
{
|
||||||
id: 'sid', label: gettext('Existing Server (Optional)'), deps: ['connected'],
|
id: 'sid', label: gettext('Existing Server (Optional)'), deps: ['connected', 'connection_refresh'],
|
||||||
type: () => ({
|
type: (state) => ({
|
||||||
type: 'select',
|
type: 'select',
|
||||||
options: () => self.getServerList(),
|
options: () => self.getServerList(),
|
||||||
optionsLoaded: (res) => self.flatServers = flattenSelectOptions(res),
|
optionsLoaded: (res) => self.flatServers = flattenSelectOptions(res),
|
||||||
optionsReloadBasis: self.flatServers.map((s) => s.connected).join(''),
|
optionsReloadBasis: `${self.flatServers.map((s) => s.connected).join('')}${state.connection_refresh}`,
|
||||||
}),
|
}),
|
||||||
depChange: (state)=>{
|
depChange: (state)=>{
|
||||||
/* Once the option is selected get the name */
|
/* Once the option is selected get the name */
|
||||||
|
@ -160,6 +169,7 @@ class AdHocConnectionSchema extends BaseUISchema {
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
deferredDepChange: (state, source, topState, actionObj) => {
|
deferredDepChange: (state, source, topState, actionObj) => {
|
||||||
|
if(source.includes('connection_refresh')) return;
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
let sid = actionObj.value;
|
let sid = actionObj.value;
|
||||||
let selectedServer = _.find(self.flatServers, (s)=>s.value==sid);
|
let selectedServer = _.find(self.flatServers, (s)=>s.value==sid);
|
||||||
|
@ -323,6 +333,7 @@ export default function AdHocConnection({mode}) {
|
||||||
const modal = useModal();
|
const modal = useModal();
|
||||||
const pgAdmin = usePgAdmin();
|
const pgAdmin = usePgAdmin();
|
||||||
const preferencesStore = usePreferences();
|
const preferencesStore = usePreferences();
|
||||||
|
const {currentWorkspace} = useWorkspace();
|
||||||
|
|
||||||
const connectExistingServer = async (sid, user, formData, connectCallback) => {
|
const connectExistingServer = async (sid, user, formData, connectCallback) => {
|
||||||
setConnecting(true);
|
setConnecting(true);
|
||||||
|
@ -447,9 +458,9 @@ export default function AdHocConnection({mode}) {
|
||||||
data: JSON.stringify(formData)
|
data: JSON.stringify(formData)
|
||||||
});
|
});
|
||||||
setConnecting(false);
|
setConnecting(false);
|
||||||
if (mode == 'Query Tool') {
|
if (mode == WORKSPACES.QUERY_TOOL) {
|
||||||
openQueryTool(respData, formData);
|
openQueryTool(respData, formData);
|
||||||
} else if (mode == 'PSQL') {
|
} else if (mode == WORKSPACES.PSQL_TOOL) {
|
||||||
openPSQLTool(respData, formData);
|
openPSQLTool(respData, formData);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -478,12 +489,16 @@ export default function AdHocConnection({mode}) {
|
||||||
};
|
};
|
||||||
|
|
||||||
let saveBtnName = gettext('Connect & Open Query Tool');
|
let saveBtnName = gettext('Connect & Open Query Tool');
|
||||||
if (mode == 'PSQL') {
|
if (mode == WORKSPACES.PSQL_TOOL) {
|
||||||
saveBtnName = gettext('Connect & Open PSQL');
|
saveBtnName = gettext('Connect & Open PSQL');
|
||||||
}
|
}
|
||||||
|
|
||||||
let adHocConObj = useMemo(() => new AdHocConnectionSchema(connectExistingServer), []);
|
let adHocConObj = useMemo(() => new AdHocConnectionSchema(connectExistingServer), []);
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
if(currentWorkspace == mode) adHocConObj.refreshServerList();
|
||||||
|
}, [currentWorkspace]);
|
||||||
|
|
||||||
return <SchemaView
|
return <SchemaView
|
||||||
formType={'dialog'}
|
formType={'dialog'}
|
||||||
getInitData={() => { /*This is intentional (SonarQube)*/ }}
|
getInitData={() => { /*This is intentional (SonarQube)*/ }}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import WelcomeBG from '../img/welcome_background.svg?svgr';
|
||||||
import { QueryToolIcon } from '../../../../static/js/components/ExternalIcon';
|
import { QueryToolIcon } from '../../../../static/js/components/ExternalIcon';
|
||||||
import TerminalRoundedIcon from '@mui/icons-material/TerminalRounded';
|
import TerminalRoundedIcon from '@mui/icons-material/TerminalRounded';
|
||||||
import { renderToStaticMarkup } from 'react-dom/server';
|
import { renderToStaticMarkup } from 'react-dom/server';
|
||||||
|
import { WORKSPACES } from '../../../../browser/static/js/constants';
|
||||||
|
|
||||||
const welcomeBackgroundString = encodeURIComponent(renderToStaticMarkup(<WelcomeBG />));
|
const welcomeBackgroundString = encodeURIComponent(renderToStaticMarkup(<WelcomeBG />));
|
||||||
const welcomeBackgroundURI = `url("data:image/svg+xml,${welcomeBackgroundString}")`;
|
const welcomeBackgroundURI = `url("data:image/svg+xml,${welcomeBackgroundString}")`;
|
||||||
|
@ -91,7 +92,7 @@ export default function WorkspaceWelcomePage({ mode }) {
|
||||||
let welcomeFirst = gettext('The Query Tool is a robust and versatile environment designed for executing SQL commands and reviewing result sets efficiently.');
|
let welcomeFirst = gettext('The Query Tool is a robust and versatile environment designed for executing SQL commands and reviewing result sets efficiently.');
|
||||||
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.');
|
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.');
|
||||||
|
|
||||||
if (mode == 'PSQL') {
|
if (mode == WORKSPACES.PSQL_TOOL) {
|
||||||
welcomeIcon = <TerminalRoundedIcon style={{height: '2rem', width: 'unset'}} />;
|
welcomeIcon = <TerminalRoundedIcon style={{height: '2rem', width: 'unset'}} />;
|
||||||
welcomeTitle = gettext('Welcome to the PSQL Workspace!');
|
welcomeTitle = gettext('Welcome to the PSQL Workspace!');
|
||||||
welcomeFirst = gettext('The PSQL tool allows users to connect to PostgreSQL or EDB Advanced server using the psql command line interface.');
|
welcomeFirst = gettext('The PSQL tool allows users to connect to PostgreSQL or EDB Advanced server using the psql command line interface.');
|
||||||
|
|
|
@ -13,11 +13,11 @@ import WorkspaceWelcomePage from './WorkspaceWelcomePage';
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
const welcomeQueryToolPanelData = {
|
const welcomeQueryToolPanelData = {
|
||||||
id: BROWSER_PANELS.WELCOME_QUERY_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={'Query Tool'} />, closable: false, group: 'playground'
|
id: BROWSER_PANELS.WELCOME_QUERY_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={WORKSPACES.QUERY_TOOL} />, closable: false, group: 'playground'
|
||||||
};
|
};
|
||||||
|
|
||||||
const welcomePSQLPanelData = {
|
const welcomePSQLPanelData = {
|
||||||
id: BROWSER_PANELS.WELCOME_PSQL_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={'PSQL'} />, closable: false, group: 'playground'
|
id: BROWSER_PANELS.WELCOME_PSQL_TOOL, title: gettext('Welcome'), content: <WorkspaceWelcomePage mode={WORKSPACES.PSQL_TOOL} />, closable: false, group: 'playground'
|
||||||
};
|
};
|
||||||
|
|
||||||
export const config = [
|
export const config = [
|
||||||
|
|
|
@ -189,7 +189,7 @@ export default class Psql {
|
||||||
<PgAdminProvider value={pgAdmin}>
|
<PgAdminProvider value={pgAdmin}>
|
||||||
<ModalProvider>
|
<ModalProvider>
|
||||||
<NotifierProvider pgAdmin={pgAdmin} pgWindow={pgWindow} />
|
<NotifierProvider pgAdmin={pgAdmin} pgWindow={pgWindow} />
|
||||||
<PsqlComponent params={JSON.parse(params)} pgAdmin={pgAdmin} />
|
<PsqlComponent params={params} pgAdmin={pgAdmin} />
|
||||||
</ModalProvider>
|
</ModalProvider>
|
||||||
</PgAdminProvider>
|
</PgAdminProvider>
|
||||||
</Theme>
|
</Theme>
|
||||||
|
|
Loading…
Reference in New Issue