fix(sidebar): refresh grouped object nodes
This commit is contained in:
parent
df574c78a5
commit
cb00b27963
|
|
@ -58,6 +58,20 @@ const groupDefs: Array<{
|
|||
},
|
||||
];
|
||||
|
||||
const objectGroupNodeTypes = new Set<TreeNodeType>([
|
||||
"group-tables",
|
||||
"group-views",
|
||||
"group-procedures",
|
||||
"group-functions",
|
||||
]);
|
||||
|
||||
export function objectGroupRefreshParentId(node: TreeNode): string | null {
|
||||
if (!objectGroupNodeTypes.has(node.type)) return null;
|
||||
const suffixStart = node.id.lastIndexOf(":__");
|
||||
if (suffixStart < 0) return null;
|
||||
return node.id.slice(0, suffixStart);
|
||||
}
|
||||
|
||||
export function buildGroupedObjectTreeNodes({
|
||||
nodeId,
|
||||
connectionId,
|
||||
|
|
|
|||
|
|
@ -23,7 +23,12 @@ import { isTauriRuntime } from "@/lib/tauriRuntime";
|
|||
import { isSchemaAware, TREE_SCHEMA_TYPES } from "@/lib/databaseCapabilities";
|
||||
import { buildDatabaseTreeNodes } from "@/lib/databaseTree";
|
||||
import { buildSqlServerDatabaseTreeNodes, SQLSERVER_DEFAULT_SCHEMA } from "@/lib/sqlServerTree";
|
||||
import { buildGroupedObjectTreeNodes, buildTableTreeNodes, expandCachedObjectBrowserNodes } from "@/lib/tableTree";
|
||||
import {
|
||||
buildGroupedObjectTreeNodes,
|
||||
buildTableTreeNodes,
|
||||
expandCachedObjectBrowserNodes,
|
||||
objectGroupRefreshParentId,
|
||||
} from "@/lib/tableTree";
|
||||
import { useSavedSqlStore } from "@/stores/savedSqlStore";
|
||||
|
||||
const PINNED_TREE_NODES_STORAGE_KEY = "dbx-pinned-tree-nodes";
|
||||
|
|
@ -964,6 +969,13 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||
}
|
||||
|
||||
async function refreshTreeNode(node: TreeNode) {
|
||||
const parentId = objectGroupRefreshParentId(node);
|
||||
const parentNode = parentId ? findNode(treeNodes.value, parentId) : null;
|
||||
if (parentNode) {
|
||||
await refreshTreeNode(parentNode);
|
||||
return;
|
||||
}
|
||||
|
||||
const expandedIds = collectExpandedNodeIds([node]);
|
||||
expandedIds.add(node.id);
|
||||
await clearPersistedTreeCacheForNode(node);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { buildTableTreeNodes, expandCachedObjectBrowserNodes } from "../src/lib/tableTree.ts";
|
||||
import { buildTableTreeNodes, expandCachedObjectBrowserNodes, objectGroupRefreshParentId } from "../src/lib/tableTree.ts";
|
||||
import type { TableInfo } from "../src/types/database.ts";
|
||||
|
||||
function table(name: string, tableType: "TABLE" | "VIEW" = "TABLE"): TableInfo {
|
||||
|
|
@ -82,3 +82,17 @@ test("expands cached object-browser nodes back into regular table nodes", () =>
|
|||
],
|
||||
);
|
||||
});
|
||||
|
||||
test("resolves grouped object refreshes to the parent schema node", () => {
|
||||
assert.equal(
|
||||
objectGroupRefreshParentId({
|
||||
id: "conn:db:public:__tables",
|
||||
label: "tree.tables",
|
||||
type: "group-tables",
|
||||
connectionId: "conn",
|
||||
database: "db",
|
||||
schema: "public",
|
||||
}),
|
||||
"conn:db:public",
|
||||
);
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue