mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-03-06 18:07:11 +00:00
Not wroking code
This commit is contained in:
parent
76742455bf
commit
78c8df0904
33
package-lock.json
generated
33
package-lock.json
generated
@ -14042,17 +14042,6 @@
|
||||
"version": "1.12.0",
|
||||
"license": "MIT"
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.7.9",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"node_modules/babel-core": {
|
||||
"version": "7.0.0-bridge.0",
|
||||
"dev": true,
|
||||
@ -31155,12 +31144,6 @@
|
||||
"node": ">= 0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/prr": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
@ -46813,16 +46796,6 @@
|
||||
"aws4": {
|
||||
"version": "1.12.0"
|
||||
},
|
||||
"axios": {
|
||||
"version": "https://registry.npmjs.org/axios/-/axios-1.7.9.tgz",
|
||||
"integrity": "sha512-LhLcE7Hbiryz8oMDdDptSrWowmB4Bl6RCt6sIJKpRB4XtVf0iEgewX3au/pJqm+Py1kCASkb/FFKjxQaLtxJvw==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
},
|
||||
"babel-core": {
|
||||
"version": "7.0.0-bridge.0",
|
||||
"dev": true,
|
||||
@ -58547,12 +58520,6 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"proxy-from-env": {
|
||||
"version": "1.1.0",
|
||||
"resolved": "https://registry.npmjs.org/proxy-from-env/-/proxy-from-env-1.1.0.tgz",
|
||||
"integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==",
|
||||
"dev": true
|
||||
},
|
||||
"prr": {
|
||||
"version": "1.0.1",
|
||||
"dev": true,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as msal from "@azure/msal-browser";
|
||||
import { Link } from "@fluentui/react/lib/Link";
|
||||
import { Panel, Widget } from "@phosphor/widgets";
|
||||
import { isPublicInternetAccessAllowed } from "Common/DatabaseAccountUtility";
|
||||
import { Environment, getEnvironment } from "Common/EnvironmentUtility";
|
||||
import { sendMessage } from "Common/MessageHandler";
|
||||
@ -17,18 +18,19 @@ import { useQueryCopilot } from "hooks/useQueryCopilot";
|
||||
import * as ko from "knockout";
|
||||
import React from "react";
|
||||
import _ from "underscore";
|
||||
import { Terminal as XTerminal } from 'xterm';
|
||||
import shallow from "zustand/shallow";
|
||||
import { AuthType } from "../AuthType";
|
||||
import { BindingHandlersRegisterer } from "../Bindings/BindingHandlersRegisterer";
|
||||
import * as Constants from "../Common/Constants";
|
||||
import { Areas, ConnectionStatusType, HttpStatusCodes, Notebook, PoolIdType } from "../Common/Constants";
|
||||
import { ConnectionStatusType, Notebook, PoolIdType } from "../Common/Constants";
|
||||
import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHandlingUtils";
|
||||
import * as Logger from "../Common/Logger";
|
||||
import { QueriesClient } from "../Common/QueriesClient";
|
||||
import { readCollection, readSampleCollection } from "../Common/dataAccess/readCollection";
|
||||
import { readDatabases } from "../Common/dataAccess/readDatabases";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import { ContainerConnectionInfo, IPhoenixServiceInfo, IProvisionData, IResponse } from "../Contracts/DataModels";
|
||||
import { IPhoenixServiceInfo, IResponse } from "../Contracts/DataModels";
|
||||
import * as ViewModels from "../Contracts/ViewModels";
|
||||
import { GitHubOAuthService } from "../GitHub/GitHubOAuthService";
|
||||
import { PhoenixClient } from "../Phoenix/PhoenixClient";
|
||||
@ -377,87 +379,87 @@ export default class Explorer {
|
||||
}
|
||||
|
||||
public async allocateContainer(poolId: PoolIdType, mode?: string): Promise<void> {
|
||||
const shouldUseNotebookStates = poolId === PoolIdType.DefaultPoolId ? true : false;
|
||||
const notebookServerInfo = shouldUseNotebookStates
|
||||
? useNotebook.getState().notebookServerInfo
|
||||
: useQueryCopilot.getState().notebookServerInfo;
|
||||
// const shouldUseNotebookStates = poolId === PoolIdType.DefaultPoolId ? true : false;
|
||||
// const notebookServerInfo = shouldUseNotebookStates
|
||||
// ? useNotebook.getState().notebookServerInfo
|
||||
// : useQueryCopilot.getState().notebookServerInfo;
|
||||
|
||||
const isAllocating = shouldUseNotebookStates
|
||||
? useNotebook.getState().isAllocating
|
||||
: useQueryCopilot.getState().isAllocatingContainer;
|
||||
if (
|
||||
isAllocating === false &&
|
||||
(notebookServerInfo === undefined ||
|
||||
(notebookServerInfo && notebookServerInfo.notebookServerEndpoint === undefined))
|
||||
) {
|
||||
const connectionStatus: ContainerConnectionInfo = {
|
||||
status: ConnectionStatusType.Connecting,
|
||||
};
|
||||
// const isAllocating = shouldUseNotebookStates
|
||||
// ? useNotebook.getState().isAllocating
|
||||
// : useQueryCopilot.getState().isAllocatingContainer;
|
||||
// if (
|
||||
// isAllocating === false &&
|
||||
// (notebookServerInfo === undefined ||
|
||||
// (notebookServerInfo && notebookServerInfo.notebookServerEndpoint === undefined))
|
||||
// ) {
|
||||
// const connectionStatus: ContainerConnectionInfo = {
|
||||
// status: ConnectionStatusType.Connecting,
|
||||
// };
|
||||
|
||||
shouldUseNotebookStates && useNotebook.getState().setConnectionInfo(connectionStatus);
|
||||
// shouldUseNotebookStates && useNotebook.getState().setConnectionInfo(connectionStatus);
|
||||
|
||||
let connectionInfo;
|
||||
let provisionData: IProvisionData;
|
||||
try {
|
||||
TelemetryProcessor.traceStart(Action.PhoenixConnection, {
|
||||
dataExplorerArea: Areas.Notebook,
|
||||
});
|
||||
if (shouldUseNotebookStates) {
|
||||
useNotebook.getState().setIsAllocating(true);
|
||||
provisionData = {
|
||||
cosmosEndpoint: userContext?.databaseAccount?.properties?.documentEndpoint,
|
||||
poolId: undefined,
|
||||
};
|
||||
} else {
|
||||
useQueryCopilot.getState().setIsAllocatingContainer(true);
|
||||
provisionData = {
|
||||
poolId: poolId,
|
||||
databaseId: useTabs.getState().activeTab.collection.databaseId,
|
||||
containerId: useTabs.getState().activeTab.collection.id(),
|
||||
mode: mode,
|
||||
};
|
||||
}
|
||||
connectionInfo = await this.phoenixClient.allocateContainer(provisionData);
|
||||
if (!connectionInfo?.data?.phoenixServiceUrl) {
|
||||
throw new Error(`PhoenixServiceUrl is invalid!`);
|
||||
}
|
||||
await this.setNotebookInfo(shouldUseNotebookStates, connectionInfo, connectionStatus);
|
||||
TelemetryProcessor.traceSuccess(Action.PhoenixConnection, {
|
||||
dataExplorerArea: Areas.Notebook,
|
||||
});
|
||||
} catch (error) {
|
||||
TelemetryProcessor.traceFailure(Action.PhoenixConnection, {
|
||||
dataExplorerArea: Areas.Notebook,
|
||||
status: error.status,
|
||||
error: getErrorMessage(error),
|
||||
errorStack: getErrorStack(error),
|
||||
});
|
||||
if (shouldUseNotebookStates) {
|
||||
connectionStatus.status = ConnectionStatusType.Failed;
|
||||
shouldUseNotebookStates
|
||||
? useNotebook.getState().resetContainerConnection(connectionStatus)
|
||||
: useQueryCopilot.getState().resetContainerConnection();
|
||||
if (error?.status === HttpStatusCodes.Forbidden && error.message) {
|
||||
useDialog.getState().showOkModalDialog("Connection Failed", `${error.message}`);
|
||||
} else {
|
||||
useDialog
|
||||
.getState()
|
||||
.showOkModalDialog(
|
||||
"Connection Failed",
|
||||
"We are unable to connect to the temporary workspace. Please try again in a few minutes. If the error persists, file a support ticket.",
|
||||
);
|
||||
}
|
||||
}
|
||||
throw error;
|
||||
} finally {
|
||||
shouldUseNotebookStates
|
||||
? useNotebook.getState().setIsAllocating(false)
|
||||
: useQueryCopilot.getState().setIsAllocatingContainer(false);
|
||||
this.refreshCommandBarButtons();
|
||||
this.refreshNotebookList();
|
||||
this._isInitializingNotebooks = false;
|
||||
}
|
||||
}
|
||||
// let connectionInfo;
|
||||
// let provisionData: IProvisionData;
|
||||
// try {
|
||||
// TelemetryProcessor.traceStart(Action.PhoenixConnection, {
|
||||
// dataExplorerArea: Areas.Notebook,
|
||||
// });
|
||||
// if (shouldUseNotebookStates) {
|
||||
// useNotebook.getState().setIsAllocating(true);
|
||||
// provisionData = {
|
||||
// cosmosEndpoint: userContext?.databaseAccount?.properties?.documentEndpoint,
|
||||
// poolId: undefined,
|
||||
// };
|
||||
// } else {
|
||||
// useQueryCopilot.getState().setIsAllocatingContainer(true);
|
||||
// provisionData = {
|
||||
// poolId: poolId,
|
||||
// databaseId: useTabs.getState().activeTab.collection.databaseId,
|
||||
// containerId: useTabs.getState().activeTab.collection.id(),
|
||||
// mode: mode,
|
||||
// };
|
||||
// }
|
||||
// // connectionInfo = await this.phoenixClient.allocateContainer(provisionData);
|
||||
// // if (!connectionInfo?.data?.phoenixServiceUrl) {
|
||||
// // throw new Error(`PhoenixServiceUrl is invalid!`);
|
||||
// // }
|
||||
// // await this.setNotebookInfo(shouldUseNotebookStates, connectionInfo, connectionStatus);
|
||||
// // TelemetryProcessor.traceSuccess(Action.PhoenixConnection, {
|
||||
// // dataExplorerArea: Areas.Notebook,
|
||||
// // });
|
||||
// } catch (error) {
|
||||
// TelemetryProcessor.traceFailure(Action.PhoenixConnection, {
|
||||
// dataExplorerArea: Areas.Notebook,
|
||||
// status: error.status,
|
||||
// error: getErrorMessage(error),
|
||||
// errorStack: getErrorStack(error),
|
||||
// });
|
||||
// if (shouldUseNotebookStates) {
|
||||
// connectionStatus.status = ConnectionStatusType.Failed;
|
||||
// shouldUseNotebookStates
|
||||
// ? useNotebook.getState().resetContainerConnection(connectionStatus)
|
||||
// : useQueryCopilot.getState().resetContainerConnection();
|
||||
// if (error?.status === HttpStatusCodes.Forbidden && error.message) {
|
||||
// useDialog.getState().showOkModalDialog("Connection Failed", `${error.message}`);
|
||||
// } else {
|
||||
// useDialog
|
||||
// .getState()
|
||||
// .showOkModalDialog(
|
||||
// "Connection Failed",
|
||||
// "We are unable to connect to the temporary workspace. Please try again in a few minutes. If the error persists, file a support ticket.",
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
// throw error;
|
||||
// } finally {
|
||||
// shouldUseNotebookStates
|
||||
// ? useNotebook.getState().setIsAllocating(false)
|
||||
// : useQueryCopilot.getState().setIsAllocatingContainer(false);
|
||||
// this.refreshCommandBarButtons();
|
||||
// this.refreshNotebookList();
|
||||
// this._isInitializingNotebooks = false;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public async setNotebookInfo(
|
||||
@ -907,19 +909,19 @@ export default class Explorer {
|
||||
|
||||
public async openNotebookTerminal(kind: ViewModels.TerminalKind): Promise<void> {
|
||||
if (useNotebook.getState().isPhoenixFeatures) {
|
||||
await this.allocateContainer(PoolIdType.DefaultPoolId);
|
||||
const notebookServerInfo = useNotebook.getState().notebookServerInfo;
|
||||
if (notebookServerInfo && notebookServerInfo.notebookServerEndpoint !== undefined) {
|
||||
this.connectToNotebookTerminal(kind);
|
||||
} else {
|
||||
useDialog
|
||||
.getState()
|
||||
.showOkModalDialog(
|
||||
"Failed to connect",
|
||||
"Failed to connect to temporary workspace. This could happen because of network issues. Please refresh the page and try again.",
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// //await this.allocateContainer(PoolIdType.DefaultPoolId);
|
||||
// //const notebookServerInfo = useNotebook.getState().notebookServerInfo;
|
||||
// // if (notebookServerInfo && notebookServerInfo.notebookServerEndpoint !== undefined) {
|
||||
// this.connectToNotebookTerminal(kind);
|
||||
// // } else {
|
||||
// // useDialog
|
||||
// // .getState()
|
||||
// // .showOkModalDialog(
|
||||
// // "Failed to connect",
|
||||
// // "Failed to connect to temporary workspace. This could happen because of network issues. Please refresh the page and try again.",
|
||||
// // );
|
||||
// // }
|
||||
// } else {
|
||||
this.connectToNotebookTerminal(kind);
|
||||
}
|
||||
}
|
||||
@ -972,6 +974,33 @@ export default class Explorer {
|
||||
});
|
||||
|
||||
useTabs.getState().activateNewTab(newTab);
|
||||
|
||||
const xterminal = new XTerminal();
|
||||
|
||||
// Ensure newTab.node is set to a valid HTMLDivElement
|
||||
if (!newTab.node || !(newTab.node instanceof HTMLDivElement)) {
|
||||
newTab.node = document.createElement('div'); // Create a div if not already set
|
||||
}
|
||||
|
||||
// Ensure the container is an HTMLDivElement
|
||||
const termContainer = newTab.node as unknown as HTMLDivElement;
|
||||
termContainer.style.width = '100%';
|
||||
termContainer.style.height = '100%';
|
||||
|
||||
// Append the container to the tab system if necessary
|
||||
document.body.appendChild(termContainer); // Optional: Add it to the DOM if needed
|
||||
|
||||
// Attach xterm.js to the correct container
|
||||
xterminal.open(termContainer);
|
||||
|
||||
const termWidget = new Widget();
|
||||
termWidget.node.appendChild(termContainer);
|
||||
|
||||
const panel = new Panel();
|
||||
panel.addWidget(termWidget);
|
||||
|
||||
// Write to the terminal
|
||||
xterminal.write('I am new shell');
|
||||
}
|
||||
|
||||
public async openGallery(
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,7 @@ import { IMessage, ITerminalConnection } from "@jupyterlab/services/lib/terminal
|
||||
import "@jupyterlab/terminal/style/index.css";
|
||||
import { MessageTypes } from "Contracts/ExplorerContracts";
|
||||
import postRobot from "post-robot";
|
||||
import { Terminal as XTerminal } from 'xterm';
|
||||
import { HttpHeaders } from "../Common/Constants";
|
||||
import { Action } from "../Shared/Telemetry/TelemetryConstants";
|
||||
import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor";
|
||||
@ -11,7 +12,7 @@ import { JupyterLabAppFactory } from "./JupyterLabAppFactory";
|
||||
import { TerminalProps } from "./TerminalProps";
|
||||
import "./index.css";
|
||||
|
||||
let session: ITerminalConnection | undefined;
|
||||
let session: ITerminalConnection | undefined | XTerminal;
|
||||
|
||||
const createServerSettings = (props: TerminalProps): ServerConnection.ISettings => {
|
||||
let body: BodyInit | undefined;
|
||||
@ -62,7 +63,37 @@ const initTerminal = async (props: TerminalProps): Promise<void> => {
|
||||
|
||||
const serverSettings = createServerSettings(props);
|
||||
|
||||
createTerminalApp(props, serverSettings);
|
||||
//createTerminalApp(props, serverSettings);
|
||||
|
||||
|
||||
const xterminal = new XTerminal();
|
||||
|
||||
// Ensure newTab.node is set to a valid HTMLDivElement
|
||||
if (!newTab.node || !(newTab.node instanceof HTMLDivElement)) {
|
||||
newTab.node = document.createElement('div'); // Create a div if not already set
|
||||
}
|
||||
|
||||
// Ensure the container is an HTMLDivElement
|
||||
const termContainer = newTab.node as unknown as HTMLDivElement;
|
||||
termContainer.style.width = '100%';
|
||||
termContainer.style.height = '100%';
|
||||
|
||||
// Append the container to the tab system if necessary
|
||||
document.body.appendChild(termContainer); // Optional: Add it to the DOM if needed
|
||||
|
||||
// Attach xterm.js to the correct container
|
||||
xterminal.open(termContainer);
|
||||
|
||||
const termWidget = new Widget();
|
||||
termWidget.node.appendChild(termContainer);
|
||||
|
||||
const panel = new Panel();
|
||||
panel.addWidget(termWidget);
|
||||
|
||||
// Write to the terminal
|
||||
xterminal.write('I am new shell');
|
||||
|
||||
session = xterminal;
|
||||
};
|
||||
|
||||
const createTerminalApp = async (props: TerminalProps, serverSettings: ServerConnection.ISettings) => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user