feat(grid): add column header tooltip toggle

This commit is contained in:
OOMEcho authored and GitHub committed 2026-09-24 22:33:50 +08:00
1 parent 3294ade2cc
commit cd24f69daa
21 files changed
+173 -36

No files matched your search

@@ -661,6 +661,7 @@ const debugLogCopied = ref(false);
const debugLogDownloaded = ref(false);
const editShowColumnCommentsInHeader = ref(settingsStore.editorSettings.showColumnCommentsInHeader);
const editShowColumnTypesInHeader = ref(settingsStore.editorSettings.showColumnTypesInHeader);
const editShowColumnHeaderTooltips = ref(settingsStore.editorSettings.showColumnHeaderTooltips);
const editShowResultSourceDatabase = ref(settingsStore.editorSettings.showResultSourceDatabase);
const editDataGridShowTransposeFieldMetadata = ref(settingsStore.editorSettings.dataGridShowTransposeFieldMetadata);
const editColorizeDataGridCellTypes = ref(settingsStore.editorSettings.colorizeDataGridCellTypes);
@@ -1003,6 +1004,7 @@ function currentEditorSettingsDraft(): EditorSettingsDraft {
tabSortMode: editTabSortMode.value,
showColumnCommentsInHeader: editShowColumnCommentsInHeader.value,
showColumnTypesInHeader: editShowColumnTypesInHeader.value,
showColumnHeaderTooltips: editShowColumnHeaderTooltips.value,
showResultSourceDatabase: editShowResultSourceDatabase.value,
dataGridShowTransposeFieldMetadata: editDataGridShowTransposeFieldMetadata.value,
colorizeDataGridCellTypes: editColorizeDataGridCellTypes.value,
@@ -1649,6 +1651,7 @@ function syncEditorSettingsDraftFromStore() {
editTabSortMode.value = settingsStore.editorSettings.tabSortMode;
editShowColumnCommentsInHeader.value = settingsStore.editorSettings.showColumnCommentsInHeader;
editShowColumnTypesInHeader.value = settingsStore.editorSettings.showColumnTypesInHeader;
editShowColumnHeaderTooltips.value = settingsStore.editorSettings.showColumnHeaderTooltips;
editShowResultSourceDatabase.value = settingsStore.editorSettings.showResultSourceDatabase;
editDataGridShowTransposeFieldMetadata.value = settingsStore.editorSettings.dataGridShowTransposeFieldMetadata;
editColorizeDataGridCellTypes.value = settingsStore.editorSettings.colorizeDataGridCellTypes;
@@ -1783,6 +1786,7 @@ const editorSettingsDraftRefs: EditorSettingsDraftRefMap = {
tabSortMode: editTabSortMode,
showColumnCommentsInHeader: editShowColumnCommentsInHeader,
showColumnTypesInHeader: editShowColumnTypesInHeader,
showColumnHeaderTooltips: editShowColumnHeaderTooltips,
showResultSourceDatabase: editShowResultSourceDatabase,
dataGridShowTransposeFieldMetadata: editDataGridShowTransposeFieldMetadata,
colorizeDataGridCellTypes: editColorizeDataGridCellTypes,
@@ -2308,6 +2312,7 @@ function resetDefaultsForTab(tab: SettingsCategory) {
historyRetention.reset();
editShowColumnCommentsInHeader.value = DEFAULT_EDITOR_SETTINGS.showColumnCommentsInHeader;
editShowColumnTypesInHeader.value = DEFAULT_EDITOR_SETTINGS.showColumnTypesInHeader;
editShowColumnHeaderTooltips.value = DEFAULT_EDITOR_SETTINGS.showColumnHeaderTooltips;
editShowResultSourceDatabase.value = DEFAULT_EDITOR_SETTINGS.showResultSourceDatabase;
editDataGridShowTransposeFieldMetadata.value = DEFAULT_EDITOR_SETTINGS.dataGridShowTransposeFieldMetadata;
editColorizeDataGridCellTypes.value = DEFAULT_EDITOR_SETTINGS.colorizeDataGridCellTypes;
@@ -2416,6 +2421,7 @@ function resetAllDefaults() {
editSidebarTablePageSize.value = DEFAULT_SIDEBAR_TABLE_PAGE_SIZE;
editShowColumnCommentsInHeader.value = DEFAULT_EDITOR_SETTINGS.showColumnCommentsInHeader;
editShowColumnTypesInHeader.value = DEFAULT_EDITOR_SETTINGS.showColumnTypesInHeader;
editShowColumnHeaderTooltips.value = DEFAULT_EDITOR_SETTINGS.showColumnHeaderTooltips;
editDataGridShowTransposeFieldMetadata.value = DEFAULT_EDITOR_SETTINGS.dataGridShowTransposeFieldMetadata;
editColorizeDataGridCellTypes.value = DEFAULT_EDITOR_SETTINGS.colorizeDataGridCellTypes;
// Reset the selection only; saved schemes survive a full settings reset.
@@ -7952,6 +7958,17 @@ onUnmounted(() => {
</div>
<Switch id="show-column-types-in-header" v-model="editShowColumnTypesInHeader" />
</div>
<div class="settings-item flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="show-column-header-tooltips">
{{ t("settings.showColumnHeaderTooltips") }}
</Label>
<p class="text-xs text-muted-foreground">
{{ t("settings.showColumnHeaderTooltipsDescription") }}
</p>
</div>
<Switch id="show-column-header-tooltips" v-model="editShowColumnHeaderTooltips" />
</div>
<div class="settings-item flex items-center justify-between gap-4 rounded-md border bg-muted/20 px-3 py-2">
<div class="space-y-1">
<Label for="show-result-source-database">
@@ -760,6 +760,7 @@ const dataGridTopbarOverflowActionCount = ref(0);
const dataGridTopbarExpandedRequiredWidth = ref(0);
const showColumnCommentsInHeader = computed(() => settingsStore.editorSettings.showColumnCommentsInHeader);
const showColumnTypesInHeader = computed(() => settingsStore.editorSettings.showColumnTypesInHeader);
const showColumnHeaderTooltips = computed(() => settingsStore.editorSettings.showColumnHeaderTooltips !== false);
const showTransposeFieldMetadata = computed(() => settingsStore.editorSettings.dataGridShowTransposeFieldMetadata);
const showIndexIndicatorsInHeader = computed(() => settingsStore.editorSettings.showIndexIndicatorsInHeader !== false);
const indexes = ref<IndexInfo[]>([]);
@@ -12740,7 +12741,7 @@ useUpdateBlocker(() => (hasPendingChanges.value || hasPendingDataEditorDraft.val
:dark="isDark"
:frozen="col.visibleColIdx < frozenColumnCount"
:frozen-separator="frozenColumnCount > 0 && col.visibleColIdx === frozenColumnCount - 1"
:tooltip-disabled="columnHeaderTooltipsDisabled"
:tooltip-disabled="columnHeaderTooltipsDisabled || !showColumnHeaderTooltips"
:column-type="headerColumnType(col.name, col.actualColIdx)"
:column-comment="headerColumnComment(col.name, col.actualColIdx)"
:show-type-line="reserveColumnTypeLine"
@@ -1,11 +1,13 @@
// @vitest-environment happy-dom
import { readFileSync } from "node:fs";
import { nextTick } from "vue";
import { createApp, defineComponent, h, nextTick } from "vue";
import { beforeEach, describe, expect, it, vi } from "vitest";
import { createPinia, setActivePinia } from "pinia";
import { dispatch, findAll, findOne, hostText, mountComponent } from "./vueHostHarness";
import type { DataGridCellDetail } from "@/lib/dataGrid/dataGridDetail";
const settingsMock = vi.hoisted(() => ({ store: null as any }));
const mocks = vi.hoisted(() => ({
editor: { create: vi.fn(), destroy: vi.fn(), setValue: vi.fn(), openSearch: vi.fn() },
updateSettings: vi.fn(),
@@ -16,40 +18,15 @@ const mocks = vi.hoisted(() => ({
toast: vi.fn(),
}));
vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key }) }));
vi.mock("vue-i18n", () => ({
useI18n: () => ({ t: (key: string) => key, locale: { value: "en" } }),
// DataGrid.vue's import graph reaches @/i18n, which builds a real i18n instance at module scope.
createI18n: () => ({ install: () => {}, global: { t: (key: string) => key, locale: { value: "en" } } }),
}));
vi.mock("@lucide/vue", async () => {
const { createPassthroughStub } = await import("./vueHostHarness");
const icon = createPassthroughStub("Icon", "i");
return {
Check: icon,
CaseSensitive: icon,
ChevronDown: icon,
ChevronUp: icon,
ChevronLeft: icon,
ChevronRight: icon,
ChevronsLeft: icon,
ChevronsRight: icon,
Download: icon,
ChevronsDown: icon,
Filter: icon,
Focus: icon,
FileDiff: icon,
Loader2: icon,
FileUp: icon,
Upload: icon,
Search: icon,
X: icon,
Code2: icon,
Copy: icon,
Eye: icon,
EyeOff: icon,
GripVertical: icon,
Info: icon,
Pencil: icon,
Plus: icon,
RotateCcw: icon,
Trash2: icon,
};
return new Proxy({}, { get: (_target, key) => (key === "__esModule" ? false : icon), has: () => true });
});
vi.mock("@/components/ui/button", async () => ({ Button: (await import("./vueHostHarness")).createPassthroughStub("Button", "button") }));
@@ -72,7 +49,7 @@ vi.mock("@/components/ui/dropdown-menu", async () => {
});
vi.mock("@/components/ui/popover", async () => {
const { createPassthroughStub } = await import("./vueHostHarness");
return { Popover: createPassthroughStub("Popover"), PopoverContent: createPassthroughStub("PopoverContent"), PopoverTrigger: createPassthroughStub("PopoverTrigger") };
return { Popover: createPassthroughStub("Popover"), PopoverAnchor: createPassthroughStub("PopoverAnchor"), PopoverContent: createPassthroughStub("PopoverContent"), PopoverTrigger: createPassthroughStub("PopoverTrigger") };
});
vi.mock("@/components/ui/tooltip", async () => {
const { createPassthroughStub } = await import("./vueHostHarness");
@@ -90,8 +67,24 @@ vi.mock("@/components/ui/LightTooltip.vue", async () => ({ default: (await impor
vi.mock("@/components/grid/TemporalCellEditor.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("TemporalCellEditor") }));
vi.mock("@/components/grid/DataGridValueTransform.vue", async () => ({ default: (await import("./vueHostHarness")).createPassthroughStub("DataGridValueTransform") }));
vi.mock("@/composables/useCellDetailEditor", () => ({ useCellDetailEditor: () => mocks.editor }));
vi.mock("@/composables/useTheme", () => ({ useTheme: () => ({ isDark: { value: false }, themePalette: { value: {} } }) }));
vi.mock("@/stores/settingsStore", () => ({ useSettingsStore: () => ({ editorSettings: { cellDetailJsonFormatted: true, theme: "default", fontSize: 13, fontFamily: "monospace" }, updateEditorSettings: mocks.updateSettings }) }));
vi.mock("@/composables/useTheme", async () => {
const { ref } = await import("vue");
// Real refs: DataGrid.vue both watches isDark and binds it to a Boolean prop.
const isDark = ref(false);
const themePalette = ref({});
return { useTheme: () => ({ isDark, themePalette }) };
});
vi.mock("@/stores/settingsStore", async () => {
const actual = await vi.importActual<typeof import("@/stores/settingsStore")>("@/stores/settingsStore");
const { reactive } = await import("vue");
// Reactive and complete: DataGrid.vue reads dozens of editor settings and must
// re-render when a test flips one.
settingsMock.store = {
editorSettings: reactive({ ...actual.DEFAULT_EDITOR_SETTINGS, cellDetailJsonFormatted: true, theme: "default", fontSize: 13, fontFamily: "monospace" }),
updateEditorSettings: mocks.updateSettings,
};
return { ...actual, useSettingsStore: () => settingsMock.store };
});
vi.mock("@/lib/dataGrid/geometryPreview", () => ({ isHexGeometry: () => false, renderWktOnCanvas: mocks.renderWkt }));
vi.mock("@/lib/common/clipboard", () => ({ copyToClipboard: mocks.copyToClipboard }));
vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: mocks.toast }) }));
@@ -107,6 +100,7 @@ vi.mock("@/composables/useDataGridCellDetail", async () => {
import DataGridCellDetailDialog from "@/components/grid/DataGridCellDetailDialog.vue";
import DataGridCellDetailPanel from "@/components/grid/DataGridCellDetailPanel.vue";
import DataGrid from "@/components/grid/DataGrid.vue";
import DataGridColumnHeader from "@/components/grid/DataGridColumnHeader.vue";
import DataGridCopyColumnNamesDialog from "@/components/grid/DataGridCopyColumnNamesDialog.vue";
import DataGridFilterBuilder from "@/components/grid/DataGridFilterBuilder.vue";
@@ -1870,3 +1864,44 @@ describe("DataGridCopyColumnNamesDialog", () => {
expect(previewText(mounted)).toBe("id\ttype");
});
});
describe("DataGrid column header tooltips", () => {
// The rest of this file drives leaf components through the host renderer, but
// DataGrid.vue touches the DOM directly (querySelector/observers), so this
// case mounts it into happy-dom instead.
function mountDataGrid() {
setActivePinia(createPinia());
const host = document.createElement("div");
document.body.appendChild(host);
const app = createApp(defineComponent({ setup: () => () => h(DataGrid, { result: { columns: ["id", "name"], rows: [[1, "a"]] } }) }));
app.mount(host);
return {
host,
// `disabled` is not one of Vue's special boolean attributes, so binding it
// on the LightTooltip stub's <div> renders the literal "true"/"false".
headerTooltipsDisabled: () => [...host.querySelectorAll('[data-grid-column-index] [data-stub="LightTooltip"]')].map((node) => node.getAttribute("disabled") === "true"),
destroy() {
app.unmount();
host.remove();
},
};
}
it("follows the showColumnHeaderTooltips preference", async () => {
const grid = mountDataGrid();
await nextTick();
expect(settingsMock.store.editorSettings.showColumnHeaderTooltips).toBe(true);
expect(grid.headerTooltipsDisabled()).toEqual([false, false]);
settingsMock.store.editorSettings.showColumnHeaderTooltips = false;
await nextTick();
expect(grid.headerTooltipsDisabled()).toEqual([true, true]);
settingsMock.store.editorSettings.showColumnHeaderTooltips = true;
await nextTick();
expect(grid.headerTooltipsDisabled()).toEqual([false, false]);
grid.destroy();
});
});