Skip to content

armgit / dbx

Public Imported from GitHub
0

25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。

fix(ui): restore query tab activation

t8y2701f188e4594
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 6227061579..9242dd6d7d 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -545,6 +545,11 @@ function activateSettingsPage() {
driverStoreActive.value = false;
}
+function activateQuerySurface() {
+ driverStoreActive.value = false;
+ settingsStore.settingsPageActive = false;
+}
+
function closeSettingsPage() {
settingsPageTabOpen.value = false;
settingsStore.settingsPageActive = false;
@@ -750,8 +755,7 @@ watch(
pendingTabHistoryNavigationId = null;
}
if (id) newQueryContextSource.value = "tab";
- if (id && driverStoreActive.value) driverStoreActive.value = false;
- if (id && settingsStore.settingsPageActive) settingsStore.settingsPageActive = false;
+ if (id) activateQuerySurface();
selectedSql.value = "";
activeOutputView.value = "result";
if (id) queryStore.reloadEvictedTab(id);
@@ -2318,8 +2322,7 @@ function activateQueryTab(tabId: string): boolean {
if (!queryStore.tabs.some((tab) => tab.id === tabId)) return false;
dispatchBeforeTabSwitch(tabId);
queryStore.activeTabId = tabId;
- driverStoreActive.value = false;
- settingsStore.settingsPageActive = false;
+ activateQuerySurface();
return true;
}
@@ -2706,6 +2709,7 @@ onMounted(async () => {
window.addEventListener("blur", handleTabSwitcherWindowBlur);
document.addEventListener("visibilitychange", handleTabSwitcherVisibilityChange);
window.addEventListener("dbx-open-driver-store", openDriverStoreFromEvent);
+ window.addEventListener("dbx:activate-query-surface", activateQuerySurface);
window.addEventListener("dbx-mcp-status-changed", handleMcpStatusChanged);
if (isDesktop) {
document.addEventListener("contextmenu", handleContextMenu);
@@ -2779,6 +2783,7 @@ onUnmounted(() => {
document.removeEventListener("visibilitychange", handleTabSwitcherVisibilityChange);
tabSwitcherKeyboard.reset();
window.removeEventListener("dbx-open-driver-store", openDriverStoreFromEvent);
+ window.removeEventListener("dbx:activate-query-surface", activateQuerySurface);
window.removeEventListener("dbx-mcp-status-changed", handleMcpStatusChanged);
document.removeEventListener("contextmenu", handleContextMenu);
window.clearTimeout(sqlLibraryFlyAnimationTimer);
@@ -2854,10 +2859,7 @@ onUnmounted(() => {
@activate-driver-store="openDriverStorePage"
@activate-settings-page="activateSettingsPage"
@locate-tab="locateTabInSidebar"
- @activate-tab="
- driverStoreActive = false;
- settingsStore.settingsPageActive = false;
- "
+ @activate-tab="activateQuerySurface"
@close-driver-store="closeDriverStorePage"
@close-settings-page="closeSettingsPage"
@save-tab="handleSaveTab"
diff --git a/apps/desktop/src/stores/__tests__/queryStore.switchTab.spec.ts b/apps/desktop/src/stores/__tests__/queryStore.switchTab.spec.ts
index fb8ca1c98c..08390a49e5 100644
--- a/apps/desktop/src/stores/__tests__/queryStore.switchTab.spec.ts
+++ b/apps/desktop/src/stores/__tests__/queryStore.switchTab.spec.ts
@@ -11,6 +11,7 @@ describe("queryStore switchTab", () => {
setItem: vi.fn(),
removeItem: vi.fn(),
});
+ vi.stubGlobal("window", { dispatchEvent: vi.fn() });
setActivePinia(createPinia());
});
@@ -36,6 +37,16 @@ describe("queryStore switchTab", () => {
expect(queryStore.activeTabId).toBe(tabId);
});
+ it("notifies the app when switching to an existing tab", async () => {
+ const queryStore = useQueryStore();
+ const tabId = queryStore.createTab("pg-1", "app", "users", "data", "public");
+ const dispatchEvent = window.dispatchEvent as ReturnType<typeof vi.fn>;
+
+ queryStore.switchTab(tabId);
+
+ expect(dispatchEvent).toHaveBeenCalledWith(expect.objectContaining({ type: "dbx:activate-query-surface" }));
+ });
+
it("deactivates settings page when switching to a different tab", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const { useSettingsStore } = await import("@/stores/settingsStore");
diff --git a/apps/desktop/src/stores/queryStore.ts b/apps/desktop/src/stores/queryStore.ts
index 43bf10e577..3ddb972b19 100644
--- a/apps/desktop/src/stores/queryStore.ts
+++ b/apps/desktop/src/stores/queryStore.ts
@@ -84,6 +84,8 @@ import type { SqlExecutionTargetContext } from "@/lib/database/sqlExecutionTarge
import type { DriverProfileWorkspaceScope } from "@/lib/database/driverProfileExtensions";
import type { MultiDbExecutionTarget, MultiDbResultRunExecution } from "@/types/sqlExecution";
+const QUERY_SURFACE_ACTIVATION_EVENT = "dbx:activate-query-surface";
+
const ORACLE_LIKE_METADATA_TYPES = new Set<string>(["oracle", "dameng", "oceanbase-oracle"]);
const ORACLE_DEFERRED_LOB_TYPES = new Set<string>(["CLOB", "NCLOB", "BLOB", "BFILE", "XMLTYPE", "SYS.XMLTYPE"]);
@@ -1960,6 +1962,7 @@ export const useQueryStore = defineStore("query", () => {
function switchTab(tabId: string) {
activeTabId.value = tabId;
settingsStore.settingsPageActive = false;
+ if (typeof window !== "undefined") window.dispatchEvent(new Event(QUERY_SURFACE_ACTIVATION_EVENT));
}
function openUserAdmin(connectionId: string) {