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
feat(query): open the summary view when a batch run starts (#13017)
弈秋fb56fb6a119b
diff --git a/apps/desktop/src/components/layout/ContentArea.vue b/apps/desktop/src/components/layout/ContentArea.vueindex 9020964285..1fd2bb466b 100644--- a/apps/desktop/src/components/layout/ContentArea.vue+++ b/apps/desktop/src/components/layout/ContentArea.vue@@ -1156,12 +1156,23 @@ watch();watch(- () => [props.activeTab.id, props.activeTab.result, props.activeTab.results, props.activeTab.isExecuting, props.activeOutputView] as const,+ () => [props.activeTab.id, props.activeTab.result, props.activeTab.results, props.activeTab.isExecuting, props.activeTab.batchSqlExecution, props.activeOutputView] as const,() => {// The output view belongs to the shared result surface. An editor-only// surface (a background group's editor) must never redirect the global// view when its own tab finishes executing.if (props.editorOnly) return;+ // A batch run reports its progress statement by statement, and only the+ // summary view shows that, so a run of several statements opens there+ // instead of on the first statement's grid. The switch is recorded against+ // the run it happened in: a user who picks another view mid-run keeps it,+ // and the next run switches again.+ const batchExecution = props.activeTab.batchSqlExecution;+ if (batchExecution && batchExecution.finishedAt === undefined && batchExecution.total > 1 && props.activeOutputView === "result" && props.activeTab.uiState?.batchSummaryExecutionId !== batchExecution.executionId) {+ queryStore.updateTabUiState(props.activeTab.id, { activeOutputView: "summary", batchSummaryExecutionId: batchExecution.executionId });+ emit("update:activeOutputView", props.activeTab.id, "summary");+ return;+ }if (props.activeTab.isExecuting) return;if (props.activeOutputView === "graph" && !canShowGraphOutput.value) {emit("update:activeOutputView", props.activeTab.id, "result");diff --git a/apps/desktop/src/components/layout/__tests__/ContentArea.batchSummary.spec.ts b/apps/desktop/src/components/layout/__tests__/ContentArea.batchSummary.spec.tsnew file mode 100644index 0000000000..e79b9b7299--- /dev/null+++ b/apps/desktop/src/components/layout/__tests__/ContentArea.batchSummary.spec.ts@@ -0,0 +1,133 @@+// @vitest-environment happy-dom+import { createApp, defineComponent, h, nextTick, reactive } from "vue";+import { createPinia, setActivePinia } from "pinia";+import { createI18n } from "vue-i18n";+import { afterEach, describe, expect, it, vi } from "vitest";+import type { BatchSqlExecution, QueryResult, QueryTab, TabOutputView } from "@/types/database";++vi.mock("@/components/editor/QueryEditor.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/transfer/QueryResultTransferDialog.vue", () => ({ __esModule: true, default: { render: () => null } }));+vi.mock("@/components/grid/DataGrid.vue", () => ({ __esModule: true, default: { render: () => h("div", { "data-test": "data-grid" }) } }));++import ContentArea from "../ContentArea.vue";+import { useConnectionStore } from "@/stores/connectionStore";+import { useQueryStore } from "@/stores/queryStore";++const cleanups: Array<() => void> = [];+afterEach(() => {+ cleanups.splice(0).forEach((cleanup) => cleanup());+ document.body.replaceChildren();+ window.localStorage?.clear();+});++function batch(executionId: string, total: number, finishedAt?: number): BatchSqlExecution {+ return {+ executionId,+ submittedSql: "SELECT 1; SELECT 2;",+ editorFingerprint: "fp",+ sourceOffset: 0,+ completed: 0,+ total,+ startedAt: Date.now(),+ finishedAt,+ items: Array.from({ length: total }, (_, statementIndex) => ({ statementIndex, sql: `SELECT ${statementIndex + 1}`, from: 0, to: 0, status: statementIndex === 0 ? "running" : "pending" })),+ };+}++async function mountTab(options: { batch?: BatchSqlExecution; isExecuting?: boolean; results?: QueryResult[] }) {+ const pinia = createPinia();+ setActivePinia(pinia);+ const connection = { id: "mysql", name: "MySQL", db_type: "mysql" as const, host: "localhost", port: 3306, username: "", password: "" };+ useConnectionStore().connections = [connection];+ const results = options.results ?? [];+ const tab = reactive<QueryTab>({+ id: "query",+ title: "Query",+ connectionId: connection.id,+ database: "app",+ mode: "query",+ sql: "SELECT 1; SELECT 2;",+ isExecuting: options.isExecuting ?? true,+ results,+ result: results[0],+ activeResultIndex: 0,+ batchSqlExecution: options.batch,+ });+ useQueryStore().tabs.push(tab);+ const state = reactive({ view: "result" as TabOutputView });+ const host = document.createElement("div");+ document.body.appendChild(host);+ const app = createApp(+ defineComponent({+ setup: () => () =>+ h(ContentArea, {+ activeTab: tab,+ activeConnection: connection,+ activeOutputView: state.view,+ executableSql: "",+ formatSqlRequest: null,+ compressSqlRequest: null,+ selectedSql: "",+ cursorPos: 0,+ resultOnly: true,+ blockDangerousRedisCommands: false,+ "onUpdate:activeOutputView": (_tabId: string, view: string) => {+ state.view = view as TabOutputView;+ },+ }),+ }),+ );+ app.use(pinia);+ app.use(createI18n({ legacy: false, locale: "en", messages: { en: { tabs: { resultN: "Result {n}", allResults: "All results ({count})" } } }, missingWarn: false, fallbackWarn: false }));+ app.mount(host);+ cleanups.push(() => app.unmount());+ await nextTick();+ await nextTick();+ return { host, state, tab };+}++describe("batch execution output view", () => {+ it("opens the summary while a multi-statement run is in progress", async () => {+ const { state, tab } = await mountTab({ batch: batch("run-1", 3) });++ expect(state.view).toBe("summary");+ expect(useQueryStore().tabs.find((candidate) => candidate.id === tab.id)?.uiState?.batchSummaryExecutionId).toBe("run-1");+ });++ it("keeps the view the user picks during that run", async () => {+ const { state, tab } = await mountTab({ batch: batch("run-1", 3) });+ expect(state.view).toBe("summary");++ state.view = "result";+ await nextTick();+ await nextTick();++ expect(state.view).toBe("result");+ expect(useQueryStore().tabs.find((candidate) => candidate.id === tab.id)?.uiState?.batchSummaryExecutionId).toBe("run-1");+ });++ it("opens the summary again for the next run", async () => {+ const { state, tab } = await mountTab({ batch: batch("run-1", 3) });+ state.view = "result";+ await nextTick();++ tab.batchSqlExecution = batch("run-2", 2);+ await nextTick();+ await nextTick();++ expect(state.view).toBe("summary");+ expect(useQueryStore().tabs.find((candidate) => candidate.id === tab.id)?.uiState?.batchSummaryExecutionId).toBe("run-2");+ });++ it("leaves a single-statement execution on its result grid", async () => {+ const { state } = await mountTab({ batch: batch("run-1", 1), results: [{ columns: ["a"], rows: [[1]], affected_rows: 1, execution_time_ms: 1 }] });++ expect(state.view).toBe("result");+ });++ it("does not redirect a run that already finished", async () => {+ const { state } = await mountTab({ batch: batch("run-1", 2, Date.now()), isExecuting: false, results: [{ columns: ["a"], rows: [[1]], affected_rows: 1, execution_time_ms: 1 }] });++ expect(state.view).toBe("result");+ });+});diff --git a/apps/desktop/src/types/database.ts b/apps/desktop/src/types/database.tsindex ecb245d4f4..b7ae4ece15 100644--- a/apps/desktop/src/types/database.ts+++ b/apps/desktop/src/types/database.ts@@ -2100,6 +2100,12 @@ export interface TabUiState {resultPaneOpen?: boolean;/** Tracks whether the active output view was auto-switched to "messages" by live server output during execution. */autoSwitchedToMessagesDuringExecution?: boolean;+ /**+ * Execution id whose batch run already auto-switched the output view to the+ * summary. Keying the switch by run keeps it to once per execution, so a user+ * who picks another view mid-run stays there.+ */+ batchSummaryExecutionId?: string;/** Small JSON-compatible snapshots owned by special-page components. */page?: Record<string, TabPageUiState>;}