Skip to content

Commit eb7c3ef

Browse files
committed
Workspace Layout Update - Enhanced Query Tool and PSQL Behaviour:
With these changes, the Query Tool and PSQL tabs will now open in the same active workspace where the action is initiated.
1 parent 2c37ff2 commit eb7c3ef

File tree

7 files changed

+61
-7
lines changed

7 files changed

+61
-7
lines changed
70.9 KB
Loading

Diff for: docs/en_US/preferences.rst

+5
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,11 @@ Expand the *Miscellaneous* node to specify miscellaneous display preferences.
286286
areas for the Query Tool, PSQL, and Schema Diff tools. 'Workspace' layout is
287287
the default layout, but user can change it to 'Classic'.
288288

289+
* When the *Open the Query Tool/PSQL in their respective workspaces* switch is set to *True*
290+
then all Query Tool/PSQL tabs will open in their respective workspaces. By default,
291+
this setting is False, meaning that Query Tool/PSQL tabs will open in the currently
292+
active workspace (either the default or the workspace selected at the time of opening).
293+
289294
* Use the *Themes* drop-down listbox to select the theme for pgAdmin. You'll also get a preview just below the
290295
drop down. You can also submit your own themes,
291296
check `here <https://github.com/pgadmin-org/pgadmin4/blob/master/README.md>`_ how.

Diff for: web/pgadmin/misc/__init__.py

+14
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ def register_preferences(self):
105105
'Diff tools.'
106106
)
107107
)
108+
self.preference.register(
109+
'user_interface', 'open_in_res_workspace',
110+
gettext("Open the Query Tool/PSQL in their respective workspaces"),
111+
'boolean', False,
112+
category_label=PREF_LABEL_USER_INTERFACE,
113+
help_str=gettext(
114+
'This setting applies only when the layout is set to '
115+
'Workspace Layout. When set to True, all Query Tool/PSQL '
116+
'tabs will open in their respective workspaces. By default, '
117+
'this setting is False, meaning that Query Tool/PSQL tabs '
118+
'will open in the currently active workspace (either the '
119+
'default or the workspace selected at the time of opening)'
120+
)
121+
)
108122

109123
def get_exposed_url_endpoints(self):
110124
"""

Diff for: web/pgadmin/misc/workspaces/static/js/WorkspaceProvider.jsx

+13-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
import React, { useContext, useMemo, useRef, useState } from 'react';
1111
import PropTypes from 'prop-types';
12-
import { WORKSPACES } from '../../../../browser/static/js/constants';
12+
import { BROWSER_PANELS, WORKSPACES } from '../../../../browser/static/js/constants';
1313
import { usePgAdmin } from '../../../../static/js/PgAdminProvider';
1414
import usePreferences from '../../../../preferences/static/js/store';
1515
import { config } from './config';
@@ -23,8 +23,11 @@ export function WorkspaceProvider({children}) {
2323
const [currentWorkspace, setCurrentWorkspace] = useState(WORKSPACES.DEFAULT);
2424
const lastSelectedTreeItem = useRef();
2525
const isClassic = (usePreferences()?.getPreferencesForModule('misc')?.layout ?? 'classic') == 'classic';
26+
const openInResWorkspace = usePreferences()?.getPreferencesForModule('misc')?.open_in_res_workspace && !isClassic;
2627

27-
pgAdmin.Browser.docker.currentWorkspace = WORKSPACES.DEFAULT;
28+
if (_.isUndefined(pgAdmin.Browser.docker.currentWorkspace)) {
29+
pgAdmin.Browser.docker.currentWorkspace = WORKSPACES.DEFAULT;
30+
}
2831
/* In case of classic UI all workspace objects should point to the
2932
* the instance of the default layout.
3033
*/
@@ -50,6 +53,14 @@ export function WorkspaceProvider({children}) {
5053
workspace = WORKSPACES.DEFAULT;
5154
}
5255

56+
// If the layout is Workspace layout and 'Open the Query Tool/PSQL in their respective workspaces'
57+
// is False then check the current workspace and set the workspace and docker accordingly.
58+
if (!openInResWorkspace && pgAdmin.Browser.docker.currentWorkspace == WORKSPACES.DEFAULT &&
59+
(panelId.indexOf(BROWSER_PANELS.QUERY_TOOL) >= 0 || panelId.indexOf(BROWSER_PANELS.PSQL_TOOL) >= 0)) {
60+
docker = pgAdmin.Browser.docker.default_workspace;
61+
workspace = WORKSPACES.DEFAULT;
62+
}
63+
5364
// Call onWorkspaceChange to enable or disable the menu based on the selected workspace.
5465
changeWorkspace(workspace);
5566
return {docker: docker, focus: ()=>changeWorkspace(workspace)};

Diff for: web/pgadmin/preferences/static/js/components/PreferencesComponent.jsx

+19
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,8 @@ export default function PreferencesComponent({ ...props }) {
299299
preferencesValues[element.id] = { 'warning': _val[0], 'alert': _val[1] };
300300
} else if (subNode.label == gettext('Results grid') && node.label == gettext('Query Tool')) {
301301
setResultsOptions(element, subNode, preferencesValues, type);
302+
} else if (subNode.label == gettext('User Interface') && node.label == gettext('Miscellaneous')) {
303+
setWorkspaceOptions(element, subNode, preferencesValues, type);
302304
} else {
303305
element.type = type;
304306
preferencesValues[element.id] = element.value;
@@ -329,6 +331,23 @@ export default function PreferencesComponent({ ...props }) {
329331
preferencesValues[element.id] = element.value;
330332
}
331333

334+
function setWorkspaceOptions(element, subNode, preferencesValues, type) {
335+
if (element.name== 'open_in_res_workspace') {
336+
let layout_control_id = null;
337+
subNode.preferences.forEach((_el) => {
338+
if(_el.name == 'layout') {
339+
layout_control_id = _el.id;
340+
}
341+
342+
});
343+
element.disabled = (state) => {
344+
return state[layout_control_id] != 'workspace';
345+
};
346+
}
347+
element.type = type;
348+
preferencesValues[element.id] = element.value;
349+
}
350+
332351
function setThemesOptions(element) {
333352
if (element.name == 'theme') {
334353
element.type = 'theme';

Diff for: web/pgadmin/static/js/BrowserComponent.jsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,16 @@ let defaultLayout = {
8080
mode: 'horizontal',
8181
children: [
8282
{
83-
size: 20,
83+
size: 10,
8484
tabs: [
8585
LayoutDocker.getPanel({
86-
id: BROWSER_PANELS.OBJECT_EXPLORER, title: gettext('Object Explorer'),
86+
id: BROWSER_PANELS.OBJECT_EXPLORER, title: gettext(''),
8787
content: <ObjectExplorer />, group: 'object-explorer'
8888
}),
8989
],
9090
},
9191
{
92-
size: 80,
92+
size: 90,
9393
id: BROWSER_PANELS.MAIN,
9494
group: 'playground',
9595
tabs: defaultTabsData.map((t)=>LayoutDocker.getPanel(t)),

Diff for: web/pgadmin/tools/sqleditor/static/js/SQLEditorModule.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import ReactDOM from 'react-dom/client';
2323
import QueryToolComponent from './components/QueryToolComponent';
2424
import ModalProvider from '../../../../static/js/helpers/ModalProvider';
2525
import Theme from '../../../../static/js/Theme';
26-
import { BROWSER_PANELS } from '../../../../browser/static/js/constants';
26+
import { BROWSER_PANELS, WORKSPACES } from '../../../../browser/static/js/constants';
2727
import { NotifierProvider } from '../../../../static/js/helpers/Notifier';
2828
import usePreferences, { listenPreferenceBroadcast } from '../../../../preferences/static/js/store';
2929
import { PgAdminProvider } from '../../../../static/js/PgAdminProvider';
@@ -229,6 +229,11 @@ export default class SQLEditor {
229229
}
230230

231231
async loadComponent(container, params) {
232+
let panelDocker = pgWindow.pgAdmin.Browser.docker.query_tool_workspace;
233+
if (pgWindow.pgAdmin.Browser.docker.currentWorkspace == WORKSPACES.DEFAULT) {
234+
panelDocker = pgWindow.pgAdmin.Browser.docker.default_workspace;
235+
}
236+
232237
const selectedNodeInfo = params.selectedNodeInfo ? JSON.parse(_.unescape(params.selectedNodeInfo)) : params.selectedNodeInfo;
233238
pgAdmin.Browser.keyboardNavigation.init();
234239
await listenPreferenceBroadcast();
@@ -238,7 +243,7 @@ export default class SQLEditor {
238243
<PgAdminProvider value={pgAdmin}>
239244
<ModalProvider>
240245
<NotifierProvider pgAdmin={pgAdmin} pgWindow={pgWindow} />
241-
<QueryToolComponent params={params} pgWindow={pgWindow} pgAdmin={pgAdmin} qtPanelDocker={pgWindow.pgAdmin.Browser.docker.query_tool_workspace}
246+
<QueryToolComponent params={params} pgWindow={pgWindow} pgAdmin={pgAdmin} qtPanelDocker={panelDocker}
242247
qtPanelId={`${BROWSER_PANELS.QUERY_TOOL}_${params.trans_id}`} selectedNodeInfo={selectedNodeInfo}/>
243248
</ModalProvider>
244249
</PgAdminProvider>

0 commit comments

Comments
 (0)