fix(tabs): hide database tooltip for unsupported plugin tabs

This commit is contained in:
OOMEcho authored and GitHub committed 2026-09-28 13:12:48 +08:00
1 parent 2012b856f8
commit 9e17d465a0
3 files changed
+37 -2

No files matched your search

@@ -42,7 +42,9 @@ vi.mock("@/components/icons/DatabaseIcon.vue", () => ({
})); }));
import EditorGroupTabBar from "../EditorGroupTabBar.vue"; import EditorGroupTabBar from "../EditorGroupTabBar.vue";
import { useConnectionStore } from "@/stores/connectionStore";
import { useQueryStore } from "@/stores/queryStore"; import { useQueryStore } from "@/stores/queryStore";
import type { ConnectionConfig } from "@/types/database";
function createHost(): HTMLDivElement { function createHost(): HTMLDivElement {
const host = document.createElement("div"); const host = document.createElement("div");
@@ -84,6 +86,12 @@ function mountBar(
en: { en: {
toolbar: { pluginCenter: "Plugin Center" }, toolbar: { pluginCenter: "Plugin Center" },
common: { close: "Close" }, common: { close: "Close" },
connectionGroup: { ungroupedLabel: "Ungrouped" },
tabs: {
tooltipConnection: "Connection:",
tooltipGroup: "Group:",
tooltipDatabase: "Database:",
},
contextMenu: { contextMenu: {
splitRight: "Split right", splitRight: "Split right",
splitDown: "Split down", splitDown: "Split down",
@@ -244,7 +252,10 @@ describe("EditorGroupTabBar behavior", () => {
it("keeps the tooltip for a connection-bound plugin tab", async () => { it("keeps the tooltip for a connection-bound plugin tab", async () => {
const store = useQueryStore(); const store = useQueryStore();
const tabId = store.openPluginWorkbench("com.example.toolbox", "toolbox", { connectionId: "pg-1" }); const connectionStore = useConnectionStore();
connectionStore.connections = [{ id: "plugin-1", name: "SSH server", db_type: "plugin" } as ConnectionConfig];
connectionStore.sidebarLayout = { groups: [], order: [{ type: "connection", id: "plugin-1" }] };
const tabId = store.openPluginWorkbench("com.example.toolbox", "toolbox", { connectionId: "plugin-1" });
const mainGroup = store.groups[0]; const mainGroup = store.groups[0];
const { app, host } = mountBar(mainGroup.id, [tabId], tabId, pinia); const { app, host } = mountBar(mainGroup.id, [tabId], tabId, pinia);
await settle(); await settle();
@@ -255,6 +266,8 @@ describe("EditorGroupTabBar behavior", () => {
expect(tooltip.dataset.open).toBe("true"); expect(tooltip.dataset.open).toBe("true");
expect(host.querySelector("[data-plugin-title-tooltip]")).toBeNull(); expect(host.querySelector("[data-plugin-title-tooltip]")).toBeNull();
expect(host.querySelector<HTMLElement>(".tooltip-content-stub")?.textContent).toContain("SSH server");
expect(host.querySelector<HTMLElement>(".tooltip-content-stub")?.textContent).not.toContain("Database:");
app.unmount(); app.unmount();
host.remove(); host.remove();
@@ -431,6 +431,25 @@ describe("tab group presentation", () => {
} }
}); });
it("shows a database row for plugin tabs only when the tab or connection has a database", () => {
const store = useConnectionStore();
store.sidebarLayout = {
groups: [],
order: [{ type: "connection", id: "conn-1" }],
};
store.connections = [{ id: "conn-1", name: "SSH server", db_type: "plugin" } as ConnectionConfig];
const tab = queryTab({ mode: "plugin-workbench", database: "" });
expect(tabTooltipLines(tab, translate)).toEqual([
{ label: "Connection:", value: "SSH server" },
{ label: "Group:", value: "Ungrouped" },
]);
store.connections = [{ id: "conn-1", name: "Database plugin", db_type: "plugin", database: "analytics" } as ConnectionConfig];
expect(tabTooltipLines(tab, translate)).toContainEqual({ label: "Database:", value: "analytics" });
expect(tabTooltipLines(queryTab({ mode: "plugin-workbench", database: "reporting" }), translate)).toContainEqual({ label: "Database:", value: "reporting" });
});
it("labels a top-level connection as ungrouped", () => { it("labels a top-level connection as ungrouped", () => {
const store = useConnectionStore(); const store = useConnectionStore();
store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", database: "app" } as ConnectionConfig]; store.connections = [{ id: "conn-1", name: "PostgreSQL", db_type: "postgres", database: "app" } as ConnectionConfig];
+4 -1
View File
@@ -263,10 +263,13 @@ export function tabTooltipLines(tab: QueryTab, t: Translate): { label: string; v
const connName = connectionDisplayName(tab.connectionId); const connName = connectionDisplayName(tab.connectionId);
const groupName = connectionGroupDisplayName(tab.connectionId, t); const groupName = connectionGroupDisplayName(tab.connectionId, t);
const connection = useConnectionStore().getConfig(tab.connectionId); const connection = useConnectionStore().getConfig(tab.connectionId);
const isPluginTab = tab.mode === "plugin-workbench" || tab.mode === "plugin-filesystem";
const database = isPluginTab ? tab.database || connection?.database || "" : tab.database;
const showDatabase = (!connection || supportsConnectionDatabaseInfo(connection.db_type)) && (!isPluginTab || Boolean(database.trim()));
const lines: { label: string; value: string }[] = [ const lines: { label: string; value: string }[] = [
{ label: t("tabs.tooltipConnection"), value: connName }, { label: t("tabs.tooltipConnection"), value: connName },
...(groupName ? [{ label: t("tabs.tooltipGroup"), value: groupName }] : []), ...(groupName ? [{ label: t("tabs.tooltipGroup"), value: groupName }] : []),
...(!connection || supportsConnectionDatabaseInfo(connection.db_type) ? [{ label: t("tabs.tooltipDatabase"), value: databaseDisplayNameForTab(tab.connectionId, tab.database, t) }] : []), ...(showDatabase ? [{ label: t("tabs.tooltipDatabase"), value: databaseDisplayNameForTab(tab.connectionId, database, t) }] : []),
]; ];
if (tab.mode === "query" && queryTitle(tab)) { if (tab.mode === "query" && queryTitle(tab)) {
lines.unshift({ label: t("tabs.tooltipTitle"), value: tab.title }); lines.unshift({ label: t("tabs.tooltipTitle"), value: tab.title });