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(sidebar): sync trigger toggle status and preserve table triggers
lxk9556a2caa508389
diff --git a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vueindex 4395398e15..5ebeeed9d6 100644--- a/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue+++ b/apps/desktop/src/components/sidebar/SidebarTreeRuntimeHost.vue@@ -3070,6 +3070,17 @@ async function executeXuguSchedulerJobAction(action: XuguSchedulerJobAction) {}}+function findTreeNodeById(nodes: readonly TreeNode[], id: string): TreeNode | null {+ for (const item of nodes) {+ if (item.id === id) return item;+ if (item.children?.length) {+ const found = findTreeNodeById(item.children, id);+ if (found) return found;+ }+ }+ return null;+}+async function toggleTriggerState(node: TreeNode, enabled: boolean) {if (!node.connectionId || !node.database) return;const databaseType = databaseTypeForNode(node);@@ -3089,8 +3100,18 @@ async function toggleTriggerState(node: TreeNode, enabled: boolean) {await connectionStore.ensureConnected(node.connectionId);const executed = await executeTreeNodeSqlWithProductionGuard(node, sql, { database: node.database, schema: node.schema });if (!executed) return;- if (node.meta && typeof node.meta === "object") {- (node.meta as TriggerInfo).enabled = enabled;+ const updatedMeta: TriggerInfo = {+ // The fallback must satisfy TriggerInfo; the spread ternary's narrower+ // arm is what tripped vue-tsc (TS2322) in CI.+ ...(node.meta && typeof node.meta === "object" ? (node.meta as TriggerInfo) : { name: triggerName, event: "", timing: "" }),+ enabled,+ };+ // `node` may be a frozen action-target copy (createSidebarActionTarget);+ // assigning to it throws in strict mode, and the live node below is the+ // only assignment that matters.+ const liveNode = findSidebarActionTarget(connectionStore.treeNodes, createSidebarActionTarget(node)) ?? findTreeNodeById(connectionStore.treeNodes, node.id);+ if (liveNode) {+ liveNode.meta = updatedMeta;}toast(t(enabled ? "contextMenu.enableTriggerSuccess" : "contextMenu.disableTriggerSuccess", { name: triggerName }), 3000);await connectionStore.refreshTreeNode(node);diff --git a/apps/desktop/src/components/sidebar/TreeItem.vue b/apps/desktop/src/components/sidebar/TreeItem.vueindex 1c7c8f1665..13c9f4231e 100644--- a/apps/desktop/src/components/sidebar/TreeItem.vue+++ b/apps/desktop/src/components/sidebar/TreeItem.vue@@ -230,7 +230,12 @@ const stopPasteHandlerRegistration = watch(const activeNode = shallowRef<TreeNode>(props.node);-const isDisabledTrigger = computed(() => activeNode.value.type === "trigger" && (activeNode.value.meta as TriggerInfo | undefined)?.enabled === false);+const isDisabledTrigger = computed(() => {+ const current = activeNode.value;+ if (current.type !== "trigger") return false;+ const meta = (props.node.meta as TriggerInfo | undefined) ?? (current.meta as TriggerInfo | undefined);+ return meta?.enabled === false;+});const showProductionBadge = computed(() => {const node = activeNode.value;diff --git a/apps/desktop/src/components/sidebar/__tests__/TreeItem.triggerStatus.spec.ts b/apps/desktop/src/components/sidebar/__tests__/TreeItem.triggerStatus.spec.tsindex ec3cf10559..800d125432 100644--- a/apps/desktop/src/components/sidebar/__tests__/TreeItem.triggerStatus.spec.ts+++ b/apps/desktop/src/components/sidebar/__tests__/TreeItem.triggerStatus.spec.ts@@ -170,6 +170,19 @@ describe("TreeItem trigger status", () => {expect(container.querySelector(disabledSelector)).toBeNull();});+ it("updates the badge when trigger node meta is replaced with updated enabled status", async () => {+ const { container, node } = await mountTreeItem(triggerNode(false));+ expect(container.querySelector(disabledSelector)).not.toBeNull();++ node.value.meta = { ...(node.value.meta as TriggerInfo), enabled: true };+ await nextTick();+ expect(container.querySelector(disabledSelector)).toBeNull();++ node.value.meta = { ...(node.value.meta as TriggerInfo), enabled: false };+ await nextTick();+ expect(container.querySelector(disabledSelector)).not.toBeNull();+ });+it("localizes the badge tooltip and accessible name without disabling row activation", async () => {const initialNode = triggerNode(false);const { container, host } = await mountTreeItem(initialNode);diff --git a/apps/desktop/src/stores/__tests__/connectionStore.refresh.spec.ts b/apps/desktop/src/stores/__tests__/connectionStore.refresh.spec.tsindex b31aad3cd7..4d38ede8dd 100644--- a/apps/desktop/src/stores/__tests__/connectionStore.refresh.spec.ts+++ b/apps/desktop/src/stores/__tests__/connectionStore.refresh.spec.ts@@ -67,7 +67,7 @@ function column(name: string) {};}-function installApiMocks(options?: { getColumns?: ReturnType<typeof vi.fn>; listTables?: ReturnType<typeof vi.fn>; listObjects?: ReturnType<typeof vi.fn> }) {+function installApiMocks(options?: { getColumns?: ReturnType<typeof vi.fn>; listTables?: ReturnType<typeof vi.fn>; listObjects?: ReturnType<typeof vi.fn>; listTriggers?: ReturnType<typeof vi.fn> }) {vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));vi.doMock("@/lib/backend/api", () => ({checkConnectionHealth: vi.fn().mockResolvedValue(undefined),@@ -76,6 +76,7 @@ function installApiMocks(options?: { getColumns?: ReturnType<typeof vi.fn>; listlistInstalledAgents: vi.fn().mockResolvedValue([]),listObjects: options?.listObjects ?? vi.fn().mockResolvedValue([]),listTables: options?.listTables ?? vi.fn().mockResolvedValue([]),+ listTriggers: options?.listTriggers ?? vi.fn().mockResolvedValue([]),loadSchemaCache: vi.fn().mockResolvedValue(null),saveConnections: vi.fn().mockResolvedValue(undefined),saveSchemaCache: vi.fn().mockResolvedValue(undefined),@@ -167,6 +168,98 @@ describe("connectionStore tree refresh state", () => {expect(getColumns).toHaveBeenCalledTimes(2);expect(store.completionCacheRevision("pg-1", "app")).toBeGreaterThan(0);});++ it("refreshes a table-level trigger group using listTriggers without wiping triggers", async () => {+ const listTriggers = vi.fn().mockResolvedValue([{ name: "trg_orders_audit", timing: "AFTER", event: "UPDATE", enabled: false }]);+ const listObjects = vi.fn().mockResolvedValue([]);+ installApiMocks({ listTriggers, listObjects });++ const triggerGroup: TreeNode = {+ id: "pg-1:app:public:orders:__triggers",+ label: "tree.triggers",+ type: "group-triggers",+ connectionId: "pg-1",+ database: "app",+ schema: "public",+ tableName: "orders",+ isExpanded: true,+ children: [],+ };+ const table: TreeNode = {+ id: "pg-1:app:public:orders",+ label: "orders",+ type: "table",+ connectionId: "pg-1",+ database: "app",+ schema: "public",+ tableName: "orders",+ isExpanded: true,+ children: [triggerGroup],+ };+ const root = schemaNode([table]);+ const store = await createStore(root);++ await store.refreshTreeNode(triggerGroup);++ expect(listTriggers).toHaveBeenCalledWith("pg-1", "app", "public", "orders", undefined);+ expect(listObjects).not.toHaveBeenCalled();+ expect(triggerGroup.objectCount).toBe(1);+ expect(triggerGroup.children).toHaveLength(1);+ expect(triggerGroup.children![0]).toMatchObject({+ id: "pg-1:app:public:orders:__triggers:trg_orders_audit",+ type: "trigger",+ tableName: "orders",+ meta: { name: "trg_orders_audit", enabled: false },+ });+ });++ it("refreshes the parent table trigger group when refreshing a child trigger node", async () => {+ const listTriggers = vi.fn().mockResolvedValue([{ name: "trg_orders_audit", timing: "AFTER", event: "UPDATE", enabled: true }]);+ installApiMocks({ listTriggers });++ const triggerChild: TreeNode = {+ id: "pg-1:app:public:orders:__triggers:trg_orders_audit",+ label: "trg_orders_audit (AFTER UPDATE)",+ type: "trigger",+ connectionId: "pg-1",+ database: "app",+ schema: "public",+ tableName: "orders",+ meta: { name: "trg_orders_audit", enabled: false },+ };+ const triggerGroup: TreeNode = {+ id: "pg-1:app:public:orders:__triggers",+ label: "tree.triggers",+ type: "group-triggers",+ connectionId: "pg-1",+ database: "app",+ schema: "public",+ tableName: "orders",+ isExpanded: true,+ children: [triggerChild],+ };+ const table: TreeNode = {+ id: "pg-1:app:public:orders",+ label: "orders",+ type: "table",+ connectionId: "pg-1",+ database: "app",+ schema: "public",+ tableName: "orders",+ isExpanded: true,+ children: [triggerGroup],+ };+ const root = schemaNode([table]);+ const store = await createStore(root);++ await store.refreshTreeNode(triggerChild);++ expect(listTriggers).toHaveBeenCalledWith("pg-1", "app", "public", "orders", undefined);+ expect(triggerGroup.children![0].meta).toMatchObject({+ name: "trg_orders_audit",+ enabled: true,+ });+ });});describe("connection node refresh awaits object cache invalidation", () => {diff --git a/apps/desktop/src/stores/connectionStore.ts b/apps/desktop/src/stores/connectionStore.tsindex d358d1e6b5..7df455c223 100644--- a/apps/desktop/src/stores/connectionStore.ts+++ b/apps/desktop/src/stores/connectionStore.ts@@ -7413,7 +7413,7 @@ export const useConnectionStore = defineStore("connection", () => {async function loadAllObjectGroupChildren(parent: TreeNode, initialLoadOptions?: LoadTreeOptions) {if (!parent.connectionId || !hasTreeNodeDatabaseContext(parent)) return;- if (!objectTypesForGroupNode(parent.type)) return;+ if (!objectTypesForGroupNode(parent.type) || parent.tableName) return;const liveParent = treeNodeInSidebarTree(parent);if (!liveParent) return;if (initialLoadOptions?.force || !isTreeNodeChildrenLoaded(liveParent.id) || filteredObjectGroupChildrenIds.has(liveParent.id)) {@@ -8069,6 +8069,13 @@ export const useConnectionStore = defineStore("connection", () => {}invalidateCompletionCachesForNode(node);invalidateMetadataCachesForNode(node, options);+ if (node.type === "trigger") {+ const parentNode = findParentNode(treeNodes.value, node.id) ?? (node.id.lastIndexOf(":") > 0 ? findNode(treeNodes.value, node.id.slice(0, node.id.lastIndexOf(":"))) : null);+ if (parentNode) {+ await refreshTreeNode(parentNode, options);+ return;+ }+ }if (objectTypesForGroupNode(node.type) && !node.tableName) {clearLoadedChildrenCache(node.id, { deletePersisted: false });await loadObjectGroupChildren(node, { force: true });