fix(xugu): preserve type members during refresh
This commit is contained in:
1 parent
50607826d0
commit
90af026193
2 files changed
+51
-4
No files matched your search
@@ -188,7 +188,7 @@ describe("connectionStore metadata loading", () => {
|
|||||||
database: "app_db",
|
database: "app_db",
|
||||||
schema: "app_schema",
|
schema: "app_schema",
|
||||||
children: [],
|
children: [],
|
||||||
isExpanded: false,
|
isExpanded: true,
|
||||||
};
|
};
|
||||||
store.connections = [connection];
|
store.connections = [connection];
|
||||||
store.connectedIds = new Set([connection.id]);
|
store.connectedIds = new Set([connection.id]);
|
||||||
@@ -301,6 +301,48 @@ describe("connectionStore metadata loading", () => {
|
|||||||
expect(typeNode.children?.every((child) => child.parentName === "ADDRESS_T")).toBe(true);
|
expect(typeNode.children?.every((child) => child.parentName === "ADDRESS_T")).toBe(true);
|
||||||
}, 15000);
|
}, 15000);
|
||||||
|
|
||||||
|
it("keeps expanded Xugu type members loaded during forced tree refresh", async () => {
|
||||||
|
const completionAssistantSearch = vi.fn(async (request: { object_kinds?: string[] }) => ({
|
||||||
|
candidates: request.object_kinds?.includes("column") ? [{ name: "street", kind: "column", data_type: "VARCHAR(120)" }] : [],
|
||||||
|
incomplete: false,
|
||||||
|
fallback_used: false,
|
||||||
|
}));
|
||||||
|
const getCustomTypeDetails = vi.fn().mockRejectedValue(new Error("custom type loader must not be called for Xugu types"));
|
||||||
|
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||||
|
vi.doMock("@/lib/backend/api", () => ({
|
||||||
|
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||||
|
completionAssistantSearch,
|
||||||
|
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
|
||||||
|
getCustomTypeDetails,
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||||
|
const store = useConnectionStore();
|
||||||
|
const connection = xuguConnection();
|
||||||
|
const typeNode: TreeNode = {
|
||||||
|
id: "xugu-1:app_db:app_schema:type:address_t",
|
||||||
|
label: "ADDRESS_T",
|
||||||
|
type: "type",
|
||||||
|
objectName: "ADDRESS_T",
|
||||||
|
connectionId: connection.id,
|
||||||
|
database: "app_db",
|
||||||
|
schema: "app_schema",
|
||||||
|
xuguTypeMembersExpandable: true,
|
||||||
|
children: [],
|
||||||
|
isExpanded: false,
|
||||||
|
};
|
||||||
|
store.connections = [connection];
|
||||||
|
store.connectedIds = new Set([connection.id]);
|
||||||
|
store.treeNodes = [typeNode];
|
||||||
|
|
||||||
|
await store.refreshTreeNode(typeNode);
|
||||||
|
|
||||||
|
expect(getCustomTypeDetails).not.toHaveBeenCalled();
|
||||||
|
expect(completionAssistantSearch).toHaveBeenCalledTimes(2);
|
||||||
|
expect(typeNode.children?.map((child) => [child.type, child.objectCount])).toEqual([["type-attributes", 1]]);
|
||||||
|
expect(typeNode.isExpanded).toBe(true);
|
||||||
|
}, 15000);
|
||||||
|
|
||||||
it("hides the Xugu type expander after loading no members", async () => {
|
it("hides the Xugu type expander after loading no members", async () => {
|
||||||
const completionAssistantSearch = vi.fn().mockResolvedValue({ candidates: [], incomplete: false, fallback_used: false });
|
const completionAssistantSearch = vi.fn().mockResolvedValue({ candidates: [], incomplete: false, fallback_used: false });
|
||||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||||
|
|||||||
@@ -6119,6 +6119,11 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
await loadTables(node.connectionId, node.database, node.schema, options);
|
await loadTables(node.connectionId, node.database, node.schema, options);
|
||||||
} else if ((node.type === "table" || node.type === "view" || node.type === "materialized_view") && node.connectionId && hasTreeNodeDatabaseContext(node)) {
|
} else if ((node.type === "table" || node.type === "view" || node.type === "materialized_view") && node.connectionId && hasTreeNodeDatabaseContext(node)) {
|
||||||
await loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id, node.catalog);
|
await loadTableGroups(node.connectionId, node.database, node.label, node.schema, node.id, node.catalog);
|
||||||
|
} else if (node.type === "type" && isXuguTypeMemberContainer(node, getConfig(node.connectionId || "")?.db_type)) {
|
||||||
|
// Xugu object types expose attributes and methods through the scoped
|
||||||
|
// completion endpoint. Do not route them through the generic custom-type
|
||||||
|
// loader, which treats the type name as a table and issues getColumns.
|
||||||
|
await loadXuguTypeMembers(node, options);
|
||||||
} else if (node.type === "type") {
|
} else if (node.type === "type") {
|
||||||
await loadCustomTypeChildren(node, options);
|
await loadCustomTypeChildren(node, options);
|
||||||
} else if (node.type === "group-columns" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {
|
} else if (node.type === "group-columns" && node.connectionId && hasTreeNodeDatabaseContext(node) && node.tableName) {
|
||||||
@@ -6447,17 +6452,17 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function loadXuguTypeMembers(node: TreeNode, options?: Pick<LoadTreeOptions, "preserveCollapsedChildren">): Promise<void> {
|
async function loadXuguTypeMembers(node: TreeNode, options?: Pick<LoadTreeOptions, "force" | "preserveCollapsedChildren">): Promise<void> {
|
||||||
if (!isXuguTypeMemberContainer(node, getConfig(node.connectionId || "")?.db_type)) return;
|
if (!isXuguTypeMemberContainer(node, getConfig(node.connectionId || "")?.db_type)) return;
|
||||||
const connectionId = node.connectionId;
|
const connectionId = node.connectionId;
|
||||||
const database = node.database;
|
const database = node.database;
|
||||||
if (!connectionId || !database) return;
|
if (!connectionId || !database) return;
|
||||||
if (node.isExpanded) {
|
if (node.isExpanded && !options?.force) {
|
||||||
node.isExpanded = false;
|
node.isExpanded = false;
|
||||||
if (!sidebarSearchQuery.value && !options?.preserveCollapsedChildren) releaseCollapsedTreeNodeChildren(node.id);
|
if (!sidebarSearchQuery.value && !options?.preserveCollapsedChildren) releaseCollapsedTreeNodeChildren(node.id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (node.children && node.children.length > 0) {
|
if (!options?.force && node.children && node.children.length > 0) {
|
||||||
node.isExpanded = true;
|
node.isExpanded = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user