fix(sidebar): preserve connection node during metadata refresh
This commit is contained in:
1 parent
6660957153
commit
7b356ddb22
2 files changed
+30
-1
No files matched your search
@@ -74,6 +74,33 @@ describe("connectionStore database info", () => {
|
|||||||
expect(store.connectedIds.has(config.id)).toBe(true);
|
expect(store.connectedIds.has(config.id)).toBe(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preserves the connection tree node while background database info is stored", async () => {
|
||||||
|
const config = mysqlConnection();
|
||||||
|
const saveConnectionDatabaseInfo = vi.fn().mockResolvedValue(undefined);
|
||||||
|
|
||||||
|
vi.doMock("@/lib/backend/tauriRuntime", () => ({ isTauriRuntime: () => false }));
|
||||||
|
vi.doMock("@/lib/backend/api", () => ({
|
||||||
|
connectDb: vi.fn().mockResolvedValue(config.id),
|
||||||
|
connectionDatabaseInfo: vi.fn().mockResolvedValue({ productName: "MySQL", productVersion: "8.0.34" }),
|
||||||
|
saveConnectionDatabaseInfo,
|
||||||
|
saveConnections: vi.fn().mockResolvedValue(undefined),
|
||||||
|
saveSidebarLayout: vi.fn().mockResolvedValue(undefined),
|
||||||
|
connectionIdentifierQuote: vi.fn().mockResolvedValue(undefined),
|
||||||
|
}));
|
||||||
|
|
||||||
|
const { useConnectionStore } = await import("@/stores/connectionStore");
|
||||||
|
const store = useConnectionStore();
|
||||||
|
await store.addConnection(config);
|
||||||
|
const connectionNode = store.treeNodes[0];
|
||||||
|
|
||||||
|
await store.connect(config);
|
||||||
|
await vi.waitFor(() => expect(saveConnectionDatabaseInfo).toHaveBeenCalled());
|
||||||
|
|
||||||
|
expect(store.treeNodes[0]).toBe(connectionNode);
|
||||||
|
expect(store.getConfig(config.id)?.database_info?.productVersion).toBe("8.0.34");
|
||||||
|
expect(store.connectedIds.has(config.id)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
it("does not delay connection success while optional metadata is loading", async () => {
|
it("does not delay connection success while optional metadata is loading", async () => {
|
||||||
const config = mysqlConnection();
|
const config = mysqlConnection();
|
||||||
let resolveDatabaseInfo!: (value: { productName: string; productVersion: string }) => void;
|
let resolveDatabaseInfo!: (value: { productName: string; productVersion: string }) => void;
|
||||||
|
|||||||
@@ -1811,7 +1811,9 @@ export const useConnectionStore = defineStore("connection", () => {
|
|||||||
const nextConnections = [...connections.value];
|
const nextConnections = [...connections.value];
|
||||||
nextConnections[index] = { ...nextConnections[index], database_info: normalized };
|
nextConnections[index] = { ...nextConnections[index], database_info: normalized };
|
||||||
connections.value = nextConnections;
|
connections.value = nextConnections;
|
||||||
rebuildTreeNodes();
|
// Database info is reactive connection metadata, not tree structure. Keep
|
||||||
|
// navigator node identities stable so an in-flight first expansion can
|
||||||
|
// still apply its loaded children after this background refresh completes.
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshConnectedDatabaseInfo(connectionId: string, config: ConnectionConfig): Promise<void> {
|
async function refreshConnectedDatabaseInfo(connectionId: string, config: ConnectionConfig): Promise<void> {
|
||||||
|
|||||||
Reference in new issue
Block a user