mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-27 12:51:41 +00:00
- Make sure we pass the error message string instead of an error object when we call `TelemetryProcessor.traceFailure` since TelemetryProcessor will call `JSON.stringify` on the error object which would result in an empty object - Removed ErrorParserUtility since it only works on specific error types. We can just log the full error message and manually derive information we need from the message. - Added option to include stack trace in `getErrorMessage`. This is useful for figuring out where the client side script errors are coming from. - Some minor refactors
114 lines
4.1 KiB
TypeScript
114 lines
4.1 KiB
TypeScript
import * as ViewModels from "../../Contracts/ViewModels";
|
|
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
|
|
import { Areas, KeyCodes } from "../../Common/Constants";
|
|
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
|
|
import { ContextualPaneBase } from "./ContextualPaneBase";
|
|
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
|
|
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
|
|
import * as ko from "knockout";
|
|
import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils";
|
|
|
|
export class SetupNotebooksPane extends ContextualPaneBase {
|
|
private description: ko.Observable<string>;
|
|
|
|
constructor(options: ViewModels.PaneOptions) {
|
|
super(options);
|
|
|
|
this.description = ko.observable<string>();
|
|
this.resetData();
|
|
}
|
|
|
|
public openWithTitleAndDescription(title: string, description: string) {
|
|
this.title(title);
|
|
this.description(description);
|
|
|
|
this.open();
|
|
}
|
|
|
|
public open() {
|
|
super.open();
|
|
const completeSetupBtn = document.getElementById("completeSetupBtn");
|
|
completeSetupBtn && completeSetupBtn.focus();
|
|
}
|
|
|
|
public submit() {
|
|
// override default behavior because this is not a form
|
|
}
|
|
|
|
public onCompleteSetupClick = async (src: any, event: MouseEvent) => {
|
|
await this.setupNotebookWorkspace();
|
|
};
|
|
|
|
public onCompleteSetupKeyPress = async (src: any, event: KeyboardEvent) => {
|
|
if (event.keyCode === KeyCodes.Space || event.keyCode === KeyCodes.Enter) {
|
|
await this.setupNotebookWorkspace();
|
|
event.stopPropagation();
|
|
return false;
|
|
}
|
|
return true;
|
|
};
|
|
|
|
public async setupNotebookWorkspace(): Promise<void> {
|
|
if (!this.container) {
|
|
return;
|
|
}
|
|
|
|
const startKey: number = TelemetryProcessor.traceStart(Action.CreateNotebookWorkspace, {
|
|
databaseAccountName: this.container && this.container.databaseAccount().name,
|
|
defaultExperience: this.container && this.container.defaultExperience(),
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
paneTitle: this.title()
|
|
});
|
|
const id = NotificationConsoleUtils.logConsoleMessage(
|
|
ConsoleDataType.InProgress,
|
|
"Creating a new default notebook workspace"
|
|
);
|
|
try {
|
|
this.isExecuting(true);
|
|
await this.container.notebookWorkspaceManager.createNotebookWorkspaceAsync(
|
|
this.container.databaseAccount() && this.container.databaseAccount().id,
|
|
"default"
|
|
);
|
|
this.container.isAccountReady.valueHasMutated(); // re-trigger init notebooks
|
|
this.close();
|
|
TelemetryProcessor.traceSuccess(
|
|
Action.CreateNotebookWorkspace,
|
|
{
|
|
databaseAccountName: this.container && this.container.databaseAccount().name,
|
|
defaultExperience: this.container && this.container.defaultExperience(),
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
paneTitle: this.title()
|
|
},
|
|
startKey
|
|
);
|
|
NotificationConsoleUtils.logConsoleMessage(
|
|
ConsoleDataType.Info,
|
|
"Successfully created a default notebook workspace for the account"
|
|
);
|
|
} catch (error) {
|
|
const errorMessage = getErrorMessage(error);
|
|
TelemetryProcessor.traceFailure(
|
|
Action.CreateNotebookWorkspace,
|
|
{
|
|
databaseAccountName: this.container && this.container.databaseAccount().name,
|
|
defaultExperience: this.container && this.container.defaultExperience(),
|
|
dataExplorerArea: Areas.ContextualPane,
|
|
paneTitle: this.title(),
|
|
error: errorMessage,
|
|
errorStack: getErrorStack(error)
|
|
},
|
|
startKey
|
|
);
|
|
this.formErrors("Failed to setup a default notebook workspace");
|
|
this.formErrorsDetails(`Failed to setup a default notebook workspace: ${errorMessage}`);
|
|
NotificationConsoleUtils.logConsoleMessage(
|
|
ConsoleDataType.Error,
|
|
`Failed to create a default notebook workspace: ${errorMessage}`
|
|
);
|
|
} finally {
|
|
this.isExecuting(false);
|
|
NotificationConsoleUtils.clearInProgressMessageWithId(id);
|
|
}
|
|
}
|
|
}
|