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
feat(sidebar): show the production badge on object rows
HARRISONccac7ba14ff5
diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex 595c36de29..7a89718bd5 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -229,10 +229,40 @@ const activeNode = shallowRef<TreeNode>(props.node);const isDisabledTrigger = computed(() => activeNode.value.type === "trigger" && (activeNode.value.meta as TriggerInfo | undefined)?.enabled === false);+// Marked rows answer "which environment am I looking at" for the connection and+// database that carry the mark, plus the objects below them: a long tree scrolls+// the boundary row out of sight, and that is exactly when the marker is needed.+// Grouping rows (group-*), detail rows (column, index, …) and chrome rows stay+// unmarked so the badge keeps pointing at write targets.+const PRODUCTION_BADGE_NODE_TYPES: ReadonlySet<TreeNode["type"]> = new Set([+ "connection",+ "database",+ "redis-db",+ "mongo-db",+ "table",+ "table-vgroup",+ "view",+ "materialized_view",+ "procedure",+ "function",+ "sequence",+ "synonym",+ "type",+ "package",+ "job",+ "extension",+ "event-trigger",+ "oracle-db-link",+ "mongo-collection",+ "dynamodb-table",+ "vector-collection",+ "elasticsearch-index",+]);+const showProductionBadge = computed(() => {const connectionId = activeNode.value.connectionId;const context = productionContextForDatabase(connectionId ? connectionStore.getConfig(connectionId) : undefined, activeNode.value.database);- return context.active && ["connection", "database", "redis-db", "mongo-db"].includes(activeNode.value.type);+ return context.active && PRODUCTION_BADGE_NODE_TYPES.has(activeNode.value.type);});function currentDatabaseType(): DatabaseType | undefined {diff --git a/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts b/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.tsnew file mode 100644index 0000000000..fb7ffbe7ff--- /dev/null+++ b/apps/desktop/src/components/sidebar/__tests__/TreeItem.productionBadgeScope.spec.ts@@ -0,0 +1,190 @@+// @vitest-environment happy-dom++import { createApp, defineComponent, h, nextTick, type App } from "vue";+import { afterEach, describe, expect, it, vi } from "vitest";+import i18n from "@/i18n";+import TreeItem from "@/components/sidebar/TreeItem.vue";+import { createSidebarTreeRuntime, sidebarTreeRuntimeKey, type SidebarTreeRuntimeHost } from "@/lib/sidebar/sidebarTreeRuntime";+import type { ConnectionConfig, TreeNode } from "@/types/database";++const productionConnection: ConnectionConfig = {+ id: "connection-1",+ name: "Orders",+ db_type: "postgres",+ host: "127.0.0.1",+ port: 5432,+ username: "postgres",+ password: "",+ is_production: true,+};++const databaseMarkedConnection: ConnectionConfig = {+ ...productionConnection,+ is_production: false,+ production_databases: ["analytics"],+};++let connection = productionConnection;++const connectionStore = {+ activeConnectionId: productionConnection.id,+ connectedIds: new Set([productionConnection.id]),+ connectingIds: new Set<string>(),+ connectionErrors: {},+ connectionMultiSelectActive: false,+ connections: [productionConnection],+ getConfig: () => connection,+ getSidebarVisibleFilterSummary: () => null,+ clearConnectionError: vi.fn(),+ isDefaultDatabase: () => false,+ isDefaultSchema: () => false,+ isPinnedTreeNodeReorderTarget: () => false,+ isTreeNodeChildrenLoaded: () => false,+ isTreeNodePinned: () => false,+ selectedTreeNodeId: null as string | null,+ selectedTreeNodeIds: [] as string[],+ selectedTreeNodeIdsSet: new Set<string>(),+ sidebarTableSearchQueries: {},+ tableNameFilterForScope: () => undefined,+ treeNodes: [],+ treeSelectionAnchorId: null as string | null,+};++vi.mock("@/stores/connectionStore", () => ({+ useConnectionStore: () => connectionStore,+}));++vi.mock("@/stores/queryStore", () => ({+ useQueryStore: () => ({ openDatabaseKeys: new Set<string>() }),+}));++vi.mock("@/stores/settingsStore", () => ({+ useSettingsStore: () => ({+ editorSettings: {+ shortcuts: { openDataInNewTab: "" },+ sidebarActivation: "double",+ sidebarAllowHorizontalScroll: false,+ sidebarHiddenTablePrefixes: [],+ sidebarObjectInfoMode: "none",+ sidebarDensity: "default",+ sidebarShowTooltips: false,+ sidebarIndent: 16,+ sidebarTableSearchLocal: true,+ },+ }),+}));++vi.mock("@/composables/useToast", () => ({+ useToast: () => ({ toast: vi.fn() }),+}));++const mountedApps: App[] = [];++afterEach(() => {+ while (mountedApps.length > 0) {+ mountedApps.pop()?.unmount();+ }+ document.body.innerHTML = "";+ connection = productionConnection;+});++function createTreeRuntimeHost(): SidebarTreeRuntimeHost {+ return {+ handleRowClick: vi.fn(),+ handleRowDoubleClick: vi.fn(),+ handleRowKeydown: vi.fn(),+ handleToggleExpand: vi.fn(),+ isSelected: () => false,+ isMultiSelected: () => false,+ isAnchor: () => false,+ usesSelectionSetHighlight: () => false,+ isSelectionLead: () => false,+ isDragging: () => false,+ dragVisualState: () => ({+ dragging: false,+ showBefore: false,+ showAfter: false,+ showInside: false,+ dropTargetNodeId: null,+ }),+ tableVGroupDropTargetNodeId: () => null,+ updateTreeDragTarget: vi.fn(),+ clearTreeDragTarget: vi.fn(),+ canDragPinnedOrder: () => false,+ startPinnedOrderDrag: vi.fn(),+ isNodeHighlighted: () => false,+ onRowContextMenu: vi.fn(),+ executeDefaultNodeAction: vi.fn(),+ };+}++function mountTreeItem(node: TreeNode) {+ const container = document.createElement("div");+ document.body.appendChild(container);++ const runtime = createSidebarTreeRuntime(createTreeRuntimeHost());+ const rootComponent = defineComponent({+ setup() {+ return () => h(TreeItem, { node, depth: 1 });+ },+ });++ const app = createApp(rootComponent);+ app.use(i18n);+ app.provide(sidebarTreeRuntimeKey, runtime);+ app.mount(container);+ mountedApps.push(app);++ return container;+}++function rowText(container: HTMLElement, nodeId: string): string {+ const row = container.querySelector(`[data-node-id="${nodeId}"]`);+ expect(row).not.toBeNull();+ return row?.textContent ?? "";+}++describe("TreeItem production badge scope", () => {+ it("marks object rows inside a production connection", async () => {+ const container = mountTreeItem({ id: "table-1", label: "orders", type: "table", connectionId: productionConnection.id, database: "shop" });+ await nextTick();++ expect(rowText(container, "table-1")).toContain("PROD");+ });++ it("keeps grouping and detail rows unmarked", async () => {+ const groupContainer = mountTreeItem({ id: "group-tables-1", label: "tree.tables", type: "group-tables", connectionId: productionConnection.id, database: "shop" });+ const columnContainer = mountTreeItem({+ id: "column-1",+ label: "status",+ type: "column",+ connectionId: productionConnection.id,+ database: "shop",+ meta: { is_nullable: true, is_primary_key: false },+ });+ await nextTick();++ expect(rowText(groupContainer, "group-tables-1")).not.toContain("PROD");+ expect(rowText(columnContainer, "column-1")).not.toContain("PROD");+ });++ it("leaves object rows unmarked when the connection is not production", async () => {+ connection = { ...productionConnection, is_production: false };++ const container = mountTreeItem({ id: "table-1", label: "orders", type: "table", connectionId: productionConnection.id, database: "shop" });+ await nextTick();++ expect(rowText(container, "table-1")).not.toContain("PROD");+ });++ it("marks object rows only for the databases marked as production", async () => {+ connection = databaseMarkedConnection;++ const markedContainer = mountTreeItem({ id: "table-1", label: "orders", type: "table", connectionId: productionConnection.id, database: "analytics" });+ const otherContainer = mountTreeItem({ id: "table-2", label: "orders", type: "table", connectionId: productionConnection.id, database: "staging" });+ await nextTick();++ expect(rowText(markedContainer, "table-1")).toContain("PROD");+ expect(rowText(otherContainer, "table-2")).not.toContain("PROD");+ });+});