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(settings): enable sidebar auto-expand on connect by default (#13597)

zipg8f0e227db77d
diff --git a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts
index 6734421ee7..6a53991e0b 100644
--- a/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts
+++ b/apps/desktop/src/components/sidebar/__tests__/SidebarTreeRuntimeHost.expansion.spec.ts
@@ -1372,7 +1372,7 @@ describe("SidebarTreeRuntimeHost expansion", () => {
connectionStore.treeNodes = [connectionNode];
connectionStore.loadDatabases = vi.fn(async () => {
- // Loader attaches children but does not set isExpanded (e.g. sidebarExpandTreeOnConnect is false)
+ // Loader attaches children but does not auto-expand the node in this harness.
connectionNode.children = [databaseNode];
});
@@ -1468,9 +1468,9 @@ describe("SidebarTreeRuntimeHost expansion", () => {
});
// #13579: the manual-expansion regression hit every connection type, not just
- // SQL engines. Each loader below attaches children without setting
- // isExpanded (sidebarExpandTreeOnConnect defaults to false), so the shared
- // toggle path must expand the connection node itself.
+ // SQL engines. Each loader below attaches children without auto-expanding the
+ // node (the switch is off for this harness), so the shared toggle path must
+ // expand the connection node itself.
it.each([
{ dbType: "redis", loader: "loadRedisDatabases" as const, childType: "redis-db" as const },
{ dbType: "mongodb", loader: "loadMongoDatabases" as const, childType: "mongo-db" as const },
diff --git a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts b/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
index 9d26a5588e..49c9e7bf06 100644
--- a/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
+++ b/apps/desktop/src/stores/__tests__/settingsStore.spec.ts
@@ -1299,22 +1299,30 @@ describe("normalizeEditorSettings - sidebarPinDefaultDatabase", () => {
});
});
-// #13302:连接后是否自动展开对象树的开关。默认必须为 false——模式多的库
-// 全量自动展开是反馈的卡顿来源,升级后的老用户也走新默认。
+// #13302 implemented this as an opt-in switch with a default-off build, but the
+// old auto-expand behavior was the long-standing default and the off default was
+// taken as a regression. The default is enabled again (migration v1); users with
+// many schemas can still opt out with the switch.
describe("normalizeEditorSettings - sidebarExpandTreeOnConnect", () => {
- it("defaults sidebarExpandTreeOnConnect to false", () => {
- expect(normalizeEditorSettings({}).sidebarExpandTreeOnConnect).toBe(false);
+ it("defaults sidebarExpandTreeOnConnect to true", () => {
+ expect(normalizeEditorSettings({}).sidebarExpandTreeOnConnect).toBe(true);
});
- it("preserves explicit boolean values", () => {
+ it("honors an explicit toggle stamped with the current default version", () => {
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: true, sidebarExpandTreeOnConnectMigrationVersion: 1 }).sidebarExpandTreeOnConnect).toBe(true);
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: false, sidebarExpandTreeOnConnectMigrationVersion: 1 }).sidebarExpandTreeOnConnect).toBe(false);
+ });
+
+ it("migrates legacy blobs without the marker to the enabled default", () => {
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: false }).sidebarExpandTreeOnConnect).toBe(true);
expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: true }).sidebarExpandTreeOnConnect).toBe(true);
- expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: false }).sidebarExpandTreeOnConnect).toBe(false);
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: "false" } as any).sidebarExpandTreeOnConnect).toBe(true);
});
it("falls back to default for non-boolean values", () => {
- expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: "true" } as any).sidebarExpandTreeOnConnect).toBe(false);
- expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: undefined } as any).sidebarExpandTreeOnConnect).toBe(false);
- expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: 1 } as any).sidebarExpandTreeOnConnect).toBe(false);
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: "true" } as any).sidebarExpandTreeOnConnect).toBe(true);
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: undefined } as any).sidebarExpandTreeOnConnect).toBe(true);
+ expect(normalizeEditorSettings({ sidebarExpandTreeOnConnect: 1 } as any).sidebarExpandTreeOnConnect).toBe(true);
});
});
@@ -1361,13 +1369,13 @@ describe("updateEditorSettings - sidebarExpandTreeOnConnect", () => {
// store after every apply. A key that never reaches the store keeps the two apart
// forever, which is what made the dialog report unsaved changes and refuse to close.
const base = editorSettingsDraftFromSettings(store.editorSettings);
- const draft = { ...base, sidebarExpandTreeOnConnect: true };
+ const draft = { ...base, sidebarExpandTreeOnConnect: false };
expect(editorSettingsDraftChanged(draft, base)).toBe(true);
store.updateEditorSettings(editorSettingsPatchFromDraft(draft, base));
const appliedBase = editorSettingsDraftFromSettings(store.editorSettings);
- expect(appliedBase.sidebarExpandTreeOnConnect).toBe(true);
+ expect(appliedBase.sidebarExpandTreeOnConnect).toBe(false);
expect(editorSettingsDraftChanged(draft, appliedBase)).toBe(false);
});
});
diff --git a/apps/desktop/src/stores/settingsStore.ts b/apps/desktop/src/stores/settingsStore.ts
index 3856038432..4f767b8fc1 100644
--- a/apps/desktop/src/stores/settingsStore.ts
+++ b/apps/desktop/src/stores/settingsStore.ts
@@ -1185,8 +1185,10 @@ export interface EditorSettings {
autoSelectActiveSidebarNode: boolean;
sidebarPinDefaultDatabase: boolean;
sidebarBrowseObjectsOnDatabaseActivation: boolean;
- /** 连接成功后是否自动展开侧边栏对象树(连接节点/默认数据库节点)。默认关闭:模式多的库全量展开时元数据请求和渲染开销都大(#13302)。 */
+ /** 连接成功后是否自动展开侧边栏对象树(连接节点/默认数据库节点)。默认开启,与 v0.6.55 及更早的行为一致;模式较多的库可关闭以避免连接期全量展开的元数据请求与渲染开销(#13302)。 */
sidebarExpandTreeOnConnect: boolean;
+ /** 「连接后自动展开对象树」默认值迁移标记(v1:默认由关闭恢复为开启)。 */
+ sidebarExpandTreeOnConnectMigrationVersion: number;
openQueryOnConnectionOpen: boolean;
sidebarBrowseObjectsOnDatabaseActivationMigrationVersion: number;
openTabsRestoreMode: OpenTabsRestoreMode;
@@ -1373,6 +1375,11 @@ const EDITOR_THEME_VALUES = new Set<EditorTheme>(EDITOR_THEMES.map((theme) => th
export const EXECUTE_MODE_CURRENT_DEFAULT_VERSION = 1;
export const SIDEBAR_BROWSE_OBJECTS_MIGRATION_VERSION = 1;
+// v1: "expand tree on connect" became the default again, restoring the pre-v0.6.56
+// behavior. Builds that shipped the default-off version have no marker, so their
+// stored false is treated as the old default rather than an explicit opt-out; once
+// this marker is stamped, an explicit toggle wins.
+export const SIDEBAR_EXPAND_TREE_ON_CONNECT_DEFAULT_VERSION = 1;
// v1: the welcome page default moved from "intro" back to "workspace"; persisted
// blobs from the intro-default builds lack this marker and are migrated.
export const WELCOME_PAGE_DEFAULT_VERSION = 1;
@@ -1552,7 +1559,8 @@ export const DEFAULT_EDITOR_SETTINGS: EditorSettings = {
autoSelectActiveSidebarNode: false,
sidebarPinDefaultDatabase: true,
sidebarBrowseObjectsOnDatabaseActivation: false,
- sidebarExpandTreeOnConnect: false,
+ sidebarExpandTreeOnConnect: true,
+ sidebarExpandTreeOnConnectMigrationVersion: SIDEBAR_EXPAND_TREE_ON_CONNECT_DEFAULT_VERSION,
openQueryOnConnectionOpen: false,
sidebarBrowseObjectsOnDatabaseActivationMigrationVersion: SIDEBAR_BROWSE_OBJECTS_MIGRATION_VERSION,
openTabsRestoreMode: "all",
@@ -2027,6 +2035,9 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
const savedCompactTabTitleDefaultVersion = settings.compactTabTitleDefaultVersion;
const compactTabTitleDefaultVersion = typeof savedCompactTabTitleDefaultVersion === "number" && savedCompactTabTitleDefaultVersion >= COMPACT_TAB_TITLE_DEFAULT_VERSION ? savedCompactTabTitleDefaultVersion : COMPACT_TAB_TITLE_DEFAULT_VERSION;
const hasCurrentCompactTabTitleDefault = compactTabTitleDefaultVersion === savedCompactTabTitleDefaultVersion;
+ const savedSidebarExpandTreeDefaultVersion = settings.sidebarExpandTreeOnConnectMigrationVersion;
+ const sidebarExpandTreeDefaultVersion = typeof savedSidebarExpandTreeDefaultVersion === "number" && savedSidebarExpandTreeDefaultVersion >= SIDEBAR_EXPAND_TREE_ON_CONNECT_DEFAULT_VERSION ? savedSidebarExpandTreeDefaultVersion : SIDEBAR_EXPAND_TREE_ON_CONNECT_DEFAULT_VERSION;
+ const hasCurrentSidebarExpandTreeDefault = sidebarExpandTreeDefaultVersion === savedSidebarExpandTreeDefaultVersion;
// The active id can only be validated once the scheme list it points into is known.
const dataGridTypeColorSchemes = normalizeDataGridTypeColorSchemes(settings.dataGridTypeColorSchemes);
const savedExtractorMigrationVersion = settings.dataGridExtractorOptionsMigrationVersion;
@@ -2257,7 +2268,8 @@ export function normalizeEditorSettings(settings: Partial<EditorSettings>, exist
sidebarSearchOpenedDatabasesOnly: typeof settings.sidebarSearchOpenedDatabasesOnly === "boolean" ? settings.sidebarSearchOpenedDatabasesOnly : DEFAULT_EDITOR_SETTINGS.sidebarSearchOpenedDatabasesOnly,
autoSelectActiveSidebarNode: settings.autoSelectActiveSidebarNode ?? DEFAULT_EDITOR_SETTINGS.autoSelectActiveSidebarNode,
sidebarPinDefaultDatabase: typeof settings.sidebarPinDefaultDatabase === "boolean" ? settings.sidebarPinDefaultDatabase : DEFAULT_EDITOR_SETTINGS.sidebarPinDefaultDatabase,
- sidebarExpandTreeOnConnect: typeof settings.sidebarExpandTreeOnConnect === "boolean" ? settings.sidebarExpandTreeOnConnect : DEFAULT_EDITOR_SETTINGS.sidebarExpandTreeOnConnect,
+ sidebarExpandTreeOnConnect: hasCurrentSidebarExpandTreeDefault && typeof settings.sidebarExpandTreeOnConnect === "boolean" ? settings.sidebarExpandTreeOnConnect : DEFAULT_EDITOR_SETTINGS.sidebarExpandTreeOnConnect,
+ sidebarExpandTreeOnConnectMigrationVersion: SIDEBAR_EXPAND_TREE_ON_CONNECT_DEFAULT_VERSION,
openQueryOnConnectionOpen: typeof settings.openQueryOnConnectionOpen === "boolean" ? settings.openQueryOnConnectionOpen : DEFAULT_EDITOR_SETTINGS.openQueryOnConnectionOpen,
sidebarBrowseObjectsOnDatabaseActivation:
typeof settings.sidebarBrowseObjectsOnDatabaseActivation === "boolean"