25 MB lightweight cross-platform database client for 100+ databases, including MySQL, PostgreSQL, SQLite, Redis, MongoDB, DuckDB, SQL Server, and Dameng. Built-in AI, MCP Server, CLI, desktop and Docker. | 轻量级跨平台数据库管理工具,支持 MySQL、PostgreSQL、SQLite、Redis、MongoDB、达梦等 100+ 数据库,提供桌面端、Docker、CLI、内置 AI 助手和 MCP。
TypeScript aicliclickhousedatabasedatabase-clientdatabase-managementdockerguimcpmongodbmysqlpostgresqlredisrustsql-serversqlitetaurivue
fix(objects): keep the object count for single-kind scopes
Abeautifulsnowdfe7510ca0f7
diff --git a/apps/desktop/src/components/objects/ObjectBrowser.vue b/apps/desktop/src/components/objects/ObjectBrowser.vueindex 7702705333..7eefb48917 100644--- a/apps/desktop/src/components/objects/ObjectBrowser.vue+++ b/apps/desktop/src/components/objects/ObjectBrowser.vue@@ -67,7 +67,7 @@ import { translateBackendError } from "@/i18n/backend-errors";import { Button } from "@/components/ui/button";import { Input } from "@/components/ui/input";import { SearchableSelect } from "@/components/ui/searchable-select";-import { DropdownMenuCheckboxItem, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger } from "@/components/ui/dropdown-menu";+import { DropdownMenuCheckboxItem, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger } from "@/components/ui/dropdown-menu";import ToolbarOverflowMenu from "@/components/ui/ToolbarOverflowMenu.vue";import { useToolbarOverflow } from "@/composables/useToolbarOverflow";import CustomContextMenu, { type ContextMenuItem } from "@/components/ui/CustomContextMenu.vue";@@ -450,12 +450,18 @@ const objectFilters = computed<ObjectFilter[]>(() =>.map(([filter]) => filter),);const showObjectFilter = computed(() => objectFilters.value.length > 2);+// A scope that holds a single object kind makes "全部 14" and "表 14" the same number, so the+// strip is dropped as redundant — which used to drop the only object count the toolbar could+// show at all (t8y2/dbx#11624, the common MySQL "tables only" database). Keep that one kind's+// count visible on its own instead; it stays a value, not a filter control, because with a+// single kind there is no 全部 chip left for the user to reset the selection back to.+const singleKindFilter = computed<ObjectFilter | null>(() => (objectFilters.value.length === 2 ? (objectFilters.value.find((filter) => filter !== "all") ?? null) : null));// Measured condensation for the header row: tier 1 moves the sort/view/checkbox// controls into the overflow menu, tier 2 additionally moves the object type// filter there and drops the database chip. See useToolbarOverflow for the// tier contract.const toolbarRef = ref<HTMLElement | null>(null);-const { tier: toolbarTier } = useToolbarOverflow(toolbarRef, [() => props.database, () => selectedSchema.value, () => needsSchema.value, () => showObjectFilter.value]);+const { tier: toolbarTier } = useToolbarOverflow(toolbarRef, [() => props.database, () => selectedSchema.value, () => needsSchema.value, () => showObjectFilter.value, () => singleKindFilter.value]);const showToolbarOverflow = computed(() => toolbarTier.value >= 1);const showInlineSortAndView = computed(() => toolbarTier.value < 1);const showInlineCheckboxToggle = computed(() => toolbarTier.value < 1);@@ -3856,7 +3862,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {<X class="h-3 w-3" /></button></div>- <div v-if="showObjectFilter && showInlineObjectFilter" class="flex h-7 shrink-0 items-center rounded border bg-muted/20 p-0.5">+ <div v-if="showObjectFilter && showInlineObjectFilter" data-object-filter-chips class="flex h-7 shrink-0 items-center rounded border bg-muted/20 p-0.5"><buttonv-for="filter in objectFilters":key="filter"@@ -3868,6 +3874,7 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {{{ filterLabel(filter) }}</button></div>+ <span v-else-if="singleKindFilter && showInlineObjectFilter" data-object-filter-count class="shrink-0 whitespace-nowrap text-xs tabular-nums text-muted-foreground">{{ filterLabel(singleKindFilter) }}</span></div><SearchableSelectv-if="needsSchema"@@ -3952,6 +3959,10 @@ function getObjectBrowserMenuItems(item: ObjectBrowserRow): ContextMenuItem[] {<DropdownMenuSeparator /><DropdownMenuCheckboxItem v-for="filter in objectFilters" :key="filter" :model-value="objectFilter === filter" @select.prevent @update:model-value="selectObjectFilter(filter)">{{ filterLabel(filter) }}</DropdownMenuCheckboxItem></template>+ <template v-else-if="singleKindFilter && toolbarTier >= 2">+ <DropdownMenuSeparator />+ <DropdownMenuLabel data-object-filter-count>{{ filterLabel(singleKindFilter) }}</DropdownMenuLabel>+ </template></ToolbarOverflowMenu></div><div v-if="selectedTableCount > 0 && supportsBatchTableActions" class="flex h-9 shrink-0 items-center gap-2 overflow-x-auto border-b bg-muted/30 px-3 text-xs">diff --git a/apps/desktop/src/components/objects/__tests__/ObjectBrowser.singleKindObjectCount.component.spec.ts b/apps/desktop/src/components/objects/__tests__/ObjectBrowser.singleKindObjectCount.component.spec.tsnew file mode 100644index 0000000000..194b9cf014--- /dev/null+++ b/apps/desktop/src/components/objects/__tests__/ObjectBrowser.singleKindObjectCount.component.spec.ts@@ -0,0 +1,214 @@+// @vitest-environment happy-dom+//+// t8y2/dbx#11624: a scope holding a single object kind (the common MySQL "tables only"+// database) used to render no object count at all, because the per-kind strip is dropped+// whenever "全部 N" and "<kind> N" would repeat the same number. These specs pin the+// replacement: that one kind's count stays visible, stays read-only, and still follows the+// search query. The condensed-toolbar variant (tier >= 2, count moves into the overflow+// menu) is not covered here: the harness stubs ToolbarOverflowMenu out and happy-dom cannot+// drive the measured condensation.++import { createApp, defineComponent, h, nextTick, ref, type App } from "vue";+import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";+import ObjectBrowser from "@/components/objects/ObjectBrowser.vue";+import { invalidateObjectBrowserRowsCache } from "@/lib/table/objectBrowserRowsCache";+import type { ConnectionConfig } from "@/types/database";++const mocks = vi.hoisted(() => ({+ listObjects: vi.fn(),+ listSchemas: vi.fn(),+ listObjectStatistics: vi.fn(),+ mongoListCollections: vi.fn(),+ ensureConnected: vi.fn(),+}));++vi.mock("@/lib/backend/api", () => ({+ listObjects: (...args: unknown[]) => mocks.listObjects(...args),+ listSchemas: (...args: unknown[]) => mocks.listSchemas(...args),+ listObjectStatistics: (...args: unknown[]) => mocks.listObjectStatistics(...args),+ mongoListCollections: (...args: unknown[]) => mocks.mongoListCollections(...args),+}));+vi.mock("@/stores/connectionStore", () => ({+ useConnectionStore: () => ({+ getConfig: () => connection,+ ensureConnected: mocks.ensureConnected,+ orderByPinnedTreeNodes: (rows: unknown[]) => rows,+ }),+}));+vi.mock("@/stores/queryStore", () => ({ useQueryStore: () => ({}) }));+vi.mock("@/stores/settingsStore", () => ({+ useSettingsStore: () => ({+ editorSettings: {+ shortcuts: { refreshData: "F5" },+ objectBrowserViewMode: "list",+ objectBrowserShowCheckbox: false,+ sidebarCopyTableNameSeparator: "newline",+ sidebarCopyTableNameIncludeSchema: false,+ },+ }),+}));+// Labels resolve to their keys so assertions stay locale-independent.+vi.mock("vue-i18n", () => ({ useI18n: () => ({ t: (key: string) => key, locale: ref("en-US") }) }));+vi.mock("@/i18n", () => ({ default: { install: () => undefined } }));+vi.mock("@/composables/useSqlHighlighter", () => ({ useSqlHighlighter: () => ({ highlight: (sql: string) => sql }) }));+vi.mock("@/composables/useToast", () => ({ useToast: () => ({ toast: vi.fn() }) }));+vi.mock("vue-virtual-scroller", () => ({+ RecycleScroller: defineComponent({+ props: { items: { type: Array, default: () => [] } },+ setup(props, { slots }) {+ return () =>+ h(+ "div",+ props.items.map((item) => slots.default?.({ item })),+ );+ },+ }),+}));+vi.mock("@/components/ui/searchable-select", () => ({ SearchableSelect: { render: () => null } }));+vi.mock("@/components/ui/ToolbarOverflowMenu.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/ui/CustomContextMenu.vue", () => ({+ default: defineComponent({+ setup(_, { slots }) {+ return () => slots.default?.({ onContextMenu: () => undefined, isOpen: false });+ },+ }),+}));+vi.mock("@/components/editor/QueryEditor.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/editor/DangerConfirmDialog.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/objects/ProcedureExecutionDialog.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/objects/CustomTypeInfoPanel.vue", () => ({ default: { render: () => null } }));+vi.mock("@/components/export/XlsxHeaderDialog.vue", () => ({ default: { render: () => null } }));++const connection = {+ id: "mysql-cmgt",+ name: "MySQL",+ db_type: "mysql",+ database: "cmgt",+ driver_profile: null,+ url_params: null,+ transport_layers: [],+} as unknown as ConnectionConfig;++// A MongoDB scope lists collections only, so the single-kind path is the normal one there.+const mongoConnection = {+ id: "mongo-cmgt",+ name: "MongoDB",+ db_type: "mongodb",+ database: "cmgt",+ driver_profile: null,+ url_params: null,+ transport_layers: [],+} as unknown as ConnectionConfig;++const mountedApps: Array<{ app: App; host: HTMLElement }> = [];++beforeEach(() => {+ vi.clearAllMocks();+ mocks.listSchemas.mockResolvedValue([]);+ mocks.ensureConnected.mockResolvedValue(undefined);+ mocks.listObjectStatistics.mockResolvedValue([]);+ invalidateObjectBrowserRowsCache({});+});++afterEach(() => {+ for (const { app, host } of mountedApps.splice(0)) {+ app.unmount();+ host.remove();+ }+ invalidateObjectBrowserRowsCache({});+});++async function mountBrowser(objects: Array<{ name: string; object_type: string }>) {+ mocks.listObjects.mockResolvedValue(objects);+ const host = document.createElement("div");+ document.body.append(host);+ const app = createApp({ setup: () => () => h(ObjectBrowser, { connection, database: "cmgt" }) });+ mountedApps.push({ app, host });+ app.mount(host);+ await vi.waitFor(() => expect(mocks.listObjects).toHaveBeenCalled());+ return host;+}++async function mountMongoBrowser(collections: Array<{ name: string; kind?: string }>) {+ mocks.mongoListCollections.mockResolvedValue(collections);+ const host = document.createElement("div");+ document.body.append(host);+ const app = createApp({ setup: () => () => h(ObjectBrowser, { connection: mongoConnection, database: "cmgt" }) });+ mountedApps.push({ app, host });+ app.mount(host);+ await vi.waitFor(() => expect(mocks.mongoListCollections).toHaveBeenCalled());+ return host;+}++function countLabel(host: HTMLElement): Element | null {+ return host.querySelector("[data-object-filter-count]");+}++async function typeSearch(host: HTMLElement, value: string) {+ const input = host.querySelector<HTMLInputElement>("[data-object-search-input]");+ expect(input).not.toBeNull();+ input!.value = value;+ input!.dispatchEvent(new Event("input"));+ await nextTick();+ await nextTick();+}++describe("object browser count for a single-kind scope (#11624)", () => {+ it("shows the only kind's count instead of dropping the strip entirely", async () => {+ const host = await mountBrowser([+ { name: "orders", object_type: "TABLE" },+ { name: "customers", object_type: "TABLE" },+ ]);++ const label = countLabel(host);+ expect(label?.textContent?.trim()).toBe("objects.tables 2");+ // No redundant "全部 2 / 表 2" strip…+ expect(host.querySelector("[data-object-filter-chips]")).toBeNull();+ // …and the statistic is a value, not a filter control: with a single kind there would be+ // no 全部 chip left to reset a selection made here.+ expect(label?.tagName).toBe("SPAN");+ expect(label?.closest("button")).toBeNull();+ });++ it("keeps the count in step with the search query", async () => {+ const host = await mountBrowser([+ { name: "orders", object_type: "TABLE" },+ { name: "customers", object_type: "TABLE" },+ ]);+ expect(countLabel(host)?.textContent?.trim()).toBe("objects.tables 2");++ await typeSearch(host, "order");++ expect(countLabel(host)?.textContent?.trim()).toBe("objects.tables 1");+ });++ it("leaves a multi-kind scope on the clickable strip", async () => {+ const host = await mountBrowser([+ { name: "orders", object_type: "TABLE" },+ { name: "audit_log", object_type: "TRIGGER" },+ ]);++ const chips = host.querySelector("[data-object-filter-chips]");+ expect(chips).not.toBeNull();+ expect([...chips!.querySelectorAll("button")].map((button) => button.textContent?.trim())).toEqual(["objects.all 2", "objects.tables 1", "tree.triggers 1"]);+ expect(countLabel(host)).toBeNull();+ });++ it("shows nothing for an empty scope", async () => {+ const host = await mountBrowser([]);++ expect(countLabel(host)).toBeNull();+ expect(host.querySelector("[data-object-filter-chips]")).toBeNull();+ });++ it("labels a single-kind MongoDB scope with its collection count", async () => {+ const host = await mountMongoBrowser([+ { name: "events", kind: "collection" },+ { name: "sessions", kind: "collection" },+ ]);++ // Collections-only is the normal MongoDB shape, and its wording differs from tables.+ expect(countLabel(host)?.textContent?.trim()).toBe("objects.collections 2");+ expect(host.querySelector("[data-object-filter-chips]")).toBeNull();+ });+});