From 89964dafe411b6ad36d3db1ac03b0915ff52627c Mon Sep 17 00:00:00 2001 From: OOMEcho <228389787@qq.com> Date: Wed, 30 Sep 2026 12:24:11 +0800 Subject: [PATCH] fix(grid): open Columns tab via the table structure shortcut --- apps/desktop/src/components/grid/DataGrid.vue | 8 ++-- ...DataGridEditTableStructureShortcut.spec.ts | 40 +++++++++++++------ 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/apps/desktop/src/components/grid/DataGrid.vue b/apps/desktop/src/components/grid/DataGrid.vue index 88b66f577b..0bb983edd0 100644 --- a/apps/desktop/src/components/grid/DataGrid.vue +++ b/apps/desktop/src/components/grid/DataGrid.vue @@ -9492,7 +9492,7 @@ async function onGridKeydown(event: KeyboardEvent) { if (!targetAllowsNativeClipboard && props.context === "table-data" && canOpenTableStructureEditor.value && isEditTableStructureShortcut(event, settingsStore.editorSettings.shortcuts)) { event.preventDefault(); event.stopPropagation(); - openTableStructureEditor(); + openTableStructureEditor("columns"); return; } if (!targetAllowsNativeClipboard && isGoToColumnShortcut(event, settingsStore.editorSettings.shortcuts) && openGoToColumn()) { @@ -11582,9 +11582,9 @@ function copyDdl() { copyText(ddlContent.value); } -function openTableStructureEditor() { +function openTableStructureEditor(initialTab: TableInfoTab) { if (!props.connectionId || !props.database || !props.tableMeta?.tableName || !canOpenTableStructureEditor.value) return; - queryStore.openTableStructure(props.connectionId, props.database, props.tableMeta.schema, props.tableMeta.tableName, activeTableInfoTab.value, undefined, props.tableMeta.catalog, (props.tableMeta.tableType || "").toUpperCase() === "VIEW" ? "view" : "table"); + queryStore.openTableStructure(props.connectionId, props.database, props.tableMeta.schema, props.tableMeta.tableName, initialTab, undefined, props.tableMeta.catalog, (props.tableMeta.tableType || "").toUpperCase() === "VIEW" ? "view" : "table"); } function toggleDdlWrap() { @@ -14010,7 +14010,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val {{ t("contextMenu.dropAllIndexes") }} - diff --git a/apps/desktop/src/components/grid/__tests__/DataGridEditTableStructureShortcut.spec.ts b/apps/desktop/src/components/grid/__tests__/DataGridEditTableStructureShortcut.spec.ts index 191bd45810..48409800d6 100644 --- a/apps/desktop/src/components/grid/__tests__/DataGridEditTableStructureShortcut.spec.ts +++ b/apps/desktop/src/components/grid/__tests__/DataGridEditTableStructureShortcut.spec.ts @@ -1,12 +1,10 @@ // @vitest-environment happy-dom -import { readFileSync } from "node:fs"; -import { resolve } from "node:path"; import { createApp, defineComponent, h, markRaw, nextTick, type App, type PropType } from "vue"; import { createPinia, setActivePinia } from "pinia"; import { afterEach, describe, expect, it, vi } from "vitest"; import i18n from "@/i18n"; -import type { ColumnInfo, DatabaseType, QueryResult } from "@/types/database"; +import type { ColumnInfo, DatabaseType, QueryResult, TableInfoTab } from "@/types/database"; import { TooltipProvider } from "@/components/ui/tooltip"; vi.mock("@/composables/useDataGridColumnResize", async (importOriginal) => { @@ -30,7 +28,6 @@ import DataGrid from "../DataGrid.vue"; import { useQueryStore } from "@/stores/queryStore"; import { useSettingsStore } from "@/stores/settingsStore"; -const dataGridSource = readFileSync(resolve(import.meta.dirname, "../DataGrid.vue"), "utf8"); const mountedApps: Array<{ app: App; host: HTMLElement }> = []; const RecycleScroller = defineComponent({ @@ -66,6 +63,8 @@ function mountGrid( database?: string; tableMeta?: TableMeta | null; shortcut?: string; + tableInfoTab?: TableInfoTab; + autoShowTableInfo?: boolean; } = {}, ) { const pinia = createPinia(); @@ -73,6 +72,7 @@ function mountGrid( const settingsStore = useSettingsStore(); settingsStore.updateEditorSettings({ dataGridRenderMode: "canvas", + tableInfoActiveTab: options.tableInfoTab ?? "ddl", shortcuts: { ...settingsStore.editorSettings.shortcuts, editTableStructure: options.shortcut ?? "Mod+D", @@ -111,6 +111,7 @@ function mountGrid( connectionId: options.connectionId ?? "connection-1", database: options.database ?? "app", tableMeta: options.tableMeta === null ? undefined : (options.tableMeta ?? defaultTableMeta), + autoShowTableInfo: options.autoShowTableInfo ?? false, }), }, ); @@ -167,7 +168,18 @@ describe("DataGrid edit-table-structure shortcut", () => { expect(event.defaultPrevented).toBe(true); expect(bubbled).not.toHaveBeenCalled(); expect(openTableStructure).toHaveBeenCalledOnce(); - expect(openTableStructure).toHaveBeenCalledWith("connection-1", "app", "public", "users", "ddl", undefined, "warehouse", "table"); + expect(openTableStructure).toHaveBeenCalledWith("connection-1", "app", "public", "users", "columns", undefined, "warehouse", "table"); + }); + + it.each(["triggers", "indexes"] as const)("opens columns even when the drawer remembers %s", async (tableInfoTab) => { + const { host, openTableStructure } = mountGrid({ tableInfoTab }); + await settle(); + + dispatchModShortcut(gridRoot(host), "d"); + await settle(); + + expect(openTableStructure).toHaveBeenCalledExactlyOnceWith("connection-1", "app", "public", "users", "columns", undefined, "warehouse", "table"); + expect(useSettingsStore().editorSettings.tableInfoActiveTab).toBe(tableInfoTab); }); it("uses a configured shortcut and leaves the default key untouched", async () => { @@ -185,6 +197,7 @@ describe("DataGrid edit-table-structure shortcut", () => { expect(customEvent.defaultPrevented).toBe(true); expect(bubbled).toHaveBeenCalledOnce(); expect(openTableStructure).toHaveBeenCalledOnce(); + expect(openTableStructure).toHaveBeenCalledWith("connection-1", "app", "public", "users", "columns", undefined, "warehouse", "table"); }); it.each([ @@ -251,14 +264,15 @@ describe("DataGrid edit-table-structure shortcut", () => { expect(openTableStructure).not.toHaveBeenCalled(); }); - it("routes through the existing guarded action and keeps the button path", () => { - const start = dataGridSource.indexOf("async function onGridKeydown"); - const end = dataGridSource.indexOf("function copyDetailValue", start); - const keydown = dataGridSource.slice(start, end); + it("keeps the drawer's edit button on its current facet", async () => { + const { host, openTableStructure } = mountGrid({ tableInfoTab: "triggers", autoShowTableInfo: true }); + await settle(); - expect(keydown).toMatch( - /if \(!targetAllowsNativeClipboard && props\.context === "table-data" && canOpenTableStructureEditor\.value && isEditTableStructureShortcut\(event, settingsStore\.editorSettings\.shortcuts\)\) \{[\s\S]*?event\.preventDefault\(\);[\s\S]*?event\.stopPropagation\(\);[\s\S]*?openTableStructureEditor\(\);[\s\S]*?return;/, - ); - expect(dataGridSource).toMatch(/