fix(grid): open Columns tab via the table structure shortcut
This commit is contained in:
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)) {
|
if (!targetAllowsNativeClipboard && props.context === "table-data" && canOpenTableStructureEditor.value && isEditTableStructureShortcut(event, settingsStore.editorSettings.shortcuts)) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
openTableStructureEditor();
|
openTableStructureEditor("columns");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!targetAllowsNativeClipboard && isGoToColumnShortcut(event, settingsStore.editorSettings.shortcuts) && openGoToColumn()) {
|
if (!targetAllowsNativeClipboard && isGoToColumnShortcut(event, settingsStore.editorSettings.shortcuts) && openGoToColumn()) {
|
||||||
@@ -11582,9 +11582,9 @@ function copyDdl() {
|
|||||||
copyText(ddlContent.value);
|
copyText(ddlContent.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
function openTableStructureEditor() {
|
function openTableStructureEditor(initialTab: TableInfoTab) {
|
||||||
if (!props.connectionId || !props.database || !props.tableMeta?.tableName || !canOpenTableStructureEditor.value) return;
|
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() {
|
function toggleDdlWrap() {
|
||||||
@@ -14010,7 +14010,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val
|
|||||||
<span class="table-info-action-label">{{ t("contextMenu.dropAllIndexes") }}</span>
|
<span class="table-info-action-label">{{ t("contextMenu.dropAllIndexes") }}</span>
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</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" />
|
<PencilRuler class="w-3 h-3" />
|
||||||
<span class="table-info-action-label">{{ t("contextMenu.editStructure") }}</span>
|
<span class="table-info-action-label">{{ t("contextMenu.editStructure") }}</span>
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
+27
-13
@@ -1,12 +1,10 @@
|
|||||||
// @vitest-environment happy-dom
|
// @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 { createApp, defineComponent, h, markRaw, nextTick, type App, type PropType } from "vue";
|
||||||
import { createPinia, setActivePinia } from "pinia";
|
import { createPinia, setActivePinia } from "pinia";
|
||||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||||
import i18n from "@/i18n";
|
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";
|
import { TooltipProvider } from "@/components/ui/tooltip";
|
||||||
|
|
||||||
vi.mock("@/composables/useDataGridColumnResize", async (importOriginal) => {
|
vi.mock("@/composables/useDataGridColumnResize", async (importOriginal) => {
|
||||||
@@ -30,7 +28,6 @@ import DataGrid from "../DataGrid.vue";
|
|||||||
import { useQueryStore } from "@/stores/queryStore";
|
import { useQueryStore } from "@/stores/queryStore";
|
||||||
import { useSettingsStore } from "@/stores/settingsStore";
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
|
|
||||||
const dataGridSource = readFileSync(resolve(import.meta.dirname, "../DataGrid.vue"), "utf8");
|
|
||||||
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
const mountedApps: Array<{ app: App; host: HTMLElement }> = [];
|
||||||
|
|
||||||
const RecycleScroller = defineComponent({
|
const RecycleScroller = defineComponent({
|
||||||
@@ -66,6 +63,8 @@ function mountGrid(
|
|||||||
database?: string;
|
database?: string;
|
||||||
tableMeta?: TableMeta | null;
|
tableMeta?: TableMeta | null;
|
||||||
shortcut?: string;
|
shortcut?: string;
|
||||||
|
tableInfoTab?: TableInfoTab;
|
||||||
|
autoShowTableInfo?: boolean;
|
||||||
} = {},
|
} = {},
|
||||||
) {
|
) {
|
||||||
const pinia = createPinia();
|
const pinia = createPinia();
|
||||||
@@ -73,6 +72,7 @@ function mountGrid(
|
|||||||
const settingsStore = useSettingsStore();
|
const settingsStore = useSettingsStore();
|
||||||
settingsStore.updateEditorSettings({
|
settingsStore.updateEditorSettings({
|
||||||
dataGridRenderMode: "canvas",
|
dataGridRenderMode: "canvas",
|
||||||
|
tableInfoActiveTab: options.tableInfoTab ?? "ddl",
|
||||||
shortcuts: {
|
shortcuts: {
|
||||||
...settingsStore.editorSettings.shortcuts,
|
...settingsStore.editorSettings.shortcuts,
|
||||||
editTableStructure: options.shortcut ?? "Mod+D",
|
editTableStructure: options.shortcut ?? "Mod+D",
|
||||||
@@ -111,6 +111,7 @@ function mountGrid(
|
|||||||
connectionId: options.connectionId ?? "connection-1",
|
connectionId: options.connectionId ?? "connection-1",
|
||||||
database: options.database ?? "app",
|
database: options.database ?? "app",
|
||||||
tableMeta: options.tableMeta === null ? undefined : (options.tableMeta ?? defaultTableMeta),
|
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(event.defaultPrevented).toBe(true);
|
||||||
expect(bubbled).not.toHaveBeenCalled();
|
expect(bubbled).not.toHaveBeenCalled();
|
||||||
expect(openTableStructure).toHaveBeenCalledOnce();
|
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 () => {
|
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(customEvent.defaultPrevented).toBe(true);
|
||||||
expect(bubbled).toHaveBeenCalledOnce();
|
expect(bubbled).toHaveBeenCalledOnce();
|
||||||
expect(openTableStructure).toHaveBeenCalledOnce();
|
expect(openTableStructure).toHaveBeenCalledOnce();
|
||||||
|
expect(openTableStructure).toHaveBeenCalledWith("connection-1", "app", "public", "users", "columns", undefined, "warehouse", "table");
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
@@ -251,14 +264,15 @@ describe("DataGrid edit-table-structure shortcut", () => {
|
|||||||
expect(openTableStructure).not.toHaveBeenCalled();
|
expect(openTableStructure).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("routes through the existing guarded action and keeps the button path", () => {
|
it("keeps the drawer's edit button on its current facet", async () => {
|
||||||
const start = dataGridSource.indexOf("async function onGridKeydown");
|
const { host, openTableStructure } = mountGrid({ tableInfoTab: "triggers", autoShowTableInfo: true });
|
||||||
const end = dataGridSource.indexOf("function copyDetailValue", start);
|
await settle();
|
||||||
const keydown = dataGridSource.slice(start, end);
|
|
||||||
|
|
||||||
expect(keydown).toMatch(
|
const editButton = host.querySelector<HTMLButtonElement>(`button[aria-label="${i18n.global.t("contextMenu.editStructure")}"]`);
|
||||||
/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(editButton).not.toBeNull();
|
||||||
);
|
editButton!.click();
|
||||||
expect(dataGridSource).toMatch(/<Button v-if="canOpenTableStructureEditor"[^>]*@click="openTableStructureEditor">/);
|
await settle();
|
||||||
|
|
||||||
|
expect(openTableStructure).toHaveBeenCalledExactlyOnceWith("connection-1", "app", "public", "users", "triggers", undefined, "warehouse", "table");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in new issue
Block a user