Skip to content

Commit bf64942

Browse files
authored
Fix a couple of related issues in the Query Tool layout.
- Hide the AI Assistant tab if AI is disabled or unconfigured. #9696 - Ensure the AI Assistant tab is not the first one shown.
1 parent 1c93f93 commit bf64942

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

web/pgadmin/browser/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,9 @@ def utils():
494494
except Exception:
495495
pg_libpq_version = 0
496496

497+
# Check if LLM features are enabled (system-level AND provider configured)
498+
from pgadmin.llm.utils import is_llm_enabled
499+
497500
for submodule in current_blueprint.submodules:
498501
snippets.extend(submodule.jssnippets)
499502

@@ -538,7 +541,7 @@ def utils():
538541
"Administrator") else restricted_shared_storage_list,
539542
enable_server_passexec_cmd=config.ENABLE_SERVER_PASS_EXEC_CMD,
540543
max_server_tags_allowed=config.MAX_SERVER_TAGS_ALLOWED,
541-
llm_enabled=config.LLM_ENABLED,
544+
llm_enabled=is_llm_enabled(),
542545
), 200)
543546
response.headers['Content-Type'] = MIMETYPE_APP_JS
544547
response.headers['Cache-Control'] = NO_CACHE_CONTROL

web/pgadmin/static/js/helpers/Layout/index.jsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ export class LayoutDocker {
220220
}
221221

222222
loadLayout(savedLayout) {
223+
if (!savedLayout) {
224+
// No saved layout - DockLayout already initialized with defaultLayout
225+
return;
226+
}
223227
try {
224228
this.layoutObj.loadLayout(JSON.parse(savedLayout));
225229
this.addMissingDefaultPanels();
@@ -252,6 +256,22 @@ export class LayoutDocker {
252256
// Only add non-closable tabs (closable tabs may have been intentionally removed)
253257
const missingNonClosableTabs = missingTabs.filter(tab => !tab.internal?.closable);
254258

259+
if (missingNonClosableTabs.length === 0) return;
260+
261+
// Save the active tab IDs for each panel group before adding missing tabs,
262+
// so that newly added tabs don't steal focus from the user's current tab.
263+
const savedActiveIds = [];
264+
const collectActiveIds = (box) => {
265+
box.children.forEach((child) => {
266+
if (child.children) {
267+
collectActiveIds(child);
268+
} else if (child.activeId) {
269+
savedActiveIds.push(child.activeId);
270+
}
271+
});
272+
};
273+
collectActiveIds(this.layoutObj.getLayout().dockbox);
274+
255275
// Add each missing tab next to a sibling from its original panel group
256276
missingNonClosableTabs.forEach((tab) => {
257277
const siblingId = this.findSiblingTab(tab.id, flatDefault, flatCurrent);
@@ -270,6 +290,11 @@ export class LayoutDocker {
270290
}, this.resetToTabPanel, 'middle');
271291
}
272292
});
293+
294+
// Restore the original active tabs so newly added tabs don't steal focus
295+
savedActiveIds.forEach((activeId) => {
296+
this.focus(activeId);
297+
});
273298
}
274299

275300
findSiblingTab(tabId, flatDefault, flatCurrent) {

web/pgadmin/tools/sqleditor/static/js/components/QueryToolComponent.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,8 @@ export default function QueryToolComponent({params, pgWindow, pgAdmin, selectedN
232232
maximizable: true,
233233
tabs: [
234234
LayoutDocker.getPanel({id: PANELS.QUERY, title: gettext('Query'), content: <Query onTextSelect={(text) => setSelectedText(text)} setQtStatePartial={setQtStatePartial}/>}),
235-
LayoutDocker.getPanel({id: PANELS.HISTORY, title: gettext('Query History'), content: <QueryHistory />}),
236235
...(pgAdmin.llm_enabled ? [LayoutDocker.getPanel({id: PANELS.AI_ASSISTANT, title: gettext('AI Assistant'), content: <NLQChatPanel />})] : []),
236+
LayoutDocker.getPanel({id: PANELS.HISTORY, title: gettext('Query History'), content: <QueryHistory />}),
237237
],
238238
},
239239
{

0 commit comments

Comments
 (0)