fix(grid): open Columns tab via the table structure shortcut

This commit is contained in:
OOMEcho authored and GitHub committed 2026-09-30 12:24:11 +08:00
1 parent 44064a0eea
commit 89964dafe4
2 files changed
+31 -17

No files matched your search

@@ -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
<span class="table-info-action-label">{{ t("contextMenu.dropAllIndexes") }}</span>
</Button>
</div>
<Button v-if="canOpenTableStructureEditor" variant="ghost" size="sm" class="table-info-action-button h-6 px-2 text-xs" :title="t('contextMenu.editStructure')" :aria-label="t('contextMenu.editStructure')" @click="openTableStructureEditor">
<Button v-if="canOpenTableStructureEditor" variant="ghost" size="sm" class="table-info-action-button h-6 px-2 text-xs" :title="t('contextMenu.editStructure')" :aria-label="t('contextMenu.editStructure')" @click="openTableStructureEditor(activeTableInfoTab)">
<PencilRuler class="w-3 h-3" />
<span class="table-info-action-label">{{ t("contextMenu.editStructure") }}</span>
</Button>
@@ -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(/<Button v-if="canOpenTableStructureEditor"[^>]*@click="openTableStructureEditor">/);
const editButton = host.querySelector<HTMLButtonElement>(`button[aria-label="${i18n.global.t("contextMenu.editStructure")}"]`);
expect(editButton).not.toBeNull();
editButton!.click();
await settle();
expect(openTableStructure).toHaveBeenCalledExactlyOnceWith("connection-1", "app", "public", "users", "triggers", undefined, "warehouse", "table");
});
});