diff --git a/docs/docs/releasenotes.mdx b/docs/docs/releasenotes.mdx index 2adee9f4e..2b540802e 100644 --- a/docs/docs/releasenotes.mdx +++ b/docs/docs/releasenotes.mdx @@ -24,6 +24,7 @@ Wave Terminal v0.10.0 introduces workspaces, making it easier to manage multiple - [bugfix] Fixed tab flickering issues during tab switches - [bugfix] Corrected WaveAI text area resize behavior - [bugfix] Fixed concurrent block controller start issues +- [bugfix] Fixed Preview Blocks for uninitialized connections - Upgraded Go toolchain to 1.23.4 - Other bug fixes, performance improvements, and dependency updates diff --git a/frontend/app/view/preview/preview.tsx b/frontend/app/view/preview/preview.tsx index 618ad100f..3a5c1e1bd 100644 --- a/frontend/app/view/preview/preview.tsx +++ b/frontend/app/view/preview/preview.tsx @@ -128,7 +128,7 @@ export class PreviewModel implements ViewModel { normFilePath: Atom>; loadableStatFilePath: Atom>; loadableFileInfo: Atom>; - connection: Atom; + connection: Atom>; statFile: Atom>; fullFile: Atom>; fileMimeType: Atom>; @@ -136,6 +136,7 @@ export class PreviewModel implements ViewModel { fileContentSaved: PrimitiveAtom; fileContent: WritableAtom, [string], void>; newFileContent: PrimitiveAtom; + connectionError: PrimitiveAtom; openFileModal: PrimitiveAtom; openFileError: PrimitiveAtom; @@ -167,6 +168,7 @@ export class PreviewModel implements ViewModel { this.markdownShowToc = atom(false); this.filterOutNowsh = atom(true); this.monacoRef = createRef(); + this.connectionError = atom(""); this.viewIcon = atom((get) => { const blockData = get(this.blockAtom); if (blockData?.meta?.icon) { @@ -359,15 +361,22 @@ export class PreviewModel implements ViewModel { return fileInfo.dir + "/" + fileInfo.name; }); this.loadableStatFilePath = loadable(this.statFilePath); - this.connection = atom((get) => { - return get(this.blockAtom)?.meta?.connection; + this.connection = atom>(async (get) => { + const connName = get(this.blockAtom)?.meta?.connection; + try { + await RpcApi.ConnEnsureCommand(TabRpcClient, connName, { timeout: 60000 }); + globalStore.set(this.connectionError, ""); + } catch (e) { + globalStore.set(this.connectionError, e as string); + } + return connName; }); this.statFile = atom>(async (get) => { const fileName = get(this.metaFilePath); if (fileName == null) { return null; } - const conn = get(this.connection) ?? ""; + const conn = (await get(this.connection)) ?? ""; const statFile = await services.FileService.StatFile(conn, fileName); return statFile; }); @@ -384,7 +393,7 @@ export class PreviewModel implements ViewModel { if (fileName == null) { return null; } - const conn = get(this.connection) ?? ""; + const conn = (await get(this.connection)) ?? ""; const file = await services.FileService.ReadFile(conn, fileName); return file; }); @@ -434,10 +443,14 @@ export class PreviewModel implements ViewModel { const mimeType = await getFn(this.fileMimeType); const fileInfo = await getFn(this.statFile); const fileName = await getFn(this.statFilePath); + const connErr = getFn(this.connectionError); const editMode = getFn(this.editMode); const parentFileInfo = await this.getParentInfo(fileInfo); console.log(parentFileInfo); + if (connErr != "") { + return { errorStr: `Connection Error: ${connErr}` }; + } if (parentFileInfo?.notfound ?? false) { return { errorStr: `Parent Directory Not Found: ${fileInfo.path}` }; } @@ -505,7 +518,7 @@ export class PreviewModel implements ViewModel { } async getParentInfo(fileInfo: FileInfo): Promise { - const conn = globalStore.get(this.connection); + const conn = await globalStore.get(this.connection); try { const parentFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], { route: makeConnRoute(conn), @@ -526,7 +539,7 @@ export class PreviewModel implements ViewModel { this.updateOpenFileModalAndError(false); return true; } - const conn = globalStore.get(this.connection); + const conn = await globalStore.get(this.connection); try { const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.path, ".."], { route: makeConnRoute(conn), @@ -586,7 +599,7 @@ export class PreviewModel implements ViewModel { console.log("not saving file, newFileContent is null"); return; } - const conn = globalStore.get(this.connection) ?? ""; + const conn = (await globalStore.get(this.connection)) ?? ""; try { await services.FileService.SaveFile(conn, filePath, stringToBase64(newFileContent)); globalStore.set(this.fileContent, newFileContent); @@ -609,7 +622,7 @@ export class PreviewModel implements ViewModel { this.updateOpenFileModalAndError(false); return true; } - const conn = globalStore.get(this.connection); + const conn = await globalStore.get(this.connection); try { const newFileInfo = await RpcApi.RemoteFileJoinCommand(TabRpcClient, [fileInfo.dir, filePath], { route: makeConnRoute(conn),