From 7b9a04ff3e181f92b64201acb83cf85342ade02f Mon Sep 17 00:00:00 2001 From: t8y2 <1156263951@qq.com> Date: Sun, 24 May 2026 19:11:06 +0800 Subject: [PATCH] fix(ui): propagate schema when creating tabs and new queries Table/data tabs were missing schema in createTab, so the toolbar "new query" button couldn't inherit schema from the active tab. Also add schema to NewQueryTarget so resolveNewQueryTarget propagates it from both sidebar and active tab contexts. --- apps/desktop/src/App.vue | 2 +- apps/desktop/src/components/sidebar/TreeItem.vue | 2 +- apps/desktop/src/composables/useNavigationTargets.ts | 2 +- apps/desktop/src/lib/newQueryContext.ts | 8 +++++--- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue index fee10312b..50902f418 100644 --- a/apps/desktop/src/App.vue +++ b/apps/desktop/src/App.vue @@ -473,7 +473,7 @@ async function newQuery() { const conn = connectionStore.getConfig(target.connectionId); if (!conn) return; connectionStore.activeConnectionId = target.connectionId; - const tabId = queryStore.createTab(conn.id, target.database); + const tabId = queryStore.createTab(conn.id, target.database, undefined, "query", target.schema); try { await connectionStore.ensureConnected(target.connectionId); if (target.shouldRefreshDefaultDatabase) { diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vue index 529844333..0c9eda1fc 100644 --- a/apps/desktop/src/components/sidebar/TreeItem.vue +++ b/apps/desktop/src/components/sidebar/TreeItem.vue @@ -494,7 +494,7 @@ async function openData() { table: node.label, dbType: config?.db_type, }); - const tabId = queryStore.createTab(node.connectionId, node.database, node.label, "data"); + const tabId = queryStore.createTab(node.connectionId, node.database, node.label, "data", node.schema); console.info("[DBX][openData:tab-created]", { traceId, tabId, elapsed: elapsed() }); queryStore.setExecuting(tabId, true); diff --git a/apps/desktop/src/composables/useNavigationTargets.ts b/apps/desktop/src/composables/useNavigationTargets.ts index 423e9588c..4574789d3 100644 --- a/apps/desktop/src/composables/useNavigationTargets.ts +++ b/apps/desktop/src/composables/useNavigationTargets.ts @@ -23,7 +23,7 @@ async function openTableTarget(target: NavigationTarget) { connectionStore.activeConnectionId = target.connectionId; const config = connectionStore.getConfig(target.connectionId); const tabTitle = target.schema ? `${target.schema}.${target.tableName}` : target.tableName; - const tabId = queryStore.createTab(target.connectionId, target.database, tabTitle, "data"); + const tabId = queryStore.createTab(target.connectionId, target.database, tabTitle, "data", target.schema); queryStore.setExecuting(tabId, true); try { diff --git a/apps/desktop/src/lib/newQueryContext.ts b/apps/desktop/src/lib/newQueryContext.ts index fc7bf8722..4981f9aa5 100644 --- a/apps/desktop/src/lib/newQueryContext.ts +++ b/apps/desktop/src/lib/newQueryContext.ts @@ -4,14 +4,15 @@ import type { ConnectionConfig, QueryTab, TreeNode } from "@/types/database"; export interface NewQueryTarget { connectionId: string; database: string; + schema?: string; shouldRefreshDefaultDatabase: boolean; } export type NewQueryContextSource = "tab" | "sidebar"; interface ResolveNewQueryTargetInput { - activeTab?: Pick; - selectedTreeNode?: Pick | null; + activeTab?: Pick; + selectedTreeNode?: Pick | null; activeConnectionId?: string | null; connections: Pick[]; preferredSource?: NewQueryContextSource; @@ -49,7 +50,7 @@ export function resolveNewQueryTarget(input: ResolveNewQueryTargetInput): NewQue } function targetFromContext( - context: Pick | undefined, + context: Pick | undefined, connections: Pick[], ): NewQueryTarget | null { if (!context?.connectionId) return null; @@ -59,6 +60,7 @@ function targetFromContext( return { connectionId: context.connectionId, database, + schema: "schema" in context ? (context as { schema?: string }).schema : undefined, shouldRefreshDefaultDatabase: !context.database, }; }