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): support F5 shortcut to refresh sidebar connection and databases (#12780)

lxk955bd43e344c008
diff --git a/apps/desktop/src/App.vue b/apps/desktop/src/App.vue
index 51cc5ffb29..73429bafae 100644
--- a/apps/desktop/src/App.vue
+++ b/apps/desktop/src/App.vue
@@ -4638,6 +4638,13 @@ async function handleKeydown(e: KeyboardEvent) {
return;
}
if (isRefreshDataShortcut(e, shortcuts)) {
+ const target = e.target instanceof Element ? e.target : null;
+ const sidebarFocused = isSidebarFocusedTarget(target, lastFocusedSidebarSurface.value);
+ if (sidebarFocused && appSidebarRef.value?.refreshSidebar?.()) {
+ e.preventDefault();
+ e.stopPropagation();
+ return;
+ }
e.preventDefault();
e.stopPropagation();
contentAreaRef.value?.refreshData();
diff --git a/apps/desktop/src/components/layout/AppSidebar.vue b/apps/desktop/src/components/layout/AppSidebar.vue
index abf470e287..b91046ec38 100644
--- a/apps/desktop/src/components/layout/AppSidebar.vue
+++ b/apps/desktop/src/components/layout/AppSidebar.vue
@@ -8,6 +8,7 @@ import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "
import { Input } from "@/components/ui/input";
import LightDropdown from "@/components/ui/LightDropdown.vue";
import LightTooltip from "@/components/ui/LightTooltip.vue";
+import { formatShortcut } from "@/lib/editor/shortcutRegistry";
import PluginShortcutBar from "@/components/plugins/PluginShortcutBar.vue";
import { useSettingsStore } from "@/stores/settingsStore";
import ConnectionTree from "@/components/sidebar/ConnectionTree.vue";
@@ -220,11 +221,17 @@ function openTableStructureForSelection(): boolean {
return connectionTreeRef.value?.openTableStructureForSelection?.() ?? false;
}
+const refreshShortcutLabel = computed(() => formatShortcut(settingsStore.editorSettings.shortcuts.refreshData));
+
+function refreshSidebar(): boolean {
+ return connectionTreeRef.value?.refreshSidebar?.() ?? false;
+}
+
async function focusSelectedNode() {
await connectionTreeRef.value?.focusSelectedNode?.();
}
-defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections, focusSelectedNode, openTableStructureForSelection });
+defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections, focusSelectedNode, openTableStructureForSelection, refreshSidebar, refreshTree });
</script>
<template>
@@ -311,7 +318,7 @@ defineExpose({ focusSearch, locateTabInSidebar, disconnectAllActiveConnections,
</Button>
</LightTooltip>
<LightTooltip :text="t('contextMenu.refreshChildren')" side="bottom" :delay="0" :close-delay="0" nowrap>
- <Button variant="ghost" size="icon" class="h-5 w-5" @click="refreshTree">
+ <Button variant="ghost" size="icon" class="h-5 w-5" :aria-keyshortcuts="refreshShortcutLabel || undefined" @click="refreshTree">
<RefreshCw class="h-3 w-3" />
</Button>
</LightTooltip>
diff --git a/apps/desktop/src/components/sidebar/ConnectionTree.vue b/apps/desktop/src/components/sidebar/ConnectionTree.vue
index b6e58c6389..dac547a005 100644
--- a/apps/desktop/src/components/sidebar/ConnectionTree.vue
+++ b/apps/desktop/src/components/sidebar/ConnectionTree.vue
@@ -1,6 +1,7 @@
<script setup lang="ts">
import { ref, shallowRef, computed, nextTick, watch, provide, onMounted, onUnmounted, type Component, type ComponentPublicInstance, type CSSProperties } from "vue";
import { useI18n } from "vue-i18n";
+import { translateBackendError } from "@/i18n/backend-errors";
import { Search, X, ListOrdered, ArrowDownAZ, ArrowUpZA, Server, Database, FolderTree, Table2, Eye, RotateCcw, Loader2, Unplug } from "@lucide/vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore";
@@ -32,7 +33,7 @@ import { needsSidebarObjectGroupDiscovery } from "@/lib/sidebar/sidebarSearchDis
import { isSidebarSearchPrunedDatabaseNode, resolveSidebarSearchDatabaseScope } from "@/lib/sidebar/sidebarSearchDatabaseScope";
import { createSidebarSearchExpansionState } from "@/lib/sidebar/sidebarSearchExpansionState";
import { createSidebarSearchLoadingTracker } from "@/lib/sidebar/sidebarSearchLoadingTracker";
-import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isEditSidebarTableStructureShortcut, isPasteSidebarSelectionShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
+import { isCancelSearchShortcut, isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isEditSidebarTableStructureShortcut, isPasteSidebarSelectionShortcut, isRefreshDataShortcut, isViewTableDdlShortcut } from "@/lib/editor/keyboardShortcuts";
import { sidebarNodeSupportsDdlView } from "@/lib/sidebar/sidebarTreeDdlShortcut";
import { hasTreeNodeDatabaseContext } from "@/lib/sidebar/treeNodeContext";
import { objectSourceTargetForTreeNode } from "@/lib/sidebar/treeNodeClick";
@@ -2227,6 +2228,25 @@ function openSidebarTableStructureForSelection(): boolean {
return sidebarTreeRuntimeHostRef.value?.openStructureEditorForSelection?.(node) ?? false;
}
+function requestSelectedSidebarRefresh(): boolean {
+ const selectedNodeId = store.selectedTreeNodeId;
+ const node = selectedNodeId ? flatTreeIndex.value.nodeById.get(selectedNodeId) : null;
+ if (node && sidebarTreeRuntimeHostRef.value?.refreshNode?.(node)) {
+ return true;
+ }
+ void refreshAllSidebarTree();
+ return true;
+}
+
+async function refreshAllSidebarTree() {
+ try {
+ await store.reloadFromDisk();
+ await store.refreshAllTree();
+ } catch (e: any) {
+ toast(t("connection.connectFailed", { message: translateBackendError(t, e) }), 5000);
+ }
+}
+
function openSidebarElasticsearchIndexMetadata(node: TreeNode, kind: ElasticsearchIndexMetadataKind) {
if (!node.connectionId) return;
beginSidebarAction();
@@ -2577,6 +2597,13 @@ function onWindowKeydown(event: KeyboardEvent) {
}
return;
}
+ if (sidebarShortcutTargetAllowsAppShortcut(event.target) && isRefreshDataShortcut(event, settingsStore.editorSettings.shortcuts)) {
+ if (requestSelectedSidebarRefresh()) {
+ event.preventDefault();
+ event.stopPropagation();
+ }
+ return;
+ }
}
if (!pointerInsideTree.value || isEditableSidebarTypeSearchTarget(event.target) || isEditableSidebarTypeSearchTarget(document.activeElement)) return;
@@ -2603,7 +2630,9 @@ function sidebarShortcutTargetIsActive(target: EventTarget | null): boolean {
}
function sidebarShortcutTargetAllowsAppShortcut(target: EventTarget | null): boolean {
+ if (sidebarDialogOpen()) return false;
if (!(target instanceof HTMLElement)) return true;
+ if (target.closest('[role="dialog"], [role="alertdialog"]')) return false;
return !(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement || target.isContentEditable || !!target.closest("[contenteditable='true'], [role='textbox']"));
}
@@ -2753,6 +2782,7 @@ defineExpose({
disconnectAllActiveConnections,
focusSelectedNode,
openTableStructureForSelection: openSidebarTableStructureForSelection,
+ refreshSidebar: requestSelectedSidebarRefresh,
});
</script>
diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
index 557a67538a..8c0e2e8c21 100644
--- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue
@@ -163,7 +163,7 @@ import {
import { customTypeCapabilities, supportsTypeObjectSource } from "@/lib/database/databaseObjectCapabilities";
import { mongoCollectionTableTypeFromNode, mongoCreateDatabasePreview, mongoDropIndexFailureCount } from "@/lib/sidebar/mongoCollectionMutation";
import { dataTabOpenModeFromTreeClick, type DataTabOpenMode } from "@/lib/sidebar/dataTabOpenPolicy";
-import { isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isEditSidebarTableStructureShortcut, isModRShortcut, isPasteSidebarSelectionShortcut } from "@/lib/editor/keyboardShortcuts";
+import { isCopySidebarSelectionShortcut, isDisconnectSidebarConnectionShortcut, isEditSidebarConnectionShortcut, isEditSidebarTableStructureShortcut, isModRShortcut, isPasteSidebarSelectionShortcut, isRefreshDataShortcut } from "@/lib/editor/keyboardShortcuts";
import { handleSidebarTreeDeleteShortcut } from "@/lib/sidebar/sidebarTreeDeleteShortcut";
import { sidebarNodeSupportsStructureEdit } from "@/lib/sidebar/sidebarTreeStructureShortcut";
import { dataTableDoubleClickAction } from "@/lib/tabs/dataTabActivation";
@@ -1384,7 +1384,7 @@ function onKeydown(event: KeyboardEvent) {
event.stopPropagation();
return;
}
- if (isModRShortcut(event) || (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F5")) {
+ if (isRefreshDataShortcut(event, settingsStore.editorSettings.shortcuts) || isModRShortcut(event) || (!event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey && event.key === "F5")) {
if (!requestRefreshSelectedNode()) return;
event.preventDefault();
event.stopPropagation();
@@ -1555,9 +1555,16 @@ function requestRefreshSelectedNode(): boolean {
return true;
}
+function refreshNode(targetNode?: TreeNode): boolean {
+ const node = targetNode ?? (connectionStore.selectedTreeNodeId ? findSidebarActionTarget(connectionStore.treeNodes, createSidebarActionTarget({ id: connectionStore.selectedTreeNodeId } as TreeNode)) : null) ?? activeNode.value;
+ if (!node) return false;
+ activateRuntimeNode(node);
+ return requestRefreshSelectedNode();
+}
+
function canRefreshTreeNodeShortcut(): boolean {
const type = activeNode.value.type;
- if (type === "connection" || type === "database" || type === "schema" || type === "table" || type === "view" || type === "procedure" || type === "function") {
+ if (type === "connection" || type === "database" || type === "schema" || type === "table" || type === "view" || type === "materialized_view" || type === "sequence" || type === "trigger" || type === "event" || type === "package" || type === "procedure" || type === "function") {
return true;
}
return isGroupLabel(activeNode.value) && type !== "group-partitions";
@@ -6528,7 +6535,7 @@ const shortcutDisconnectConnection = computed(() => settingsStore.editorSettings
const shortcutRename = "F2";
-const shortcutRefresh = "F5";
+const shortcutRefresh = computed(() => settingsStore.editorSettings.shortcuts.refreshData || "F5");
const shortcutDelete = "Delete";
@@ -6796,7 +6803,7 @@ function buildConnectionSidebarMenu(context: SidebarMenuFactoryContext): boolean
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
const visibleFilterMenu = sidebarConnectionVisibleFilterMenu({
canConfigureVisibleDatabases: canConfigureVisibleDatabases.value,
@@ -6920,7 +6927,7 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
return true;
}
@@ -6935,7 +6942,7 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
return true;
}
@@ -6952,7 +6959,7 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: isNodeDefaultDatabase.value ? t("contextMenu.clearDefaultDatabase") : t("contextMenu.setDefaultDatabase"), action: isNodeDefaultDatabase.value ? clearNodeDefaultDatabase : setNodeAsDefaultDatabase, icon: Database });
if (canOpenSqlFileExecution.value) items.push({ sidebarActionId: "sqlFile.title", label: t("sqlFile.title"), action: openSqlFileExecution, icon: FileCode });
items.push({ label: "", separator: true });
- items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
+ items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh.value });
return true;
}
if (canCloseDatabaseConnection.value) {
@@ -7040,7 +7047,7 @@ function buildDatabaseSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
if (canConfigureVisibleSchemas.value) {
items.push({
@@ -7164,7 +7171,7 @@ function buildSpecialSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
return true;
}
@@ -7188,7 +7195,7 @@ function buildSpecialSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
if (!connectionIsEffectivelyReadOnly(connectionStore.getConfig(node.connectionId || ""))) {
items.push({ label: "", separator: true });
@@ -7267,7 +7274,7 @@ function buildSpecialSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
items.push({ label: "", separator: true });
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
@@ -7408,7 +7415,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
}
items.push({ label: "", separator: true });
items.push(exportDataSubmenu(false));
- items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
+ items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh.value });
appendPluginTableMenuItems(items, node);
return true;
}
@@ -7424,7 +7431,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
const sqlHistoryMenu = savedSqlHistorySubmenu();
if (sqlHistoryMenu) items.push(sqlHistoryMenu);
items.push({ label: "", separator: true });
- items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
+ items.push({ sidebarActionId: "contextMenu.refreshChildren", label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh.value });
appendPluginTableMenuItems(items, node);
return true;
}
@@ -7574,7 +7581,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
appendPluginTableMenuItems(items, node);
return true;
@@ -7682,7 +7689,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
if (!isPackageMember) {
items.push({ label: "", separator: true });
@@ -7704,7 +7711,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("contextMenu.viewObject"), action: () => openObjectBrowser(true, true), icon: Eye });
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
items.push({ label: t("contextMenu.dropObject"), action: deleteMenuAction(requestDropObject), icon: Trash2, shortcut: shortcutDelete, variant: "destructive" as const });
- items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
+ items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh.value });
return true;
}
@@ -7730,7 +7737,7 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("xuguSchedulerJob.drop"), action: () => executeXuguSchedulerJobAction("drop"), icon: Trash2, variant: "destructive" as const });
}
items.push({ label: "", separator: true });
- items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh });
+ items.push({ label: t("contextMenu.refreshChildren"), action: refresh, icon: RefreshCw, shortcut: shortcutRefresh.value });
return true;
}
@@ -7880,7 +7887,7 @@ function buildObjectGroupSidebarMenu(context: SidebarMenuFactoryContext): boolea
label: t("contextMenu.refreshChildren"),
action: refresh,
icon: RefreshCw,
- shortcut: shortcutRefresh,
+ shortcut: shortcutRefresh.value,
});
}
return true;
@@ -8304,6 +8311,7 @@ defineExpose({
openDataInNewTab,
openDdlForSelection,
openStructureEditorForSelection,
+ refreshNode,
requestPaste,
toggleNode,
});
diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarRefreshKeyboard.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarRefreshKeyboard.spec.ts
new file mode 100644
index 0000000000..a3ab3ed73d
--- /dev/null
+++ b/apps/desktop/src/components/sidebar/__tests__/SidebarRefreshKeyboard.spec.ts
@@ -0,0 +1,162 @@
+// @vitest-environment happy-dom
+import { describe, expect, it, vi, afterEach } from "vitest";
+import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";
+import { createPinia, setActivePinia } from "pinia";
+import { resolve } from "node:path";
+import { readFileSync } from "node:fs";
+import i18n from "@/i18n";
+import type { TreeNode } from "@/types/database";
+import SidebarTreeRuntimeHost from "@/components/sidebar/SidebarTreeRuntimeHost.vue";
+import { useConnectionStore } from "@/stores/connectionStore";
+import { useSettingsStore } from "@/stores/settingsStore";
+
+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));
+vi.mock("@/composables/useSqlHighlighter", () => ({ useSqlHighlighter: () => ({ highlight: vi.fn() }) }));
+vi.mock("@/composables/useSidebarDataOpenRuntime", () => ({ useSidebarDataOpenRuntime: () => ({ openData: vi.fn() }) }));
+vi.mock("@/composables/useDatabaseOptions", () => ({ useDatabaseOptions: () => ({ getDatabaseOptions: vi.fn() }) }));
+vi.mock("@/composables/useSidebarTableMutationRuntime", () => ({ useSidebarTableMutationRuntime: () => ({}) }));
+vi.mock("@/composables/useSidebarTreeExportRuntime", () => ({ useSidebarTreeExportRuntime: () => ({}) }));
+vi.mock("@/composables/useSidebarTreeToolRuntime", () => ({ useSidebarTreeToolRuntime: () => ({}) }));
+
+const mountedApps: App<Element>[] = [];
+
+async function flush(): Promise<void> {
+ await nextTick();
+ await new Promise((resolve) => setTimeout(resolve, 10));
+ await nextTick();
+}
+
+function mountHost(node: TreeNode) {
+ const pinia = createPinia();
+ setActivePinia(pinia);
+
+ const hostRef = ref<InstanceType<typeof SidebarTreeRuntimeHost> | null>(null);
+ const container = document.createElement("div");
+ document.body.append(container);
+
+ const Root = defineComponent({
+ setup() {
+ return () => h(SidebarTreeRuntimeHost, { ref: hostRef, node, depth: 0 });
+ },
+ });
+
+ const app = createApp(Root);
+ app.use(pinia);
+ app.use(i18n);
+ app.mount(container);
+ mountedApps.push(app);
+
+ return { hostRef, container, pinia };
+}
+
+describe("Sidebar F5 refresh shortcut and connection database reload (#12246)", () => {
+ afterEach(() => {
+ for (const app of mountedApps) app.unmount();
+ mountedApps.length = 0;
+ document.body.innerHTML = "";
+ vi.clearAllMocks();
+ });
+
+ it("exposes refreshNode and refreshes a connection node and its databases", async () => {
+ const connNode: TreeNode = {
+ id: "mysql-1",
+ label: "MySQL Production",
+ type: "connection",
+ connectionId: "mysql-1",
+ isExpanded: true,
+ children: [],
+ };
+
+ const { hostRef } = mountHost(connNode);
+ await flush();
+
+ const connectionStore = useConnectionStore();
+ connectionStore.treeNodes = [connNode];
+ connectionStore.connectedIds.add("mysql-1");
+ const refreshConnectionSpy = vi.spyOn(connectionStore, "refreshConnectionTreeNode").mockResolvedValue(undefined);
+
+ expect(typeof hostRef.value?.refreshNode).toBe("function");
+
+ const result = hostRef.value?.refreshNode(connNode);
+ expect(result).toBe(true);
+ await flush();
+ expect(refreshConnectionSpy).toHaveBeenCalledWith(expect.objectContaining({ id: "mysql-1", type: "connection" }));
+ });
+
+ it("refreshes a database node when selected", async () => {
+ const dbNode: TreeNode = {
+ id: "mysql-1:shop_db",
+ label: "shop_db",
+ type: "database",
+ connectionId: "mysql-1",
+ database: "shop_db",
+ isExpanded: true,
+ children: [],
+ };
+
+ const { hostRef } = mountHost(dbNode);
+ await flush();
+
+ const connectionStore = useConnectionStore();
+ connectionStore.treeNodes = [dbNode];
+ connectionStore.connectedIds.add("mysql-1");
+ const refreshTreeNodeSpy = vi.spyOn(connectionStore, "refreshTreeNode").mockResolvedValue(undefined);
+
+ const result = hostRef.value?.refreshNode(dbNode);
+ expect(result).toBe(true);
+ await flush();
+ expect(refreshTreeNodeSpy).toHaveBeenCalledWith(expect.objectContaining({ id: "mysql-1:shop_db", type: "database" }));
+ });
+
+ it("updates context menu shortcut based on configured refreshData shortcut", async () => {
+ const connNode: TreeNode = {
+ id: "conn-1",
+ label: "Local DB",
+ type: "connection",
+ connectionId: "conn-1",
+ };
+
+ const { hostRef } = mountHost(connNode);
+ await flush();
+
+ const connectionStore = useConnectionStore();
+ connectionStore.connections = [{ id: "conn-1", name: "Local DB", db_type: "mysql" } as any];
+
+ const settingsStore = useSettingsStore();
+ settingsStore.editorSettings.shortcuts.refreshData = "F5";
+ await flush();
+
+ const menu = hostRef.value?.buildContextMenu(connNode);
+ const refreshItem = menu?.find((item) => item.sidebarActionId === "contextMenu.refreshChildren" || item.label.includes("刷新") || item.label.includes("Refresh"));
+ expect(refreshItem?.shortcut).toBe("F5");
+
+ settingsStore.editorSettings.shortcuts.refreshData = "Mod+R";
+ await flush();
+
+ const updatedMenu = hostRef.value?.buildContextMenu(connNode);
+ const updatedRefreshItem = updatedMenu?.find((item) => item.sidebarActionId === "contextMenu.refreshChildren" || item.label.includes("刷新") || item.label.includes("Refresh"));
+ expect(updatedRefreshItem?.shortcut).toBe("Mod+R");
+ });
+
+ it("verifies ConnectionTree, AppSidebar, and App.vue routing for F5 sidebar refresh", () => {
+ const cwd = process.cwd();
+ const appSource = readFileSync(resolve(cwd, "apps/desktop/src/App.vue"), "utf8");
+ const appSidebarSource = readFileSync(resolve(cwd, "apps/desktop/src/components/layout/AppSidebar.vue"), "utf8");
+ const connectionTreeSource = readFileSync(resolve(cwd, "apps/desktop/src/components/sidebar/ConnectionTree.vue"), "utf8");
+
+ // In App.vue: refreshData shortcut checks isSidebarFocusedTarget and delegates to appSidebarRef.value?.refreshSidebar()
+ expect(appSource).toContain("isRefreshDataShortcut(e, shortcuts)");
+ expect(appSource).toMatch(/isSidebarFocusedTarget\(target,\s*lastFocusedSidebarSurface\.value\)/);
+ expect(appSource).toContain("appSidebarRef.value?.refreshSidebar?.()");
+
+ // In AppSidebar.vue: refreshSidebar delegates to ConnectionTree
+ expect(appSidebarSource).toContain("connectionTreeRef.value?.refreshSidebar?.()");
+ expect(appSidebarSource).toContain("refreshSidebar,");
+ expect(appSidebarSource).toContain("refreshShortcutLabel");
+
+ // In ConnectionTree.vue: handles isRefreshDataShortcut and exposes refreshSidebar
+ expect(connectionTreeSource).toContain("isRefreshDataShortcut(event, settingsStore.editorSettings.shortcuts)");
+ expect(connectionTreeSource).toContain("requestSelectedSidebarRefresh()");
+ expect(connectionTreeSource).toContain("refreshSidebar: requestSelectedSidebarRefresh");
+ });
+});
diff --git a/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts b/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts
index bb02144a80..07aa7149c6 100644
--- a/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts
+++ b/apps/desktop/src/lib/sidebar/sidebarTreeRuntime.ts
@@ -23,6 +23,7 @@ export interface SidebarTreeRuntimeHost {
openDataInNewTab(node: TreeNode): void;
openDdlForSelection(node: TreeNode, selectedNodeIds: readonly string[]): Promise<boolean>;
openStructureEditorForSelection?(node: TreeNode): boolean;
+ refreshNode?(node?: TreeNode): boolean;
requestPaste(node: TreeNode): boolean;
toggleNode(node: TreeNode): void;
}