mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2024-11-25 23:16:56 +00:00
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:
parent
b765cae088
commit
79b6f3cf2f
@ -8,21 +8,33 @@ import { Panel, Widget } from "@phosphor/widgets";
|
|||||||
import { userContext } from "UserContext";
|
import { userContext } from "UserContext";
|
||||||
|
|
||||||
export class JupyterLabAppFactory {
|
export class JupyterLabAppFactory {
|
||||||
private isShellClosed: boolean;
|
private isShellStarted: boolean | undefined;
|
||||||
|
private checkShellStarted: ((content: string | undefined) => void) | undefined;
|
||||||
private onShellExited: () => void;
|
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) {
|
constructor(closeTab: () => void) {
|
||||||
this.onShellExited = closeTab;
|
this.onShellExited = closeTab;
|
||||||
this.isShellClosed = false;
|
this.isShellStarted = false;
|
||||||
this.checkShellClosed = undefined;
|
this.checkShellStarted = undefined;
|
||||||
|
|
||||||
switch (userContext.apiType) {
|
switch (userContext.apiType) {
|
||||||
case "Mongo":
|
case "Mongo":
|
||||||
this.checkShellClosed = JupyterLabAppFactory.isMongoShellClosed;
|
this.checkShellStarted = this.isMongoShellStarted;
|
||||||
break;
|
break;
|
||||||
case "Cassandra":
|
case "Cassandra":
|
||||||
this.checkShellClosed = JupyterLabAppFactory.isCassandraShellClosed;
|
this.checkShellStarted = this.isCassandraShellStarted;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -34,11 +46,12 @@ export class JupyterLabAppFactory {
|
|||||||
const session = await manager.startNew();
|
const session = await manager.startNew();
|
||||||
session.messageReceived.connect(async (_, message: IMessage) => {
|
session.messageReceived.connect(async (_, message: IMessage) => {
|
||||||
const content = message.content && message.content[0]?.toString();
|
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
|
//Close the terminal tab once the shell closed messages are received
|
||||||
if (this.checkShellClosed(content)) {
|
if (!this.isShellStarted) {
|
||||||
this.isShellClosed = true;
|
this.checkShellStarted(content);
|
||||||
} else if (content?.includes("cosmosuser@") && this.isShellClosed) {
|
} else if (this.isShellExited(content)) {
|
||||||
this.onShellExited();
|
this.onShellExited();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -71,12 +84,4 @@ export class JupyterLabAppFactory {
|
|||||||
panel.dispose();
|
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"));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user