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(sql-file): keep the execution progress area in view
OkaneGaif75deba175d2
diff --git a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.tsindex a68e535b27..45551e4197 100644--- a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts+++ b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.retry.spec.ts@@ -1272,3 +1272,77 @@ describe("SqlFileExecutionDialog closeOnSuccess option (#12891)", () => {expect(onOpenChange).not.toHaveBeenCalled();});});++describe("SqlFileExecutionDialog progress visibility", () => {+ // The scrollable body has no layout in happy-dom, so its metrics are+ // stubbed to observe the scroll position the dialog keeps the progress+ // area at.+ function stubScrollBody() {+ const element = root!.querySelector<HTMLElement>('[data-testid="sql-file-scroll-body"]');+ expect(element).not.toBeNull();+ const scrollTopValues: number[] = [];+ let currentScrollTop = 0;+ Object.defineProperty(element!, "scrollHeight", { configurable: true, value: 1000 });+ Object.defineProperty(element!, "clientHeight", { configurable: true, value: 400 });+ Object.defineProperty(element!, "scrollTop", {+ configurable: true,+ get: () => currentScrollTop,+ set: (value: number) => {+ currentScrollTop = value;+ scrollTopValues.push(value);+ },+ });+ return { element: element!, scrollTopValues };+ }++ it("scrolls the progress area into view when an execution starts", async () => {+ await mountReadyDialog();+ const { scrollTopValues } = stubScrollBody();++ mocks.executeSqlFiles.mockImplementationOnce(async (request: { executionId: string }) => {+ mocks.progressHandler?.(progress(request.executionId, "running"));+ });+ findButton("sqlFile.execute").click();++ await vi.waitFor(() => expect(scrollTopValues.length).toBeGreaterThan(0));+ expect(scrollTopValues[scrollTopValues.length - 1]).toBe(1000);+ });++ it("keeps the progress area in view while the execution reports progress", async () => {+ await mountReadyDialog();+ const { scrollTopValues } = stubScrollBody();++ const gate = deferred();+ mocks.executeSqlFiles.mockImplementationOnce(() => gate.promise);+ findButton("sqlFile.execute").click();+ await vi.waitFor(() => expect(scrollTopValues.length).toBeGreaterThan(0));+ const afterStart = scrollTopValues.length;++ mocks.progressHandler?.(progress("run-1", "statementDone", { statementIndex: 1, successCount: 1 }));+ await vi.waitFor(() => expect(scrollTopValues.length).toBeGreaterThan(afterStart));++ expect(scrollTopValues[scrollTopValues.length - 1]).toBe(1000);+ gate.resolve();+ });++ it("leaves the scroll position to the user once they scroll up", async () => {+ await mountReadyDialog();+ const { element, scrollTopValues } = stubScrollBody();++ const gate = deferred();+ mocks.executeSqlFiles.mockImplementationOnce(() => gate.promise);+ findButton("sqlFile.execute").click();+ await vi.waitFor(() => expect(scrollTopValues.length).toBeGreaterThan(0));++ element.scrollTop = 120;+ element.dispatchEvent(new Event("scroll"));+ const afterUserScroll = scrollTopValues.length;++ mocks.progressHandler?.(progress("run-1", "statementDone", { statementIndex: 1, successCount: 1 }));+ await nextTick();+ await nextTick();++ expect(scrollTopValues.length).toBe(afterUserScroll);+ gate.resolve();+ });+});diff --git a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vueindex 00c67c53d4..1506c46017 100644--- a/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue+++ b/apps/desktop/src/components/sql-file/SqlFileExecutionDialog.vue@@ -43,6 +43,7 @@ import { activeTabExternalSqlFileTarget, rememberExternalSqlFileTarget, resolveEimport type { SqlFileEncoding } from "@/lib/backend/tauri";import { TABLE_IMPORT_ENCODING_OPTIONS } from "@/lib/table/tableImport";import { isSqlFilePath } from "@/lib/sql/sqlFileOpen";+import { isScrolledToBottom } from "./sqlFileProgressScroll";import { buildDisplayFileNames, tooltipText as computeTooltipText } from "./sqlFilePreviewLabel";import { parseSqlFilePathInput } from "./sqlFilePathInput";import { orderConnectionsForSidebarDisplay } from "@/lib/sidebar/connectionListSort";@@ -173,6 +174,50 @@ const refreshedTarget = ref(false);const DEFAULT_WEB_SQL_FILE_BYTES = 200 * 1024 * 1024;const webSqlFileUploadMaxBytes = ref(DEFAULT_WEB_SQL_FILE_BYTES);+// The scrollable body renders the progress block as its last child, so the+// progress area starts below the fold once a file is selected. Execution+// scrolls it into view on start and keeps it in view while the user stays at+// the bottom of the body; scrolling up hands the scroll position back to the+// user instead of fighting them.+const scrollBodyRef = ref<HTMLElement | null>(null);+let pinnedToBottom = true;++function scrollBodyToBottom() {+ const element = scrollBodyRef.value;+ if (!element) return;+ element.scrollTop = element.scrollHeight;+}++function handleScrollBodyScroll() {+ const element = scrollBodyRef.value;+ if (!element) return;+ pinnedToBottom = isScrolledToBottom(element);+}++// Starting an execution reveals the progress area for the first time, so jump+// straight to it instead of leaving the user to scroll down by hand.+watch(+ running,+ (isRunning) => {+ if (!isRunning) return;+ pinnedToBottom = true;+ scrollBodyToBottom();+ },+ { flush: "post" },+);++// The progress block grows while it runs (byte progress, per-file summary,+// failure details), so keep it in view as long as the user has not scrolled+// away from the bottom.+watch(+ [progress, running],+ () => {+ if (!pinnedToBottom) return;+ scrollBodyToBottom();+ },+ { flush: "post" },+);+// The web server caps SQL file uploads via DBX_SQL_FILE_UPLOAD_MAX_MB; fetch the// effective limit once so the client-side pre-check matches the server rule.onMounted(async () => {@@ -1011,7 +1056,7 @@ watch(</DialogHeader><!-- Keep terminal actions reachable while long previews and errors scroll inside the viewport. -->- <div class="grid min-h-0 min-w-0 flex-1 gap-4 overflow-y-auto py-3">+ <div ref="scrollBodyRef" data-testid="sql-file-scroll-body" class="grid min-h-0 min-w-0 flex-1 gap-4 overflow-y-auto py-3" @scroll="handleScrollBodyScroll"><div class="min-w-0 space-y-3"><div class="text-xs font-medium text-muted-foreground uppercase tracking-wider">{{ t("sqlFile.file") }}diff --git a/apps/desktop/src/components/sql-file/sqlFileProgressScroll.spec.ts b/apps/desktop/src/components/sql-file/sqlFileProgressScroll.spec.tsnew file mode 100644index 0000000000..bc45845c11--- /dev/null+++ b/apps/desktop/src/components/sql-file/sqlFileProgressScroll.spec.ts@@ -0,0 +1,34 @@+import { describe, expect, it } from "vitest";+import { BOTTOM_STICK_THRESHOLD_PX, isScrolledToBottom } from "./sqlFileProgressScroll";++describe("isScrolledToBottom", () => {+ it("reports a body that is exactly at its bottom", () => {+ expect(isScrolledToBottom({ scrollTop: 600, scrollHeight: 1000, clientHeight: 400 })).toBe(true);+ });++ it("reports a body that is still within the threshold of the bottom", () => {+ expect(isScrolledToBottom({ scrollTop: 600 - BOTTOM_STICK_THRESHOLD_PX, scrollHeight: 1000, clientHeight: 400 })).toBe(true);+ });++ it("reports a body that was scrolled up", () => {+ expect(isScrolledToBottom({ scrollTop: 200, scrollHeight: 1000, clientHeight: 400 })).toBe(false);+ });++ it("treats a body whose content fits as being at the bottom", () => {+ expect(isScrolledToBottom({ scrollTop: 0, scrollHeight: 300, clientHeight: 400 })).toBe(true);+ });++ it("ignores a negative scroll offset produced by overscroll", () => {+ expect(isScrolledToBottom({ scrollTop: -30, scrollHeight: 1000, clientHeight: 400 })).toBe(false);+ });++ it("rejects metrics that are not finite numbers", () => {+ expect(isScrolledToBottom({ scrollTop: Number.NaN, scrollHeight: 1000, clientHeight: 400 })).toBe(false);+ expect(isScrolledToBottom({ scrollTop: 0, scrollHeight: Number.POSITIVE_INFINITY, clientHeight: 400 })).toBe(false);+ });++ it("honours a custom threshold", () => {+ expect(isScrolledToBottom({ scrollTop: 500, scrollHeight: 1000, clientHeight: 400 }, 10)).toBe(false);+ expect(isScrolledToBottom({ scrollTop: 500, scrollHeight: 1000, clientHeight: 400 }, 100)).toBe(true);+ });+});diff --git a/apps/desktop/src/components/sql-file/sqlFileProgressScroll.ts b/apps/desktop/src/components/sql-file/sqlFileProgressScroll.tsnew file mode 100644index 0000000000..54dbbd257f--- /dev/null+++ b/apps/desktop/src/components/sql-file/sqlFileProgressScroll.ts@@ -0,0 +1,27 @@+/**+ * The "执行 SQL 文件" dialog renders its progress block as the last child of+ * the scrollable body, so the progress area starts below the fold once a file+ * is selected. Execution scrolls that area into view and keeps it visible+ * while the user works at the bottom of the body; these helpers describe when+ * the body still counts as "at the bottom" so the behaviour stays testable+ * without a layout engine.+ */++/** Slack (px) that still counts as the bottom of the scrollable body. */+export const BOTTOM_STICK_THRESHOLD_PX = 24;++export interface ScrollPosition {+ scrollTop: number;+ scrollHeight: number;+ clientHeight: number;+}++/**+ * Whether the scrollable body sits at (or within a few pixels of) its bottom.+ * A body whose content fits entirely is always at its bottom.+ */+export function isScrolledToBottom({ scrollTop, scrollHeight, clientHeight }: ScrollPosition, threshold: number = BOTTOM_STICK_THRESHOLD_PX): boolean {+ if (!Number.isFinite(scrollTop) || !Number.isFinite(scrollHeight) || !Number.isFinite(clientHeight)) return false;+ const remaining = scrollHeight - Math.max(0, scrollTop) - clientHeight;+ return remaining <= threshold;+}