feat(xugu): expose tablespaces and datafiles in tree

This commit is contained in:
Elias authored and GitHub committed 2026-09-01 00:34:12 +08:00
1 parent afe3b3f3c2
commit 351a8b699b
32 files changed
+811 -4

No files matched your search

@@ -39,6 +39,7 @@ const leafTypes: Set<TreeNodeType> = new Set([
"table-search-control",
"load-more",
"extension",
"datafile",
]);
const fullWidthLabelTypes: Set<TreeNodeType> = new Set(["table", "view", "materialized_view", "mongo-collection", "mongo-bucket", "dynamodb-table", "vector-collection", "elasticsearch-index"]);
@@ -13,7 +13,7 @@ export function treeNodeLoadedChildrenContentPresent(node: TreeNode, sidebarObje
// Grouped mode always materializes object-group placeholders; empty means a stale shell.
return sidebarObjectDisplay === "simple";
}
if (objectTypesForGroupNode(node.type) || TABLE_STRUCTURE_GROUP_TYPES.has(node.type) || node.type === "group-extensions") {
if (objectTypesForGroupNode(node.type) || TABLE_STRUCTURE_GROUP_TYPES.has(node.type) || node.type === "group-extensions" || node.type === "group-tablespaces" || node.type === "group-datafiles") {
return true;
}
return childCount > 0;
@@ -22,6 +22,8 @@ const treeGroupNodeTypes = new Set<TreeNodeType>([
"group-types",
"group-partitions",
"group-extensions",
"group-tablespaces",
"group-datafiles",
"type-attributes",
"type-methods",
]);
@@ -15,6 +15,10 @@ export function getTreeNodeIconInfo(node: TreeNode): TreeNodeIconInfo | null {
case "database":
case "mongo-db":
return { icon: Database, colorClass: "text-yellow-500" };
case "tablespace":
return { icon: Database, colorClass: "text-orange-500" };
case "datafile":
return { icon: FileCode, colorClass: "text-slate-500" };
case "vector-database":
return { icon: Database, colorClass: "text-cyan-500" };
case "linked-server-root":
@@ -138,6 +142,10 @@ export function getTreeNodeIconInfo(node: TreeNode): TreeNodeIconInfo | null {
return { icon: Clock, colorClass: "text-orange-400" };
case "group-packages":
return { icon: Package, colorClass: "text-cyan-500" };
case "group-tablespaces":
return { icon: Database, colorClass: "text-orange-500" };
case "group-datafiles":
return { icon: node.isExpanded ? FolderOpen : FolderClosed, colorClass: "text-slate-500" };
case "group-partitions":
return { icon: node.isExpanded ? FolderOpen : FolderClosed, colorClass: "text-green-400" };
case "group-extensions":
@@ -0,0 +1,50 @@
import type { TreeNode, XuguTablespaceInfo } from "@/types/database";
export function xuguDatafileDisplayName(path: string, fileNo: number): string {
const normalized = path.trim().replaceAll("\\", "/");
const parts = normalized.split("/").filter(Boolean);
const basename = parts.length > 0 ? parts[parts.length - 1] : undefined;
return basename || path.trim() || `file-${fileNo}`;
}
export function buildXuguTablespaceChildren(parent: Pick<TreeNode, "id" | "connectionId" | "database" | "children">, tablespaces: readonly XuguTablespaceInfo[]): TreeNode[] {
const existing = new Map((parent.children ?? []).map((child) => [child.id, child] as const));
return tablespaces.map((tablespace) => {
const tablespaceId = `${parent.id}:tablespace:${tablespace.space_id}`;
const previousTablespace = existing.get(tablespaceId);
const filesGroupId = `${tablespaceId}:files`;
const previousFilesGroup = previousTablespace?.children?.find((child) => child.id === filesGroupId);
const fileNodes = tablespace.datafiles.map((file) => ({
id: `${filesGroupId}:${file.file_no}:${file.path}`,
label: xuguDatafileDisplayName(file.path, file.file_no),
type: "datafile" as const,
connectionId: parent.connectionId,
database: parent.database,
objectName: file.path,
xuguDatafilePath: file.path,
comment: file.path,
}));
const filesGroup: TreeNode = {
id: filesGroupId,
label: "tree.xuguDatafiles",
type: "group-datafiles",
connectionId: parent.connectionId,
database: parent.database,
objectCount: fileNodes.length,
isExpanded: previousFilesGroup?.isExpanded ?? false,
children: fileNodes,
};
return {
id: tablespaceId,
label: tablespace.space_name,
type: "tablespace" as const,
connectionId: parent.connectionId,
database: parent.database,
objectName: tablespace.space_name,
xuguTablespace: tablespace,
objectCount: tablespace.datafiles.length,
isExpanded: previousTablespace?.isExpanded ?? false,
children: [filesGroup],
} satisfies TreeNode;
});
}