fix(desktop): unify grouped tab bar portal across special pages

This commit is contained in:
二丫讲梵 authored and GitHub committed 2026-09-06 20:39:34 +08:00
1 parent 3123e962c8
commit 148345494e
27 files changed
+1352 -590

No files matched your search

@@ -63,6 +63,19 @@ describe("queryStore detached-tab handoff", () => {
expect(freshStore.focusedGroupId).toBe(freshStore.groups[0]?.id);
});
it("keeps read-only source intent across detached-window handoff", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
const id = store.createTab("pg-1", "app", "Source - seq_users", "query", "public", "CREATE SEQUENCE seq_users", undefined, { sourceView: true });
const handoff = await store.prepareDetachedTab(id);
expect(handoff.tab.sourceView).toBe(true);
setActivePinia(createPinia());
const detachedStore = useQueryStore();
await detachedStore.adoptDetachedTab(handoff);
expect(detachedStore.tabs[0]?.sourceView).toBe(true);
expect(detachedStore.tabs[0]?.objectSource).toBeUndefined();
});
it("removeTabAfterDetachedReady clears the owning pane and prunes it when emptied", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
@@ -0,0 +1,45 @@
import { createPinia, setActivePinia } from "pinia";
import { beforeEach, describe, expect, it, vi } from "vitest";
describe("queryStore source-view intent", () => {
beforeEach(() => {
vi.stubGlobal("localStorage", { getItem: vi.fn(() => null), setItem: vi.fn(), removeItem: vi.fn() });
setActivePinia(createPinia());
});
it("preserves read-only source intent when duplicating a tab", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
const id = store.createTab("pg-1", "app", "Source - seq_users", "query", "public", "CREATE SEQUENCE seq_users", undefined, { sourceView: true });
store.duplicateTab(id);
expect(store.tabs).toHaveLength(2);
for (const tab of store.tabs) {
expect(tab.sourceView).toBe(true);
expect(tab.objectSource).toBeUndefined();
}
});
it("marks a reused legacy source tab without relying on its title to detect intent", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
const id = store.createTab("pg-1", "app", "Source - seq_users");
expect(store.tabs[0]?.sourceView).toBeUndefined();
const reused = store.createTab("pg-1", "app", "Source - seq_users", "query", undefined, undefined, undefined, { sourceView: true });
expect(reused).toBe(id);
expect(store.tabs).toHaveLength(1);
expect(store.tabs[0]?.sourceView).toBe(true);
expect(store.tabs[0]?.objectSource).toBeUndefined();
});
it("marks new and reused editable object-source tabs", async () => {
const { useQueryStore } = await import("@/stores/queryStore");
const store = useQueryStore();
const options = { connectionId: "pg-1", database: "app", title: "Source - users", sql: "CREATE VIEW users AS SELECT 1", objectSource: { name: "users", objectType: "VIEW" as const } };
const id = store.openObjectSourceTab(options);
expect(store.tabs[0]?.sourceView).toBe(true);
store.tabs[0]!.sourceView = undefined;
expect(store.openObjectSourceTab(options)).toBe(id);
expect(store.tabs[0]?.sourceView).toBe(true);
expect(store.tabs[0]?.objectSource).toEqual(options.objectSource);
});
});
+16 -2
View File
@@ -2244,6 +2244,7 @@ export const useQueryStore = defineStore("query", () => {
structureTableName: t.structureTableName,
objectBrowser: t.objectBrowser,
objectSource: t.objectSource,
sourceView: t.sourceView,
tableMeta: t.tableMeta,
mongoEditTarget: t.mongoEditTarget,
resultEvicted: t.resultEvicted,
@@ -2430,10 +2431,20 @@ export const useQueryStore = defineStore("query", () => {
return tabs.value.find((tab) => tab.connectionId === connectionId && tab.database === database && tab.title === title && tab.mode === mode && (tab.schema || "") === (schema || "") && (tab.catalog || "") === (catalog || ""));
}
function createTab(connectionId: string, database: string, title?: string, mode: QueryTab["mode"] = "query", schema?: string, initialSql?: string, catalog?: string, options: { forceNew?: boolean; activate?: boolean; forceWordWrap?: boolean; insertAfterActive?: boolean } = {}) {
function createTab(
connectionId: string,
database: string,
title?: string,
mode: QueryTab["mode"] = "query",
schema?: string,
initialSql?: string,
catalog?: string,
options: { forceNew?: boolean; activate?: boolean; forceWordWrap?: boolean; insertAfterActive?: boolean; sourceView?: boolean } = {},
) {
if (title && !options.forceNew) {
const existing = findTabByIdentity(connectionId, database, title, mode, schema, catalog);
if (existing) {
if (options.sourceView) existing.sourceView = true;
switchTab(existing.id);
return existing.id;
}
@@ -2446,6 +2457,7 @@ export const useQueryStore = defineStore("query", () => {
title: title || `query_${tabs.value.length + 1}`,
customTitle: mode === "query" && title ? true : undefined,
forceWordWrap: options.forceWordWrap,
sourceView: options.sourceView,
connectionId,
database,
schema,
@@ -2478,6 +2490,7 @@ export const useQueryStore = defineStore("query", () => {
(tab.objectSource.signature || "") === (options.objectSource.signature || ""),
);
if (existing) {
existing.sourceView = true;
switchTab(existing.id);
if (!isTabDirty(existing)) {
updateSql(existing.id, options.sql);
@@ -2486,7 +2499,7 @@ export const useQueryStore = defineStore("query", () => {
return existing.id;
}
const id = createTab(options.connectionId, options.database, options.title, "query", options.schema, options.sql, options.catalog, { forceNew: true });
const id = createTab(options.connectionId, options.database, options.title, "query", options.schema, options.sql, options.catalog, { forceNew: true, sourceView: true });
setObjectSource(id, options.objectSource);
return id;
}
@@ -3682,6 +3695,7 @@ export const useQueryStore = defineStore("query", () => {
structureDraft: original.structureDraft ? cloneTabDraft(original.structureDraft) : undefined,
objectBrowser: original.objectBrowser ? { ...original.objectBrowser } : undefined,
objectSource: original.objectSource ? { ...original.objectSource } : undefined,
sourceView: original.sourceView,
tableMeta: original.tableMeta ? { ...original.tableMeta, columns: [...original.tableMeta.columns], primaryKeys: [...original.tableMeta.primaryKeys] } : undefined,
queryAnalysis: original.queryAnalysis ? { ...original.queryAnalysis, sources: original.queryAnalysis.sources?.map((source) => ({ ...source })), columns: original.queryAnalysis.columns.map((c) => ({ ...c })) } : undefined,
querySourceColumns: original.querySourceColumns ? [...original.querySourceColumns] : undefined,