feat(tabs): persist inactive tab UI state
This commit is contained in:
39 files changed
+1066
-192
No files matched your search
@@ -111,6 +111,61 @@ describe("queryStore editor groups", () => {
|
||||
expect(store.activateTab("missing")).toBe(false);
|
||||
});
|
||||
|
||||
it("keeps UI state isolated when switching tabs", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const firstId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
const secondId = store.createTab("pg-1", "app", "Query 2", "query");
|
||||
|
||||
store.updateTabUiState(firstId, { activeOutputView: "chart", resultPaneOpen: false });
|
||||
store.updateTabUiState(secondId, { activeOutputView: "summary", resultPaneOpen: true });
|
||||
|
||||
store.activateTab(firstId);
|
||||
expect(store.tabs.find((tab) => tab.id === firstId)?.uiState).toEqual({ activeOutputView: "chart", resultPaneOpen: false });
|
||||
store.activateTab(secondId);
|
||||
expect(store.tabs.find((tab) => tab.id === secondId)?.uiState).toEqual({ activeOutputView: "summary", resultPaneOpen: true });
|
||||
});
|
||||
|
||||
it("rejects stale or wrong-mode special-page UI updates", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("pg-1", "app", "Keys", "etcd");
|
||||
const owner = store.tabs.find((tab) => tab.id === tabId)!;
|
||||
|
||||
store.updateTabPageUiState(tabId, "etcd", { EtcdKeyBrowser: { mode: "search" } }, owner);
|
||||
store.updateTabPageUiState(tabId, "query", { QueryEditor: { draft: "stale" } }, owner);
|
||||
store.updateTabPageUiState(tabId, "etcd", { EtcdKeyBrowser: { mode: "watch" } }, { ...owner });
|
||||
|
||||
expect(owner.uiState?.page).toEqual({ etcd: { EtcdKeyBrowser: { mode: "search" } } });
|
||||
});
|
||||
|
||||
it("persists tab UI state with the open-tabs snapshot", async () => {
|
||||
const api = await import("@/lib/backend/api");
|
||||
const storeApi = vi.mocked(api.saveOpenTabsState);
|
||||
storeApi.mockClear();
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
const tabId = store.createTab("pg-1", "app", "Query 1", "query");
|
||||
|
||||
store.updateTabUiState(tabId, { activeOutputView: "messages", resultPaneOpen: false });
|
||||
store.updateTabPageUiState(tabId, "query", { QueryEditor: { inspectorOpen: true } });
|
||||
await store.flushPendingPersist();
|
||||
|
||||
expect(storeApi).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
tabs: [
|
||||
expect.objectContaining({
|
||||
uiState: {
|
||||
activeOutputView: "messages",
|
||||
resultPaneOpen: false,
|
||||
page: { query: { QueryEditor: { inspectorOpen: true } } },
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("close all in group only closes the same pinned partition as the trigger tab", async () => {
|
||||
const { useQueryStore } = await import("@/stores/queryStore");
|
||||
const store = useQueryStore();
|
||||
|
||||
@@ -5,6 +5,7 @@ import { uuid } from "@/lib/common/utils";
|
||||
import { computed, markRaw, nextTick, onScopeDispose, reactive, ref, watch } from "vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import type { BatchSqlExecution, ConnectionConfig, DatabaseType, IndexInfo, NacosConfigEditorViewport, ObjectBrowserFilter, ObjectBrowserViewport, QueryResult, QueryResultSourceColumnRef, QueryTab, TableInfoTab, TableStructureEditorTarget } from "@/types/database";
|
||||
import { sanitizeTabPageUiState } from "@/lib/tabs/tabUiState";
|
||||
import { orderPinnedFirst } from "@/lib/app/pinnedItems";
|
||||
import { canCancelQueryExecution } from "@/lib/sql/queryExecutionState";
|
||||
import { buildExplainSql, parseExplainResult, parseDamengExplainText, parseOracleExplainText, sqlServerExplainResult, type BuildExplainSqlResult, type ExplainPlanDatabaseType } from "@/lib/diagram/explainPlan";
|
||||
@@ -2318,6 +2319,7 @@ export const useQueryStore = defineStore("query", () => {
|
||||
mode: t.mode,
|
||||
autoCommit: t.autoCommit,
|
||||
resultAutoSave: t.resultAutoSave,
|
||||
uiState: t.uiState,
|
||||
structureTableName: t.structureTableName,
|
||||
structureDraft: t.structureDraft,
|
||||
objectBrowser: t.objectBrowser,
|
||||
@@ -4201,6 +4203,36 @@ export const useQueryStore = defineStore("query", () => {
|
||||
queueSavedSqlEditorPositionPersist(tab);
|
||||
}
|
||||
|
||||
function updateTabUiState(id: string, patch: Partial<NonNullable<QueryTab["uiState"]>>) {
|
||||
const tab = tabs.value.find((candidate) => candidate.id === id);
|
||||
if (!tab) return;
|
||||
tab.uiState = { ...tab.uiState, ...patch };
|
||||
}
|
||||
|
||||
function updateTabPageUiState(id: string, mode: string, patch: Record<string, unknown>, owner?: QueryTab) {
|
||||
const tab = tabs.value.find((candidate) => candidate.id === id);
|
||||
if (!tab || tab.mode !== mode || (owner && owner !== tab)) return;
|
||||
const nextPageState = sanitizeTabPageUiState({ ...(tab.uiState?.page?.[mode] ?? {}), ...patch });
|
||||
if (!nextPageState) return;
|
||||
const page = sanitizeTabPageUiState({ ...(tab.uiState?.page ?? {}), [mode]: nextPageState });
|
||||
if (!page) return;
|
||||
tab.uiState = { ...tab.uiState, page: page as NonNullable<QueryTab["uiState"]>["page"] };
|
||||
}
|
||||
|
||||
function updateTabPageResult(id: string, mode: string, result: QueryResult | undefined, owner?: QueryTab) {
|
||||
const tab = tabs.value.find((candidate) => candidate.id === id);
|
||||
if (!tab || tab.mode !== mode || (owner && owner !== tab)) return;
|
||||
if (!result) {
|
||||
clearResultPayload(tab);
|
||||
return;
|
||||
}
|
||||
tab.results = undefined;
|
||||
tab.activeResultIndex = undefined;
|
||||
assignDisplayedResult(tab, result);
|
||||
touchResult(tab);
|
||||
scheduleResultCacheTrim();
|
||||
}
|
||||
|
||||
function updateEditorSelection(id: string, selection: { anchor: number; head: number }) {
|
||||
const tab = tabs.value.find((t) => t.id === id);
|
||||
if (!tab) return;
|
||||
@@ -8023,6 +8055,9 @@ export const useQueryStore = defineStore("query", () => {
|
||||
updateDataGridLocalColumnFilters,
|
||||
updateDataGridHiddenColumnKeys,
|
||||
updateEditorViewport,
|
||||
updateTabUiState,
|
||||
updateTabPageUiState,
|
||||
updateTabPageResult,
|
||||
updateEditorSelection,
|
||||
flushEditorState,
|
||||
updateObjectBrowserViewport,
|
||||
|
||||
Reference in new issue
Block a user