FIxed bugs in JupyterLabAppFactory (#1187)

* initial commit for closing terminal

* added extra case

* lint changes and hostee explorer fixes

* fixed lint errors

* fixed compile error

* fixed review comments

* modified mongo shell logic

* added cassandra hell changes

* fixed compile error
This commit is contained in:
Srinath Narayanan 2022-01-11 04:54:27 -08:00 committed by GitHub
parent b765cae088
commit 79b6f3cf2f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 18 deletions

View File

@ -8,21 +8,33 @@ import { Panel, Widget } from "@phosphor/widgets";
import { userContext } from "UserContext";
export class JupyterLabAppFactory {
private isShellClosed: boolean;
private isShellStarted: boolean | undefined;
private checkShellStarted: ((content: string | undefined) => void) | undefined;
private onShellExited: () => void;
private checkShellClosed: ((content: string | undefined) => boolean | undefined) | undefined;
private isShellExited(content: string | undefined) {
return content?.includes("cosmosuser@");
}
private isMongoShellStarted(content: string | undefined) {
this.isShellStarted = content?.includes("MongoDB shell version");
}
private isCassandraShellStarted(content: string | undefined) {
this.isShellStarted = content?.includes("Connected to") && content?.includes("cqlsh");
}
constructor(closeTab: () => void) {
this.onShellExited = closeTab;
this.isShellClosed = false;
this.checkShellClosed = undefined;
this.isShellStarted = false;
this.checkShellStarted = undefined;
switch (userContext.apiType) {
case "Mongo":
this.checkShellClosed = JupyterLabAppFactory.isMongoShellClosed;
this.checkShellStarted = this.isMongoShellStarted;
break;
case "Cassandra":
this.checkShellClosed = JupyterLabAppFactory.isCassandraShellClosed;
this.checkShellStarted = this.isCassandraShellStarted;
break;
}
}
@ -34,11 +46,12 @@ export class JupyterLabAppFactory {
const session = await manager.startNew();
session.messageReceived.connect(async (_, message: IMessage) => {
const content = message.content && message.content[0]?.toString();
if (this.checkShellClosed && message.type == "stdout") {
if (this.checkShellStarted && message.type == "stdout") {
//Close the terminal tab once the shell closed messages are received
if (this.checkShellClosed(content)) {
this.isShellClosed = true;
} else if (content?.includes("cosmosuser@") && this.isShellClosed) {
if (!this.isShellStarted) {
this.checkShellStarted(content);
} else if (this.isShellExited(content)) {
this.onShellExited();
}
}
@ -71,12 +84,4 @@ export class JupyterLabAppFactory {
panel.dispose();
});
}
private static isMongoShellClosed(content: string | undefined) {
return content?.endsWith("bye\r\n") || (content?.includes("Stopped") && content?.includes("mongo --host"));
}
private static isCassandraShellClosed(content: string | undefined) {
return content == "\r\n" || (content?.includes("Stopped") && content?.includes("cqlsh"));
}
}