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.
This commit is contained in:
t8y2 2026-05-24 19:11:06 +08:00
parent e83c335a70
commit 7b9a04ff3e
4 changed files with 8 additions and 6 deletions

View File

@ -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) {

View File

@ -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);

View File

@ -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 {

View File

@ -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<QueryTab, "connectionId" | "database">;
selectedTreeNode?: Pick<TreeNode, "connectionId" | "database"> | null;
activeTab?: Pick<QueryTab, "connectionId" | "database" | "schema">;
selectedTreeNode?: Pick<TreeNode, "connectionId" | "database" | "schema"> | null;
activeConnectionId?: string | null;
connections: Pick<ConnectionConfig, "id" | "database">[];
preferredSource?: NewQueryContextSource;
@ -49,7 +50,7 @@ export function resolveNewQueryTarget(input: ResolveNewQueryTargetInput): NewQue
}
function targetFromContext(
context: Pick<QueryTab | TreeNode, "connectionId" | "database"> | undefined,
context: Pick<QueryTab | TreeNode, "connectionId" | "database" | "schema"> | undefined,
connections: Pick<ConnectionConfig, "id" | "database">[],
): 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,
};
}