feat(xugu): organize package members and preserve body access

This commit is contained in:
Elias authored and GitHub committed 2026-08-12 10:59:37 +08:00
1 parent e8fae013bd
commit 275b4d5831
9 files changed
+412 -49

No files matched your search

@@ -1744,15 +1744,17 @@ async function refreshDropTableChildObjectPreviewSql() {
dropTableChildObjectPreviewSql.value = options ? await buildDropTableChildObjectSql(options).catch(() => "") : "";
}
function openObjectSourceDialog(initialEditing: boolean) {
function openObjectSourceDialog(initialEditing: boolean, viewPackageBody = false) {
const node = activeNode.value;
if (!node.connectionId || !node.database) return;
if (viewPackageBody && (node.type !== "package" || node.xuguPackageBodyAvailable !== true || currentDatabaseType() !== "xugu")) return;
const sourceNode: TreeNode = viewPackageBody ? { ...node, type: "package-body" } : node;
// TYPE/TYPE_BODY only have a source implementation on Xugu; PostgreSQL-family
// connections list user-defined types without a CREATE TYPE getter this cycle.
if ((node.type === "type" || node.type === "type-body") && !supportsTypeObjectSource(currentDatabaseType())) return;
if ((sourceNode.type === "type" || sourceNode.type === "type-body") && !supportsTypeObjectSource(currentDatabaseType())) return;
const connectionId = node.connectionId;
const database = node.database;
const sourceTarget = objectSourceTargetForTreeNode(node);
const sourceTarget = objectSourceTargetForTreeNode(sourceNode);
if (!sourceTarget) return;
const openMode = settingsStore.editorSettings.routineSourceOpenMode;
if (openMode === "query-tab") {
@@ -1775,7 +1777,7 @@ function openObjectSourceDialog(initialEditing: boolean) {
name: objectName,
objectType: sourceTarget.objectType as any,
databaseType,
signature: node.signature,
signature: sourceNode.signature,
});
const tabId = queryStore.createTab(connectionId, database, `Source - ${node.label}`, "query", schema, editableSource, node.catalog, { forceNew: true });
const sourceIsEditable = raw.editable !== false && !["SEQUENCE", "TRIGGER", "TYPE", "TYPE_BODY"].includes(resolvedType);
@@ -1797,7 +1799,7 @@ function openObjectSourceDialog(initialEditing: boolean) {
.ensureConnected(connectionId)
.then(() => {
connectionStore.activeConnectionId = connectionId;
emit("open-object-source", node, initialEditing);
emit("open-object-source", sourceNode, initialEditing);
})
.catch((e: any) => {
toast(e?.message || String(e), 5000);
@@ -4776,6 +4778,13 @@ function buildObjectSidebarMenu(context: SidebarMenuFactoryContext): boolean {
items.push({ label: t("contextMenu.compileObject"), action: compileXuguObject, icon: Wrench });
}
items.push({ label: t("contextMenu.viewSource"), action: () => openObjectSourceDialog(false), icon: Code2 });
if (node.type === "package" && currentDatabaseType() === "xugu" && node.xuguPackageBodyAvailable === true) {
items.push({
label: `${t("contextMenu.viewSource")} (${t("objects.packageBody")})`,
action: () => openObjectSourceDialog(false, true),
icon: Code2,
});
}
items.push({ label: t("contextMenu.copyName"), action: copyName, icon: Copy, shortcut: shortcutCopyName.value });
items.push({ label: t("contextMenu.changeOpenMode"), action: () => emit("open-settings", "navigation"), icon: Settings2 });
return true;