fix(kingbase): preserve table comments and schema expansion
This commit is contained in:
5 files changed
+124
-32
No files matched your search
@@ -123,6 +123,66 @@ describe("connectionStore metadata loading", () => {
|
||||
expect(schemaNode.children?.map((node) => node.label)).toEqual(["users"]);
|
||||
});
|
||||
|
||||
it("keeps an expanding schema attached while its parent refreshes", async () => {
|
||||
const listSchemaInfos = vi.fn().mockResolvedValue([{ name: "core", comment: null }]);
|
||||
|
||||
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||
vi.doMock("@/lib/backend/api", () => ({
|
||||
checkConnectionHealth: vi.fn().mockResolvedValue(undefined),
|
||||
deleteSchemaCachePrefix: vi.fn().mockResolvedValue(undefined),
|
||||
listSchemaInfos,
|
||||
loadSchemaCache: vi.fn().mockResolvedValue(null),
|
||||
saveSchemaCache: vi.fn().mockResolvedValue(undefined),
|
||||
saveConnections: vi.fn().mockResolvedValue(undefined),
|
||||
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
|
||||
}));
|
||||
|
||||
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||
const store = useConnectionStore();
|
||||
const connection = postgresConnection();
|
||||
const schemaNode: TreeNode = {
|
||||
id: "pg-1:app:core",
|
||||
label: "core",
|
||||
type: "schema",
|
||||
connectionId: connection.id,
|
||||
database: "app",
|
||||
schema: "core",
|
||||
isExpanded: true,
|
||||
isLoading: true,
|
||||
children: [],
|
||||
};
|
||||
store.connections = [connection];
|
||||
store.connectedIds.add(connection.id);
|
||||
store.treeNodes = [
|
||||
{
|
||||
id: connection.id,
|
||||
label: connection.name,
|
||||
type: "connection",
|
||||
connectionId: connection.id,
|
||||
isExpanded: true,
|
||||
children: [
|
||||
{
|
||||
id: "pg-1:app",
|
||||
label: "app",
|
||||
type: "database",
|
||||
connectionId: connection.id,
|
||||
database: "app",
|
||||
isExpanded: true,
|
||||
children: [schemaNode],
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const storedSchema = store.treeNodes[0].children?.[0].children?.[0];
|
||||
await store.loadSchemas(connection.id, "app", { force: true });
|
||||
|
||||
const refreshedSchema = store.treeNodes[0].children?.[0].children?.[0];
|
||||
expect(refreshedSchema).toBe(storedSchema);
|
||||
expect(refreshedSchema?.isExpanded).toBe(true);
|
||||
expect(refreshedSchema?.isLoading).toBe(true);
|
||||
});
|
||||
|
||||
it("paginates procedure groups and appends the next page", async () => {
|
||||
const firstPage = Array.from({ length: 201 }, (_, index) => procedure(`p_${String(index + 1).padStart(4, "0")}`));
|
||||
const listObjects = vi
|
||||
|
||||
@@ -18,7 +18,7 @@ import type {
|
||||
TunnelProfile,
|
||||
VectorCollectionMeta,
|
||||
} from "@/types/database";
|
||||
import { applyPinnedTreeNodeState, inheritNaturalTreeNodeOrder, migrateLegacyPinnedTreeNodeIds, syncPinnedTreeNodeStateInPlace, treeNodePinKey } from "@/lib/app/pinnedItems";
|
||||
import { inheritNaturalTreeNodeOrder, migrateLegacyPinnedTreeNodeIds, syncPinnedTreeNodeStateInPlace, treeNodePinKey } from "@/lib/app/pinnedItems";
|
||||
import {
|
||||
reconcileLayout,
|
||||
buildTreeNodesFromLayout,
|
||||
@@ -989,7 +989,17 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
const oldMap = new Map(parent.children.map((c) => [c.id, c] as const));
|
||||
children = children.map((child) => {
|
||||
const old = oldMap.get(child.id);
|
||||
if (old && old.isExpanded && old.children && old.children.length > 0) {
|
||||
if (old?.isLoading) {
|
||||
const isExpanded = old.isExpanded;
|
||||
const isLoading = old.isLoading;
|
||||
const oldChildren = old.children;
|
||||
Object.assign(old, child);
|
||||
old.isExpanded = isExpanded;
|
||||
old.isLoading = isLoading;
|
||||
old.children = oldChildren;
|
||||
return old;
|
||||
}
|
||||
if (old?.isExpanded) {
|
||||
return { ...child, isExpanded: true, children: old.children };
|
||||
}
|
||||
return child;
|
||||
@@ -1000,7 +1010,8 @@ export const useConnectionStore = defineStore("connection", () => {
|
||||
pinnedTreeNodeIds.value = migratedPins.ids;
|
||||
persistPinnedTreeNodeIds();
|
||||
}
|
||||
parent.children = markRawLeafTreeNodes(applyPinnedTreeNodeState(children, migratedPins.ids));
|
||||
syncPinnedTreeNodeStateInPlace(children, migratedPins.ids);
|
||||
parent.children = markRawLeafTreeNodes(children);
|
||||
loadedTreeNodeChildrenIds.value.add(parent.id);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user