fix(tabs): assign duplicate-tab numbers once without renumbering on close

This commit is contained in:
zipg authored and GitHub committed 2026-09-22 10:58:15 +08:00
1 parent b7152a29cd
commit 8858a731aa
8 files changed
+138 -20

No files matched your search

+56 -3
View File
@@ -16,6 +16,7 @@ import {
tabDatabaseIconType,
tabDisplayTitle,
tabDisplayTitles,
syncTabTitleNumbers,
tabIconClass,
tabTooltipLines,
tabularResultItems,
@@ -192,21 +193,73 @@ describe("query result grid identity", () => {
});
describe("tab group presentation", () => {
// 编号由 store 在标签列表变化时分配,渲染函数只读结果;这里把两步串起来,
// 与真实调用顺序保持一致(#9938)。
const titlesWithNumbers = (tabs: QueryTab[]) => {
syncTabTitleNumbers(tabs, translate);
return tabDisplayTitles(tabs, translate);
};
it("numbers colliding query tab titles so several tabs stay distinguishable", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2" }), queryTab({ id: "tab-3" })];
const titles = tabDisplayTitles(tabs, translate);
const titles = titlesWithNumbers(tabs);
expect([...titles.values()]).toEqual(["PostgreSQL@db 1", "PostgreSQL@db 2", "PostgreSQL@db 3"]);
});
it("keeps the remaining numbers when a tab in the middle is closed", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2" }), queryTab({ id: "tab-3" })];
titlesWithNumbers(tabs);
const titles = titlesWithNumbers(tabs.filter((tab) => tab.id !== "tab-2"));
expect(titles.get("tab-1")).toBe("PostgreSQL@db 1");
expect(titles.get("tab-3")).toBe("PostgreSQL@db 3");
});
it("keeps the number on the last surviving tab of a closed group", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2" })];
titlesWithNumbers(tabs);
expect(titlesWithNumbers([tabs[0]!]).get("tab-1")).toBe("PostgreSQL@db 1");
});
it("continues after the highest number still in use when a new tab opens", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2" }), queryTab({ id: "tab-3" })];
titlesWithNumbers(tabs);
const next = [...tabs.filter((tab) => tab.id !== "tab-2"), queryTab({ id: "tab-4" })];
const titles = titlesWithNumbers(next);
expect(titles.get("tab-1")).toBe("PostgreSQL@db 1");
expect(titles.get("tab-3")).toBe("PostgreSQL@db 3");
expect(titles.get("tab-4")).toBe("PostgreSQL@db 4");
});
it("drops the number of a tab whose title stops colliding", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2" })];
titlesWithNumbers(tabs);
tabs[1]!.database = "other";
const titles = titlesWithNumbers(tabs);
expect(titles.get("tab-1")).toBe("PostgreSQL@db 1");
expect(titles.get("tab-2")).toBe("PostgreSQL@other");
});
it("leaves tab titles untouched while they are unique", () => {
const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1" }), queryTab({ id: "tab-2", database: "other" }), queryTab({ id: "tab-3", customTitle: true, title: "orders.sql", savedSqlId: "sql-1" })];
const titles = tabDisplayTitles(tabs, translate);
const titles = titlesWithNumbers(tabs);
expect(titles.get("tab-1")).toBe("PostgreSQL@db");
expect(titles.get("tab-2")).toBe("PostgreSQL@other");
expect(titles.get("tab-3")).toBe("orders.sql");
@@ -217,7 +270,7 @@ describe("tab group presentation", () => {
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig, { id: "conn-preview", name: "[Preview] PostgreSQL", db_type: "postgres", driver_profile: "postgres", database: "app" } as ConnectionConfig];
const tabs = [queryTab({ id: "tab-1", customTitle: true, title: "orders.sql", savedSqlId: "sql-1" }), queryTab({ id: "tab-preview", connectionId: "conn-preview" }), queryTab({ id: "tab-2", customTitle: true, title: "orders.sql", savedSqlId: "sql-2" })];
const titles = tabDisplayTitles(tabs, translate);
const titles = titlesWithNumbers(tabs);
expect(titles.get("tab-1")).toBe("orders.sql 1");
expect(titles.get("tab-2")).toBe("orders.sql 2");
expect(titles.get("tab-preview")).toBe("SQL");