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。

feat(sidebar): show active connection host and port

dienaso8f22a9f8cdd7
diff --git a/apps/desktop/src/components/layout/AppSidebar.vue b/apps/desktop/src/components/layout/AppSidebar.vue
index d53d780115..130986751d 100644
--- a/apps/desktop/src/components/layout/AppSidebar.vue
+++ b/apps/desktop/src/components/layout/AppSidebar.vue
@@ -2,7 +2,7 @@
import { computed, ref } from "vue";
import { useI18n } from "vue-i18n";
import { translateBackendError } from "@/i18n/backend-errors";
-import { Upload, Download, ArrowDownUp, FolderPlus, FolderOpen, RefreshCw, ChevronsLeft, ChevronsDownUp, Trash2, FolderInput, Check, Minus, Square, X } from "@lucide/vue";
+import { Upload, Download, ArrowDownUp, FolderPlus, FolderOpen, RefreshCw, ChevronsLeft, ChevronsDownUp, Trash2, FolderInput, Check, Minus, Square, X, Server } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
import { Input } from "@/components/ui/input";
@@ -14,6 +14,7 @@ import ConnectionTree from "@/components/sidebar/ConnectionTree.vue";
import { applyConnectionMultiSelection, emptyConnectionMultiSelection, isExitConnectionMultiSelectionShortcut } from "@/lib/sidebar/sidebarConnectionMultiSelect";
import { connectionGroupDestinationRows } from "@/lib/sidebar/sidebarLayout";
import { useConnectionStore } from "@/stores/connectionStore";
+import { useQueryStore } from "@/stores/queryStore";
import { useToast } from "@/composables/useToast";
import type { QueryTab, TreeNode } from "@/types/database";
@@ -35,6 +36,7 @@ type ImportSource = "dbx" | "navicat" | "dbeaver" | "datagrip";
const { t } = useI18n();
const connectionStore = useConnectionStore();
+const queryStore = useQueryStore();
const settingsStore = useSettingsStore();
const { toast } = useToast();
const connectionTreeRef = ref<InstanceType<typeof ConnectionTree>>();
@@ -62,6 +64,17 @@ const connectionTransferItems = computed(() => [
},
]);
const connectionTransferLabel = computed(() => t("sidebar.importExport"));
+const activeWindowConnection = computed(() => {
+ const tab = queryStore.tabs.find((item) => item.id === queryStore.activeTabId);
+ const connectionId = tab?.connectionId || connectionStore.activeConnectionId;
+ return connectionId ? connectionStore.getConfig(connectionId) : undefined;
+});
+const activeConnectionEndpoint = computed(() => {
+ const connection = activeWindowConnection.value;
+ if (!connection) return "";
+ const host = connection.host?.trim();
+ return host ? `${host}:${connection.port}` : "";
+});
const connectionIdSet = computed(() => new Set(connectionStore.connections.map((connection) => connection.id)));
const allConnectionIds = computed(() => connectionStore.connections.map((connection) => connection.id));
const selectedConnectionIds = computed(() => (connectionStore.connectionMultiSelectActive ? connectionStore.selectedTreeNodeIds.filter((id) => connectionIdSet.value.has(id)) : []));
@@ -309,6 +322,10 @@ defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections,
<div class="flex-1 min-h-0">
<ConnectionTree ref="connectionTreeRef" @open-settings="(initialTab) => emit('open-settings', initialTab)" @add-to-ai="(nodes) => emit('add-to-ai', nodes)" />
</div>
+ <div v-if="activeConnectionEndpoint" data-sidebar-connection-endpoint class="flex shrink-0 items-center gap-1.5 border-t border-border/60 px-2.5 py-1.5 text-[11px] leading-none text-muted-foreground" :title="activeWindowConnection?.name">
+ <Server class="h-3 w-3 shrink-0" />
+ <span class="min-w-0 truncate font-mono">{{ activeConnectionEndpoint }}</span>
+ </div>
<PluginShortcutBar v-if="settingsStore.editorSettings.pluginShortcuts.enabled && settingsStore.editorSettings.pluginShortcuts.position === 'sidebar-bottom'" position="sidebar-bottom" />
</div>
<div class="panel-resize-handle panel-resize-handle--right" @pointerdown="emit('startResize', $event)" />
diff --git a/apps/desktop/src/components/layout/__tests__/AppSidebar.connectionEndpoint.spec.ts b/apps/desktop/src/components/layout/__tests__/AppSidebar.connectionEndpoint.spec.ts
new file mode 100644
index 0000000000..bb3aa4b5a9
--- /dev/null
+++ b/apps/desktop/src/components/layout/__tests__/AppSidebar.connectionEndpoint.spec.ts
@@ -0,0 +1,149 @@
+// @vitest-environment happy-dom
+import { createApp, nextTick } from "vue";
+import { createPinia } from "pinia";
+import { createI18n } from "vue-i18n";
+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
+
+vi.mock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
+vi.mock("@tauri-apps/api/core", () => ({ invoke: vi.fn(async () => undefined) }));
+vi.mock("@tauri-apps/api/event", () => ({
+ listen: vi.fn(async () => () => {}),
+ emit: vi.fn(async () => undefined),
+}));
+vi.mock("@tauri-apps/api/webviewWindow", () => ({
+ getAllWebviewWindows: vi.fn(async () => []),
+ WebviewWindow: { getByLabel: vi.fn(async () => null) },
+}));
+vi.mock("@tauri-apps/api/window", () => ({
+ getCurrentWindow: () => ({
+ label: "main",
+ isMaximized: async () => false,
+ isFullscreen: async () => false,
+ isAlwaysOnTop: async () => false,
+ setAlwaysOnTop: async () => {},
+ onResized: async () => () => {},
+ onFocusChanged: async () => () => {},
+ minimize: async () => {},
+ toggleMaximize: async () => {},
+ }),
+}));
+
+vi.mock("@/components/sidebar/ConnectionTree.vue", () => ({
+ default: { name: "ConnectionTreeStub", template: `<div />` },
+}));
+vi.mock("@/components/plugins/PluginShortcutBar.vue", () => ({
+ default: { name: "PluginShortcutBarStub", template: `<div />` },
+}));
+vi.mock("@/components/ui/LightDropdown.vue", () => ({
+ default: { name: "LightDropdownStub", template: `<div />` },
+}));
+vi.mock("@/components/ui/LightTooltip.vue", () => ({
+ default: { name: "LightTooltipStub", props: ["text"], template: `<span :title="text"><slot /></span>` },
+}));
+vi.mock("@/components/ui/button", () => ({
+ Button: { name: "ButtonStub", template: `<button><slot /></button>` },
+}));
+vi.mock("@/components/ui/dialog", () => ({
+ Dialog: { name: "DialogStub", template: `<div><slot /></div>` },
+ DialogContent: { name: "DialogContentStub", template: `<div><slot /></div>` },
+ DialogFooter: { name: "DialogFooterStub", template: `<div><slot /></div>` },
+ DialogHeader: { name: "DialogHeaderStub", template: `<div><slot /></div>` },
+ DialogTitle: { name: "DialogTitleStub", template: `<div><slot /></div>` },
+}));
+vi.mock("@/components/ui/input", () => ({
+ Input: { name: "InputStub", template: `<input />` },
+}));
+
+import { useConnectionStore } from "@/stores/connectionStore";
+import { useQueryStore } from "@/stores/queryStore";
+import AppSidebar from "../AppSidebar.vue";
+
+const connection = (id: string, host: string, port: number) =>
+ ({
+ id,
+ name: `Connection ${id}`,
+ db_type: "mysql",
+ host,
+ port,
+ username: "root",
+ password: "",
+ database: "app",
+ }) as never;
+
+let pinia: ReturnType<typeof createPinia>;
+let host: HTMLDivElement | null = null;
+
+function mountSidebar() {
+ host = document.createElement("div");
+ document.body.appendChild(host);
+ const app = createApp(AppSidebar, { sidebarWidth: 260 });
+ app.use(pinia);
+ app.use(
+ createI18n({
+ legacy: false,
+ locale: "en",
+ missingWarn: false,
+ fallbackWarn: false,
+ messages: { en: {} },
+ }),
+ );
+ app.mount(host);
+ return app;
+}
+
+function endpointText(): string {
+ return document.querySelector("[data-sidebar-connection-endpoint]")?.textContent?.trim() ?? "";
+}
+
+beforeEach(() => {
+ pinia = createPinia();
+});
+
+afterEach(() => {
+ host?.remove();
+ host = null;
+});
+
+describe("AppSidebar current connection endpoint", () => {
+ it("shows the active tab connection host and port", async () => {
+ const connectionStore = useConnectionStore(pinia);
+ const queryStore = useQueryStore(pinia);
+ connectionStore.connections = [connection("c1", "10.0.0.5", 3306), connection("c2", "10.0.0.6", 5432)];
+ connectionStore.activeConnectionId = "c2";
+ queryStore.tabs = [{ id: "t1", connectionId: "c1" } as never];
+ queryStore.activeTabId = "t1";
+
+ mountSidebar();
+ await nextTick();
+
+ expect(endpointText()).toBe("10.0.0.5:3306");
+ });
+
+ it("falls back to the selected connection when no tab is open", async () => {
+ const connectionStore = useConnectionStore(pinia);
+ const queryStore = useQueryStore(pinia);
+ connectionStore.connections = [connection("c1", "db.internal", 15432)];
+ connectionStore.activeConnectionId = "c1";
+ queryStore.tabs = [];
+ queryStore.activeTabId = null;
+
+ mountSidebar();
+ await nextTick();
+
+ expect(endpointText()).toBe("db.internal:15432");
+ });
+
+ it("renders nothing when no connection is active", async () => {
+ const connectionStore = useConnectionStore(pinia);
+ const queryStore = useQueryStore(pinia);
+ connectionStore.connections = [];
+ connectionStore.activeConnectionId = null;
+ queryStore.tabs = [];
+ queryStore.activeTabId = null;
+
+ mountSidebar();
+ await nextTick();
+
+ expect(document.querySelector("[data-sidebar-connection-endpoint]")).toBeNull();
+ });
+});
diff --git a/docs/screenshots/issue-12427-connection-endpoint.png b/docs/screenshots/issue-12427-connection-endpoint.png
new file mode 100644
index 0000000000..689eea81d1
Binary files /dev/null and b/docs/screenshots/issue-12427-connection-endpoint.png differ