fix(desktop): allow multiple new table structure tabs

This commit is contained in:
t8y2 2026-06-02 02:13:09 +08:00
parent 90c618dac6
commit 8058c238b8
2 changed files with 31 additions and 10 deletions

View File

@ -234,16 +234,18 @@ export const useQueryStore = defineStore("query", () => {
function openTableStructure(connectionId: string, database: string, schema?: string, tableName?: string) {
const resolvedTableName = tableName || "";
const existing = tabs.value.find(
(tab) =>
tab.mode === "structure" &&
tab.connectionId === connectionId &&
tab.database === database &&
(tab.structureTableName || "") === resolvedTableName,
);
if (existing) {
activeTabId.value = existing.id;
return existing.id;
if (resolvedTableName) {
const existing = tabs.value.find(
(tab) =>
tab.mode === "structure" &&
tab.connectionId === connectionId &&
tab.database === database &&
(tab.structureTableName || "") === resolvedTableName,
);
if (existing) {
activeTabId.value = existing.id;
return existing.id;
}
}
const title = resolvedTableName

View File

@ -748,3 +748,22 @@ test("tab reuse is scoped by mode and schema instead of title alone", () => {
restoreStorage();
}
});
test("new table structure tabs can open multiple drafts while existing tables still reuse tabs", () => {
const restoreStorage = installMemoryStorage();
try {
setActivePinia(createPinia());
const store = useQueryStore();
const firstDraftId = store.openTableStructure("conn-1", "db", "public", "");
const secondDraftId = store.openTableStructure("conn-1", "db", "public", "");
const firstEditId = store.openTableStructure("conn-1", "db", "public", "users");
const secondEditId = store.openTableStructure("conn-1", "db", "public", "users");
assert.notEqual(secondDraftId, firstDraftId);
assert.equal(secondEditId, firstEditId);
assert.equal(store.tabs.length, 3);
} finally {
restoreStorage();
}
});