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(desktop): constrain SQL preview dialog content
二丫讲梵bfaf8fa818eb
diff --git a/apps/desktop/src/components/admin/DatabaseUserAdmin.vue b/apps/desktop/src/components/admin/DatabaseUserAdmin.vueindex 2cce31ba4f..931cc4cc4f 100644--- a/apps/desktop/src/components/admin/DatabaseUserAdmin.vue+++ b/apps/desktop/src/components/admin/DatabaseUserAdmin.vue@@ -1042,27 +1042,29 @@ onMounted(loadUsers);</Dialog><Dialog v-model:open="sqlDialogOpen">- <DialogContent class="max-w-2xl">+ <DialogContent class="max-w-2xl grid-rows-[auto_minmax(0,1fr)_auto]"><DialogHeader><DialogTitle class="flex items-center gap-2"><AlertTriangle v-if="pendingDanger" class="h-4 w-4 text-destructive" />{{ t("userAdmin.sqlPreview") }}</DialogTitle></DialogHeader>- <pre class="max-h-[50vh] min-h-44 overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 font-mono text-xs leading-5" v-html="highlightedPendingSql" />- <div v-if="pendingResults.length > 0" class="grid gap-2 rounded-md border p-3">- <div class="text-xs font-semibold" :class="pendingStatus === 'success' ? 'text-green-600' : pendingStatus === 'partial' ? 'text-amber-600' : 'text-destructive'">- {{ t(pendingStatus === "success" ? "userAdmin.resultSuccess" : pendingStatus === "partial" ? "userAdmin.resultPartial" : "userAdmin.resultFailed") }}- </div>- <div v-for="result in pendingResults" :key="result.step.id" class="flex items-start gap-2 text-xs">- <Check v-if="result.status === 'success'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600" />- <AlertTriangle v-else-if="result.status === 'failed'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive" />- <span v-else class="mt-1 h-2 w-2 shrink-0 rounded-full bg-muted-foreground" />- <span class="min-w-0">- <span class="block">{{ authorizationStepLabel(result) }}</span>- <span v-if="result.message" class="mt-0.5 block break-all text-destructive">{{ result.message }}</span>- <span v-else-if="result.status === 'skipped'" class="mt-0.5 block text-muted-foreground">{{ t("userAdmin.stepSkipped") }}</span>- </span>+ <div class="grid min-h-0 max-h-full min-w-0 gap-3 overflow-hidden" :class="pendingResults.length > 0 ? 'h-[70vh] grid-rows-[minmax(0,1fr)_minmax(0,1fr)]' : 'h-[50vh] grid-rows-[minmax(0,1fr)]'">+ <pre class="min-h-0 min-w-0 overflow-auto overscroll-contain whitespace-pre-wrap rounded-md border bg-muted/30 p-3 font-mono text-xs leading-5" v-html="highlightedPendingSql" />+ <div v-if="pendingResults.length > 0" class="grid min-h-0 min-w-0 content-start gap-2 overflow-y-auto overscroll-contain rounded-md border p-3">+ <div class="text-xs font-semibold" :class="pendingStatus === 'success' ? 'text-green-600' : pendingStatus === 'partial' ? 'text-amber-600' : 'text-destructive'">+ {{ t(pendingStatus === "success" ? "userAdmin.resultSuccess" : pendingStatus === "partial" ? "userAdmin.resultPartial" : "userAdmin.resultFailed") }}+ </div>+ <div v-for="result in pendingResults" :key="result.step.id" class="flex items-start gap-2 text-xs">+ <Check v-if="result.status === 'success'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600" />+ <AlertTriangle v-else-if="result.status === 'failed'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive" />+ <span v-else class="mt-1 h-2 w-2 shrink-0 rounded-full bg-muted-foreground" />+ <span class="min-w-0">+ <span class="block">{{ authorizationStepLabel(result) }}</span>+ <span v-if="result.message" class="mt-0.5 block break-all text-destructive">{{ result.message }}</span>+ <span v-else-if="result.status === 'skipped'" class="mt-0.5 block text-muted-foreground">{{ t("userAdmin.stepSkipped") }}</span>+ </span>+ </div></div></div><DialogFooter>diff --git a/apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vue b/apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vueindex 084de2cedd..9837f64694 100644--- a/apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vue+++ b/apps/desktop/src/components/sidebar/SidebarTreeItemDialogs.vue@@ -600,21 +600,23 @@ watch(</Dialog><Dialog :open="showCreateDatabasePreviewDialog" @update:open="updateCreateDatabasePreviewDialog">- <DialogContent class="sm:max-w-[720px]">+ <DialogContent class="sm:max-w-[720px] grid-rows-[auto_minmax(0,1fr)_auto]"><DialogHeader><DialogTitle>{{ t("contextMenu.createDatabaseSqlPreview") }}</DialogTitle></DialogHeader>- <pre class="max-h-[48vh] min-h-44 overflow-auto whitespace-pre-wrap rounded-md border bg-muted/30 p-3 font-mono text-xs leading-5" v-html="highlight(createDatabasePreviewSql)" />- <div v-if="createDatabaseAuthorizationResults.length > 0" class="grid gap-2 rounded-md border p-3">- <div v-for="result in createDatabaseAuthorizationResults" :key="result.step.id" class="flex items-start gap-2 text-xs">- <Check v-if="result.status === 'success'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600" />- <AlertTriangle v-else-if="result.status === 'failed'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive" />- <span v-else class="mt-1 h-2 w-2 shrink-0 rounded-full bg-muted-foreground" />- <span class="min-w-0">- <span class="block">{{ createDatabaseAuthorizationStepLabel(result) }}</span>- <span v-if="result.message" class="mt-0.5 block break-all text-destructive">{{ result.message }}</span>- <span v-else-if="result.status === 'skipped'" class="mt-0.5 block text-muted-foreground">{{ t("contextMenu.createDatabaseStepSkipped") }}</span>- </span>+ <div class="grid min-h-0 max-h-full min-w-0 gap-3 overflow-hidden" :class="createDatabaseAuthorizationResults.length > 0 ? 'h-[70vh] grid-rows-[minmax(0,1fr)_minmax(0,1fr)]' : 'h-[48vh] grid-rows-[minmax(0,1fr)]'">+ <pre class="min-h-0 min-w-0 overflow-auto overscroll-contain whitespace-pre-wrap rounded-md border bg-muted/30 p-3 font-mono text-xs leading-5" v-html="highlight(createDatabasePreviewSql)" />+ <div v-if="createDatabaseAuthorizationResults.length > 0" class="grid min-h-0 min-w-0 content-start gap-2 overflow-y-auto overscroll-contain rounded-md border p-3">+ <div v-for="result in createDatabaseAuthorizationResults" :key="result.step.id" class="flex items-start gap-2 text-xs">+ <Check v-if="result.status === 'success'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-green-600" />+ <AlertTriangle v-else-if="result.status === 'failed'" class="mt-0.5 h-3.5 w-3.5 shrink-0 text-destructive" />+ <span v-else class="mt-1 h-2 w-2 shrink-0 rounded-full bg-muted-foreground" />+ <span class="min-w-0">+ <span class="block">{{ createDatabaseAuthorizationStepLabel(result) }}</span>+ <span v-if="result.message" class="mt-0.5 block break-all text-destructive">{{ result.message }}</span>+ <span v-else-if="result.status === 'skipped'" class="mt-0.5 block text-muted-foreground">{{ t("contextMenu.createDatabaseStepSkipped") }}</span>+ </span>+ </div></div></div><DialogFooter>diff --git a/packages/app-tests/sqlPreviewDialogLayout.test.ts b/packages/app-tests/sqlPreviewDialogLayout.test.tsnew file mode 100644index 0000000000..f4a95c304b--- /dev/null+++ b/packages/app-tests/sqlPreviewDialogLayout.test.ts@@ -0,0 +1,120 @@+// @vitest-environment happy-dom++import { readFileSync } from "node:fs";+import { resolve } from "node:path";+import { afterEach, describe, expect, it, vi } from "vitest";+import * as Vue from "vue";+import { compileTemplate } from "vue/compiler-sfc";+import { AlertTriangle, Check, Loader2 } from "@lucide/vue";+import { Button } from "@/components/ui/button";+import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";++const owners = [+ { name: "user authorization", path: "admin/DatabaseUserAdmin.vue", marker: '<Dialog v-model:open="sqlDialogOpen">', previewHeight: "50vh" },+ { name: "database authorization", path: "sidebar/SidebarTreeItemDialogs.vue", marker: '<Dialog :open="showCreateDatabasePreviewDialog"', previewHeight: "48vh" },+];+const mountedApps: Vue.App[] = [];++afterEach(() => {+ for (const app of mountedApps.splice(0)) app.unmount();+ document.body.innerHTML = "";+});++describe.each(owners)("$name SQL preview layout", (owner) => {+ async function mountDialog() {+ const filename = resolve(import.meta.dirname, "../../apps/desktop/src/components", owner.path);+ const source = readFileSync(filename, "utf8");+ const start = source.indexOf(owner.marker);+ expect(start).toBeGreaterThanOrEqual(0);+ const template = source.slice(start, source.indexOf("</Dialog>", start) + "</Dialog>".length);+ const compiled = compileTemplate({ source: template, filename, id: owner.name, compilerOptions: { mode: "function" } });+ expect(compiled.errors).toEqual([]);+ const results: { step: { id: string }; status: string; message?: string }[] = [];+ const state = Vue.reactive({+ sqlDialogOpen: true,+ showCreateDatabasePreviewDialog: true,+ pendingResults: results,+ createDatabaseAuthorizationResults: results,+ pendingStatus: "partial",+ pendingDanger: true,+ applying: false,+ createDatabaseAuthorizationApplying: false,+ highlightedPendingSql: "SELECT 1;\n".repeat(100),+ createDatabasePreviewSql: "SELECT 1;\n".repeat(100),+ highlight: (value: string) => value,+ t: (key: string) => key,+ authorizationStepLabel: (result: (typeof results)[number]) => result.step.id,+ createDatabaseAuthorizationStepLabel: (result: (typeof results)[number]) => result.step.id,+ applyPendingSql: vi.fn(),+ applyCreateDatabaseAuthorizationPlan: vi.fn(),+ closeCreateDatabaseResult: vi.fn(),+ updateCreateDatabasePreviewDialog: vi.fn(),+ });+ const app = Vue.createApp({+ components: { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle, Button, AlertTriangle, Check, Loader2 },+ setup: () => state,+ render: new Function("Vue", compiled.code)(Vue),+ });+ mountedApps.push(app);+ app.mount(document.body.appendChild(document.createElement("div")));+ await Vue.nextTick();+ const dialog = document.querySelector<HTMLElement>('[data-slot="dialog-content"]')!;+ expect(dialog).not.toBeNull();+ return { state, dialog };+ }++ it("caps the preferred content height to the remaining grid track before and after execution", async () => {+ const { state, dialog } = await mountDialog();+ expect(dialog.classList.contains("max-h-[calc(var(--dbx-viewport-height)-2rem)]")).toBe(true);+ expect(dialog.classList.contains("grid-rows-[auto_minmax(0,1fr)_auto]")).toBe(true);+ const sql = dialog.querySelector("pre")!;+ const middle = sql.parentElement!;+ expect(middle.classList.contains("grid-rows-[minmax(0,1fr)]")).toBe(true);+ expect(middle.classList.contains(`h-[${owner.previewHeight}]`)).toBe(true);+ expect(middle.classList.contains("max-h-full")).toBe(true);+ state.pendingResults.push({ step: { id: "created" }, status: "success" }, { step: { id: "grant" }, status: "failed", message: "permission denied".repeat(100) }, { step: { id: "skipped" }, status: "skipped" });+ await Vue.nextTick();+ expect(middle.classList.contains("h-[70vh]")).toBe(true);+ expect(middle.classList.contains("grid-rows-[minmax(0,1fr)_minmax(0,1fr)]")).toBe(true);+ expect(middle.classList.contains("max-h-full")).toBe(true);+ const resultPane = middle.children[1] as HTMLElement;+ for (const pane of [sql, resultPane]) {+ expect(pane.classList.contains("min-h-0")).toBe(true);+ expect(pane.classList.contains("min-w-0")).toBe(true);+ expect(pane.classList.contains("overscroll-contain")).toBe(true);+ }+ expect(sql.classList.contains("overflow-auto")).toBe(true);+ expect(resultPane.classList.contains("overflow-y-auto")).toBe(true);+ expect(resultPane.textContent).toContain("permission denied");+ expect(resultPane.textContent).toContain(owner.name === "user authorization" ? "userAdmin.stepSkipped" : "contextMenu.createDatabaseStepSkipped");+ expect(dialog.querySelector('[data-slot="dialog-header"]')).not.toBeNull();+ expect(dialog.querySelector('[data-slot="dialog-footer"]')!.querySelectorAll("button")).toHaveLength(1);+ state.pendingResults.splice(0);+ await Vue.nextTick();+ expect(middle.classList.contains(`h-[${owner.previewHeight}]`)).toBe(true);+ expect(middle.children).toHaveLength(1);+ });++ it("preserves execution guards and the result close action", async () => {+ const { state, dialog } = await mountDialog();+ const footer = dialog.querySelector('[data-slot="dialog-footer"]')!;+ const apply = footer.querySelectorAll("button")[1];+ state.applying = true;+ state.createDatabaseAuthorizationApplying = true;+ await Vue.nextTick();+ expect(apply.disabled).toBe(true);+ apply.click();+ expect(state.applyPendingSql).not.toHaveBeenCalled();+ expect(state.applyCreateDatabaseAuthorizationPlan).not.toHaveBeenCalled();+ state.applying = false;+ state.createDatabaseAuthorizationApplying = false;+ await Vue.nextTick();+ apply.click();+ expect(owner.name === "user authorization" ? state.applyPendingSql : state.applyCreateDatabaseAuthorizationPlan).toHaveBeenCalledOnce();+ state.pendingResults.push({ step: { id: "failed" }, status: "failed", message: "execution failed" });+ await Vue.nextTick();+ footer.querySelector("button")!.click();+ if (owner.name === "user authorization") expect(state.sqlDialogOpen).toBe(false);+ else expect(state.closeCreateDatabaseResult).toHaveBeenCalledOnce();+ });+});