feat(sidebar): group objects by type and add Object Browser context menus (#222)
Sidebar tree now groups database objects into Tables, Views, Procedures, and Functions folders instead of a flat list. Empty groups are hidden and each group shows its item count. Object Browser rows now have right-click context menus with actions like View Data, New Query, View Source, and Drop.
This commit is contained in:
1 parent
76ff987d00
commit
53a45330a6
9 files changed
+407
-27
No files matched your search
@@ -5,6 +5,8 @@ const leafTypes: Set<TreeNodeType> = new Set([
|
||||
"index",
|
||||
"fkey",
|
||||
"trigger",
|
||||
"procedure",
|
||||
"function",
|
||||
"object-browser",
|
||||
"redis-db",
|
||||
"mongo-collection",
|
||||
|
||||
+84
-1
@@ -1,4 +1,4 @@
|
||||
import type { TableInfo, TreeNode } from "@/types/database";
|
||||
import type { ObjectInfo, TableInfo, TreeNode, TreeNodeType } from "@/types/database";
|
||||
|
||||
export function buildTableTreeNodes({
|
||||
nodeId,
|
||||
@@ -25,6 +25,89 @@ export function buildTableTreeNodes({
|
||||
}));
|
||||
}
|
||||
|
||||
function normalizeObjectType(type: string): "TABLE" | "VIEW" | "PROCEDURE" | "FUNCTION" {
|
||||
const v = type.toUpperCase();
|
||||
if (v.includes("VIEW")) return "VIEW";
|
||||
if (v.includes("PROC")) return "PROCEDURE";
|
||||
if (v.includes("FUNC")) return "FUNCTION";
|
||||
return "TABLE";
|
||||
}
|
||||
|
||||
const groupDefs: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
objectType: string;
|
||||
nodeType: TreeNodeType;
|
||||
childType: TreeNodeType;
|
||||
}> = [
|
||||
{ key: "__tables", label: "tree.tables", objectType: "TABLE", nodeType: "group-tables", childType: "table" },
|
||||
{ key: "__views", label: "tree.views", objectType: "VIEW", nodeType: "group-views", childType: "view" },
|
||||
{
|
||||
key: "__procedures",
|
||||
label: "tree.procedures",
|
||||
objectType: "PROCEDURE",
|
||||
nodeType: "group-procedures",
|
||||
childType: "procedure",
|
||||
},
|
||||
{
|
||||
key: "__functions",
|
||||
label: "tree.functions",
|
||||
objectType: "FUNCTION",
|
||||
nodeType: "group-functions",
|
||||
childType: "function",
|
||||
},
|
||||
];
|
||||
|
||||
export function buildGroupedObjectTreeNodes({
|
||||
nodeId,
|
||||
connectionId,
|
||||
database,
|
||||
schema,
|
||||
objects,
|
||||
}: {
|
||||
nodeId: string;
|
||||
connectionId: string;
|
||||
database: string;
|
||||
schema?: string;
|
||||
objects: ObjectInfo[];
|
||||
}): TreeNode[] {
|
||||
const buckets = new Map<string, ObjectInfo[]>();
|
||||
for (const obj of objects) {
|
||||
const t = normalizeObjectType(obj.object_type);
|
||||
const arr = buckets.get(t) ?? [];
|
||||
arr.push(obj);
|
||||
buckets.set(t, arr);
|
||||
}
|
||||
|
||||
const groups: TreeNode[] = [];
|
||||
for (const def of groupDefs) {
|
||||
const items = buckets.get(def.objectType);
|
||||
if (!items?.length) continue;
|
||||
const isExpandable = def.childType === "table" || def.childType === "view";
|
||||
groups.push({
|
||||
id: `${nodeId}:${def.key}`,
|
||||
label: def.label,
|
||||
type: def.nodeType,
|
||||
connectionId,
|
||||
database,
|
||||
schema,
|
||||
objectCount: items.length,
|
||||
isExpanded: false,
|
||||
children: items.map((obj) => ({
|
||||
id: `${nodeId}:${obj.name}`,
|
||||
label: obj.name,
|
||||
type: def.childType,
|
||||
connectionId,
|
||||
database,
|
||||
schema,
|
||||
isExpanded: false,
|
||||
children: isExpandable ? [] : undefined,
|
||||
})),
|
||||
});
|
||||
}
|
||||
return groups;
|
||||
}
|
||||
|
||||
export function expandCachedObjectBrowserNodes(nodes: TreeNode[]): TreeNode[] {
|
||||
return nodes.flatMap((node) => {
|
||||
if (node.type === "object-browser") return node.hiddenChildren ?? [];
|
||||
|
||||
Reference in new issue
Block a user