feat(query): close individual query result and release result session

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-08-10 22:40:36 +08:00
1 parent 044bedaabe
commit 3663dc4d7b
14 files changed
+166 -1

No files matched your search

+15
View File
@@ -4,6 +4,7 @@ import { test } from "vitest";
import { compileScript, compileTemplate, parse } from "vue/compiler-sfc";
const contentAreaPath = "apps/desktop/src/components/layout/ContentArea.vue";
const appPath = "apps/desktop/src/App.vue";
const dataGridPath = "apps/desktop/src/components/grid/DataGrid.vue";
const viewSwitcherPath = "apps/desktop/src/components/layout/QueryResultViewSwitcher.vue";
const toolbarActionsPath = "apps/desktop/src/components/layout/QueryResultToolbarActions.vue";
@@ -55,6 +56,10 @@ test("ContentArea exposes retained result runs as switchable tabs or a compact l
assert.match(contentArea, /data-result-run-tab/);
assert.match(contentArea, /@keydown="onResultRunTabKeydown\(\$event, runIndex\)"/);
assert.match(contentArea, /@click\.stop\.prevent="removeResultRun\(run\.id\)"/);
assert.match(contentArea, /const canCloseQueryResult = computed\([\s\S]*!props\.activeTab\.activeResultRunId/);
assert.match(contentArea, /v-if="canCloseQueryResult"[\s\S]*@click="closeCurrentQueryResult"/);
assert.match(contentArea, /queryStore\.closeQueryResult\(props\.activeTab\.id\)/);
assert.match(contentArea, /t\('tabs\.closeResult'\)/);
assert.match(contentArea, /<DropdownMenuContent align="start" class="w-48">[\s\S]*v-for="run in resultRuns"/);
assert.match(contentArea, /setResultRunDisplayMode\('list'\)/);
assert.match(contentArea, /setResultRunDisplayMode\('tabs'\)/);
@@ -68,6 +73,16 @@ test("ContentArea exposes retained result runs as switchable tabs or a compact l
assert.equal((contentArea.match(/<QueryResultToolbarActions\b/g) ?? []).length, 2);
});
test("the close-tab shortcut clears query results before closing the tab", () => {
const app = source(appPath);
const closeShortcutStart = app.indexOf("if (isCloseTabShortcut(e, shortcuts))");
const closeShortcutEnd = app.indexOf("if (isSaveShortcut", closeShortcutStart);
const closeShortcut = app.slice(closeShortcutStart, closeShortcutEnd);
assert.ok(closeShortcutStart >= 0);
assert.ok(closeShortcut.indexOf("await queryStore.clearQueryResults(queryStore.activeTabId)") < closeShortcut.indexOf("queryStore.closeTab(queryStore.activeTabId)"));
});
test("ContentArea keeps MySQL standard explain results available in the shared toolbar", () => {
const contentArea = source(contentAreaPath);
+21
View File
@@ -1304,6 +1304,27 @@ test("removing the active result run selects an adjacent run", async () => {
assert.deepEqual(tab.result?.columns, ["one"]);
});
test("closing an ordinary query result preserves the query tab", async () => {
setActivePinia(createPinia());
const store = useQueryStore();
const tabId = store.createTab("conn-1", "db");
const tab = store.tabs.find((item) => item.id === tabId);
assert.ok(tab);
tab.sql = "select draft";
tab.result = { columns: ["one"], rows: [[1]], affected_rows: 0, execution_time_ms: 1 };
tab.lastExecutedSql = "select 1";
assert.equal(await store.closeQueryResult(tabId), true);
assert.equal(tab.sql, "select draft");
assert.equal(tab.connectionId, "conn-1");
assert.equal(tab.database, "db");
assert.equal(tab.result, undefined);
assert.equal(tab.results, undefined);
assert.equal(tab.activeResultRunId, undefined);
});
test("removing the active result run clears output when remaining caches are unavailable", async () => {
setActivePinia(createPinia());
const store = useQueryStore();