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。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(structure): ensure consistent row heights across data types in table structure editor (#13659) (#13699)
lxk9550a9eee0e2ace
diff --git a/apps/desktop/src/components/structure/TableStructureEditor.vue b/apps/desktop/src/components/structure/TableStructureEditor.vueindex 74f8c2906e..621ded03f0 100644--- a/apps/desktop/src/components/structure/TableStructureEditor.vue+++ b/apps/desktop/src/components/structure/TableStructureEditor.vue@@ -1455,6 +1455,7 @@ const structureDensityStyle = computed(() => {"--structure-cell-py": `${metric.cellPaddingY}px`,"--structure-header-py": `${metric.headerPaddingY}px`,"--structure-control-height": `${metric.controlHeight}px`,+ "--structure-column-row-height": `${metric.controlHeight + metric.cellPaddingY * 2 + 1}px`,"--structure-control-px": `${metric.controlPaddingX}px`,"--structure-icon-size": `${metric.iconSize}px`,"--structure-checkbox-size": `${metric.checkboxSize}px`,@@ -8639,7 +8640,10 @@ watch(<RecycleScrollerref="columnsScrollerRef"class="structure-column-virtual-scroller structure-table-scroller h-full overflow-auto"- :style="{ '--structure-column-table-width': columnTableWidth + 'px' }"+ :style="{+ '--structure-column-table-width': columnTableWidth + 'px',+ '--structure-column-row-height': structureColumnRowHeight + 'px',+ }":items="columnVirtualRows":item-size="columnVirtualItemSize":min-item-size="structureColumnRowHeight"@@ -8692,8 +8696,8 @@ watch(</thead></table></template>- <template #default="{ item: { column, index }, active }">- <table class="structure-column-virtual-row-table border-separate border-spacing-0 text-[length:var(--structure-font-size)] leading-[var(--structure-line-height)]">+ <template #default="{ item: { column, index, size }, active }">+ <table class="structure-column-virtual-row-table border-separate border-spacing-0 text-[length:var(--structure-font-size)] leading-[var(--structure-line-height)]" :style="{ height: (size || structureColumnRowHeight) + 'px' }"><colgroup><col v-for="(width, columnIndex) in visibleColWidths" :key="columnIndex" :style="{ width: width + 'px' }" /></colgroup>@@ -8704,6 +8708,7 @@ watch(:data-column-row-index="index":data-column-id="column.id":data-column-row-active="active ? 'true' : 'false'"+ :style="{ height: (size || structureColumnRowHeight) + 'px' }"@mousedown="onColumnRowMouseDown($event)"@click="onColumnRowClick(column, $event)"@focusin="onColumnRowActivate(column)"@@ -8866,7 +8871,8 @@ watch(<SelectTrigger:aria-label="t('structureEditor.lengthUnit')":title="t('structureEditor.lengthUnit')"- class="structure-grid-control h-[var(--structure-control-height)] w-16 shrink-0 rounded-[6px] px-[var(--structure-control-px)] font-mono text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25"+ size="sm"+ class="structure-grid-control h-[var(--structure-control-height)] w-16 shrink-0 rounded-[6px] px-[var(--structure-control-px)] py-0 font-mono text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25"><SelectValue :placeholder="t('structureEditor.unitPlaceholder')" /></SelectTrigger>@@ -9127,7 +9133,7 @@ watch(}">- <SelectTrigger class="structure-grid-control h-[var(--structure-control-height)] w-28 rounded-[6px] px-[var(--structure-control-px)] text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25">+ <SelectTrigger size="sm" class="structure-grid-control h-[var(--structure-control-height)] w-28 rounded-[6px] px-[var(--structure-control-px)] py-0 text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25"><SelectValue /></SelectTrigger><SelectContent>@@ -9290,7 +9296,10 @@ watch(</td><td :class="structureCellClass"><Select v-if="indexTypeOptions.length > 0" :model-value="index.indexType || 'BTREE'" :disabled="!canEditIndexDraft(index)" data-index-type @update:model-value="(value: unknown) => onIndexTypeChange(index, value)">- <SelectTrigger class="structure-grid-control h-[var(--structure-control-height)] w-full rounded-[6px] px-[var(--structure-control-px)] font-mono text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25">+ <SelectTrigger+ size="sm"+ class="structure-grid-control h-[var(--structure-control-height)] w-full rounded-[6px] px-[var(--structure-control-px)] py-0 font-mono text-[length:var(--structure-font-size)] focus-visible:border-ring/50 focus-visible:ring-1 focus-visible:ring-ring/25"+ ><SelectValue /></SelectTrigger><SelectContent>@@ -10455,6 +10464,8 @@ watch(.structure-column-virtual-scroller :deep(.structure-column-virtual-row) {width: 100%;min-width: var(--structure-column-table-width);+ min-height: var(--structure-column-row-height);+ box-sizing: border-box;}.structure-column-virtual-scroller :deep(.structure-column-virtual-header-table),@@ -10464,6 +10475,22 @@ watch(width: 100%;min-width: var(--structure-column-table-width);table-layout: fixed;+ box-sizing: border-box;+}++.structure-column-virtual-scroller :deep(.structure-column-virtual-row-table) {+ height: 100%;+}++.structure-column-virtual-scroller :deep(.structure-column-virtual-row-table tr) {+ height: 100%;+ box-sizing: border-box;+}++.structure-column-virtual-scroller :deep(.structure-column-virtual-row-table td) {+ height: var(--structure-column-row-height);+ box-sizing: border-box;+ vertical-align: middle;}.structure-vertical-scrollbar {@@ -10528,12 +10555,25 @@ watch(/* Editable values behave like grid cells, not a row of independent pill controls. */.structure-edit-grid :deep(.structure-grid-control) {+ height: var(--structure-control-height);+ min-height: var(--structure-control-height);+ max-height: var(--structure-control-height);+ padding-top: 0;+ padding-bottom: 0;border-color: transparent;border-radius: 0;background-color: transparent;box-shadow: none;}+.structure-edit-grid :deep(.structure-grid-control[data-slot="select-trigger"]) {+ height: var(--structure-control-height);+ min-height: var(--structure-control-height);+ max-height: var(--structure-control-height);+ padding-top: 0;+ padding-bottom: 0;+}+.structure-edit-grid > tbody > tr > td:hover,.structure-edit-grid > tr > td:hover {background-color: color-mix(in oklab, var(--muted) 36%, transparent);diff --git a/apps/desktop/src/components/structure/__tests__/TableStructureEditor.rowHeight.spec.ts b/apps/desktop/src/components/structure/__tests__/TableStructureEditor.rowHeight.spec.tsnew file mode 100644index 0000000000..3fc63e92c0--- /dev/null+++ b/apps/desktop/src/components/structure/__tests__/TableStructureEditor.rowHeight.spec.ts@@ -0,0 +1,418 @@+// @vitest-environment happy-dom++import { createApp, nextTick, type App } from "vue";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";++const mocks = vi.hoisted(() => ({+ connection: {+ id: "structure-row-height-test",+ name: "Dameng",+ db_type: "dameng",+ driver_profile: "dameng",+ driver_label: "Dameng",+ },+ ensureConnected: vi.fn(),+ executeQuery: vi.fn(),+ listDataTypes: vi.fn(),+ buildTableStructureChangeSql: vi.fn(),+ executeBatch: vi.fn(),+ getTableOwner: vi.fn(),+ updateEditorSettings: vi.fn(),+ loadObjectDdl: vi.fn(),+ invalidateObjectDdl: vi.fn(),+ loadObjectMetadataFacet: vi.fn(),+ invalidateObjectMetadataCache: vi.fn(),+ invalidateTableMetadataCache: vi.fn(),+ toast: vi.fn(),+}));++vi.mock("vue-i18n", async (original) => ({ ...(await original<typeof import("vue-i18n")>()), useI18n: () => ({ t: (key: string) => key }) }));++vi.mock("@lucide/vue", async () => {+ const { defineComponent, h } = await import("vue");+ const Icon = defineComponent({ name: "Icon", setup: () => () => h("span") });+ return {+ AlertTriangle: Icon,+ Check: Icon,+ ChevronDown: Icon,+ ChevronLeft: Icon,+ ChevronRight: Icon,+ ChevronUp: Icon,+ ClipboardList: Icon,+ Copy: Icon,+ Database: Icon,+ Info: Icon,+ Keyboard: Icon,+ KeyRound: Icon,+ ListChevronsUpDown: Icon,+ Loader2: Icon,+ Maximize2: Icon,+ Pencil: Icon,+ Plus: Icon,+ RefreshCw: Icon,+ Rows3: Icon,+ Save: Icon,+ Search: Icon,+ Settings: Icon,+ SlidersHorizontal: Icon,+ Trash2: Icon,+ UserRound: Icon,+ X: Icon,+ };+});++vi.mock("@/components/ui/button", async () => {+ const { defineComponent, h } = await import("vue");+ return {+ Button: defineComponent({+ name: "Button",+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("button", attrs, slots.default?.()),+ }),+ };+});+vi.mock("@/components/ui/input", async () => {+ const { defineComponent, h } = await import("vue");+ return {+ Input: defineComponent({+ name: "Input",+ inheritAttrs: false,+ props: { modelValue: { type: [String, Number], default: "" } },+ emits: ["update:modelValue"],+ setup:+ (props, { attrs, emit }) =>+ () =>+ h("input", {+ ...attrs,+ value: props.modelValue,+ onInput: (event: Event) => emit("update:modelValue", (event.target as HTMLInputElement).value),+ }),+ }),+ };+});+vi.mock("@/components/ui/badge", async () => {+ const { defineComponent, h } = await import("vue");+ return {+ Badge: defineComponent({+ name: "Badge",+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("span", attrs, slots.default?.()),+ }),+ };+});+vi.mock("@/components/ui/tabs", async () => {+ const { defineComponent, h } = await import("vue");+ const Div = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("div", attrs, slots.default?.()),+ });+ const Button = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("button", attrs, slots.default?.()),+ });+ return { Tabs: Div, TabsContent: Div, TabsList: Div, TabsTrigger: Button };+});+vi.mock("@/components/ui/dropdown-menu", async () => {+ const { defineComponent, h } = await import("vue");+ const Div = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("div", attrs, slots.default?.()),+ });+ const Button = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("button", attrs, slots.default?.()),+ });+ return { DropdownMenu: Div, DropdownMenuCheckboxItem: Div, DropdownMenuContent: Div, DropdownMenuItem: Button, DropdownMenuTrigger: Div };+});+vi.mock("@/components/ui/popover", async () => {+ const { defineComponent, h } = await import("vue");+ const Div = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("div", attrs, slots.default?.()),+ });+ return { Popover: Div, PopoverContent: Div, PopoverTrigger: Div };+});+vi.mock("@/components/ui/tooltip", async () => {+ const { defineComponent, h } = await import("vue");+ const Div = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("div", attrs, slots.default?.()),+ });+ return { Tooltip: Div, TooltipContent: Div, TooltipTrigger: Div };+});+vi.mock("@/components/ui/searchable-select", async () => {+ const { defineComponent, h } = await import("vue");+ return {+ SearchableSelect: defineComponent({+ name: "SearchableSelect",+ inheritAttrs: false,+ props: {+ modelValue: { type: String, default: "" },+ options: { type: Array, default: () => [] },+ allowCustom: { type: Boolean, default: false },+ },+ emits: ["update:modelValue"],+ setup:+ (props, { attrs, emit }) =>+ () =>+ h("button", {+ ...attrs,+ type: "button",+ "data-searchable-select": "true",+ "data-model-value": props.modelValue,+ onClick: () => emit("update:modelValue", "custom"),+ }),+ }),+ };+});+vi.mock("@/components/ui/select", async () => {+ const { defineComponent, h } = await import("vue");+ const Div = defineComponent({+ inheritAttrs: false,+ setup:+ (_props, { attrs, slots }) =>+ () =>+ h("div", attrs, slots.default?.()),+ });+ const SelectTrigger = defineComponent({+ name: "SelectTrigger",+ inheritAttrs: false,+ props: {+ size: { type: String, default: "default" },+ },+ setup:+ (props, { attrs, slots }) =>+ () =>+ h("button", { ...attrs, "data-size": props.size, "data-slot": "select-trigger" }, slots.default?.()),+ });+ return { Select: Div, SelectContent: Div, SelectItem: Div, SelectTrigger, SelectValue: Div };+});++vi.mock("@/stores/connectionStore", () => ({+ useConnectionStore: () => ({+ ensureConnected: mocks.ensureConnected,+ connectionStateRevision: () => 0,+ isCurrentConnectionStateRevision: () => true,+ getConfig: (connectionId: string) => (connectionId === mocks.connection.id ? mocks.connection : undefined),+ }),+}));+vi.mock("@/stores/productionSafetyStore", () => ({ useProductionSafetyStore: () => ({ requestConfirmation: vi.fn() }) }));+vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({ tableStructureRefreshVersion: () => 0 }) }));+vi.mock("@/stores/historyStore", () => ({ useHistoryStore: () => ({ add: vi.fn() }) }));++let mockDensity = "compact";+vi.mock("@/stores/settingsStore", () => ({+ useSettingsStore: () => ({+ editorSettings: { structureEditorDensity: mockDensity, sqlFormatter: {}, tableColumnTemplateFields: [], generateSqlQuoteIdentifiers: true },+ updateEditorSettings: mocks.updateEditorSettings,+ }),+}));+vi.mock("@/composables/useTheme", () => ({ useTheme: () => ({ isDark: { value: false } }) }));+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: mocks.toast }) }));+vi.mock("@/lib/sql/sqlHighlighter", () => ({ createShikiSqlHighlighter: vi.fn(async () => (sql: string) => sql) }));+vi.mock("@/lib/metadata/objectDdlCache", () => ({+ loadObjectDdl: mocks.loadObjectDdl,+ invalidateObjectDdl: mocks.invalidateObjectDdl,+}));+vi.mock("@/lib/metadata/objectMetadataCache", () => ({ loadObjectMetadataFacet: mocks.loadObjectMetadataFacet, invalidateObjectMetadataCache: mocks.invalidateObjectMetadataCache }));+vi.mock("@/lib/metadata/tableMetadataCache", () => ({ invalidateTableMetadataCache: mocks.invalidateTableMetadataCache }));+vi.mock("@/lib/backend/api", () => ({+ executeQuery: mocks.executeQuery,+ listDataTypes: mocks.listDataTypes,+ buildTableStructureChangeSql: mocks.buildTableStructureChangeSql,+ executeBatch: mocks.executeBatch,+ getTableOwner: mocks.getTableOwner,+}));++import TableStructureEditor from "@/components/structure/TableStructureEditor.vue";++const mountedApps: App[] = [];++function draftWithColumns(columns: Array<{ name: string; dataType: string }>) {+ return {+ initialized: true,+ activeTab: "columns" as const,+ newTableName: "",+ tableComment: "",+ originalTableComment: "",+ columns: columns.map((col, index) => ({+ id: `existing:${col.name}`,+ name: col.name,+ dataType: col.dataType,+ isNullable: true,+ defaultValue: "",+ comment: "",+ isPrimaryKey: false,+ characterSet: "",+ collation: "",+ extra: {},+ original: {+ name: col.name,+ data_type: col.dataType,+ is_nullable: true,+ column_default: null,+ is_primary_key: false,+ extra: null,+ comment: null,+ },+ originalPosition: index,+ markedForDrop: false,+ })),+ indexes: [],+ foreignKeys: [],+ triggers: [],+ };+}++async function mountEditor(draft: ReturnType<typeof draftWithColumns>) {+ mocks.ensureConnected.mockResolvedValue(undefined);+ mocks.listDataTypes.mockResolvedValue([+ { name: "VARCHAR", full_type: "VARCHAR(255)" },+ { name: "TIMESTAMP", full_type: "TIMESTAMP" },+ { name: "TEXT", full_type: "TEXT" },+ ]);+ mocks.buildTableStructureChangeSql.mockResolvedValue({ statements: [], warnings: [] });++ const root = document.createElement("div");+ document.body.append(root);+ const app = createApp(TableStructureEditor, {+ connectionId: mocks.connection.id,+ database: "test",+ schema: "test",+ tableName: "mixed_types_table",+ draft,+ });+ mountedApps.push(app);+ app.mount(root);+ await nextTick();+ await Promise.resolve();+ await nextTick();+ return root;+}++beforeEach(() => {+ vi.clearAllMocks();+ mockDensity = "compact";+ mocks.connection.db_type = "dameng";+ mocks.connection.driver_profile = "dameng";+ mocks.getTableOwner.mockResolvedValue("dameng");+ mocks.loadObjectDdl.mockResolvedValue({ ddl: "CREATE TABLE mixed_types_table (del_flag VARCHAR(1) BYTE, create_time TIMESTAMP)", cacheStatus: "remote" });+ mocks.loadObjectMetadataFacet.mockImplementation(async (_options: unknown, facet: string) => {+ if (facet === "owner") return { value: "app_user", cacheStatus: "remote" };+ return { value: [], cacheStatus: "remote" };+ });+ mocks.executeBatch.mockResolvedValue({ affected_rows: 0 });+});++afterEach(() => {+ for (const app of mountedApps.splice(0)) app.unmount();+ document.body.innerHTML = "";+});++describe("TableStructureEditor row height consistency (#13659)", () => {+ it("applies --structure-column-row-height CSS variable and uniform row heights across mixed data types", async () => {+ const root = await mountEditor(+ draftWithColumns([+ { name: "del_flag", dataType: "VARCHAR(1) BYTE" },+ { name: "create_by", dataType: "VARCHAR(64) BYTE" },+ { name: "create_time", dataType: "TIMESTAMP" },+ { name: "remark", dataType: "TEXT" },+ ]),+ );++ // Root element should define --structure-column-row-height: 33px (24 control + 4*2 cellPaddingY + 1 border)+ const rootEl = root.querySelector("[data-structure-density='compact']") as HTMLElement;+ expect(rootEl).not.toBeNull();+ expect(rootEl.style.getPropertyValue("--structure-column-row-height")).toBe("33px");++ // RecycleScroller should carry --structure-column-row-height style+ const scroller = root.querySelector(".structure-column-virtual-scroller") as HTMLElement;+ expect(scroller).not.toBeNull();+ expect(scroller.style.getPropertyValue("--structure-column-row-height")).toBe("33px");++ // All row tables and tr elements must have uniform height matching the 33px slot+ const rowTables = root.querySelectorAll(".structure-column-virtual-row-table") as NodeListOf<HTMLElement>;+ expect(rowTables.length).toBeGreaterThan(0);+ for (const table of Array.from(rowTables)) {+ expect(table.style.height).toBe("33px");+ }++ const rowTrs = root.querySelectorAll(".structure-column-virtual-row-table tr[data-column-id]") as NodeListOf<HTMLElement>;+ expect(rowTrs.length).toBeGreaterThan(0);+ for (const tr of Array.from(rowTrs)) {+ expect(tr.style.height).toBe("33px");+ }++ // Length unit SelectTrigger in VARCHAR rows should have size="sm"+ const triggers = root.querySelectorAll("[data-slot='select-trigger']");+ expect(triggers.length).toBeGreaterThan(0);+ for (const trigger of Array.from(triggers)) {+ expect(trigger.getAttribute("data-size")).toBe("sm");+ }+ });++ it("updates --structure-column-row-height and row heights when density changes to standard", async () => {+ mockDensity = "standard";+ const root = await mountEditor(+ draftWithColumns([+ { name: "id", dataType: "BIGINT" },+ { name: "name", dataType: "VARCHAR(50)" },+ ]),+ );++ // Standard density: controlHeight 28 + cellPaddingY 5 * 2 + 1 border = 39px+ const rootEl = root.querySelector("[data-structure-density='standard']") as HTMLElement;+ expect(rootEl).not.toBeNull();+ expect(rootEl.style.getPropertyValue("--structure-column-row-height")).toBe("39px");++ const rowTables = root.querySelectorAll(".structure-column-virtual-row-table") as NodeListOf<HTMLElement>;+ for (const table of Array.from(rowTables)) {+ expect(table.style.height).toBe("39px");+ }+ });++ it("allocates extra height for Postgres geometry columns with variable geometry hint", async () => {+ mockDensity = "compact";+ mocks.connection.db_type = "postgres";+ mocks.connection.driver_profile = "postgres";+ mocks.getTableOwner.mockResolvedValue("postgres");+ const root = await mountEditor(+ draftWithColumns([+ { name: "id", dataType: "BIGINT" },+ { name: "geom", dataType: "geometry(,4326)" },+ ]),+ );++ const idRow = root.querySelector("tr[data-column-id='existing:id']") as HTMLElement;+ const geomRow = root.querySelector("tr[data-column-id='existing:geom']") as HTMLElement;+ expect(idRow).not.toBeNull();+ expect(geomRow).not.toBeNull();+ expect(idRow.style.height).toBe("33px");+ const geomHeight = parseInt(geomRow.style.height, 10);+ expect(geomHeight).toBeGreaterThan(33);+ });+});