Remove deprecated calls to logConsoleMessage (#608)

Co-authored-by: Steve Faulkner <southpolesteve@gmail.com>
This commit is contained in:
Jordi Bunster 2021-04-21 11:52:01 -07:00 committed by GitHub
parent cdd6d32990
commit e49bcc524f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 234 additions and 388 deletions

View File

@ -5,11 +5,10 @@ import { configContext } from "../ConfigContext";
import * as DataModels from "../Contracts/DataModels";
import { MessageTypes } from "../Contracts/ExplorerContracts";
import { Collection } from "../Contracts/ViewModels";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import DocumentId from "../Explorer/Tree/DocumentId";
import * as NotificationConsoleUtils from "../Utils/NotificationConsoleUtils";
import { ApiType, HttpHeaders, HttpStatusCodes } from "./Constants";
import { userContext } from "../UserContext";
import { logConsoleError } from "../Utils/NotificationConsoleUtils";
import { ApiType, HttpHeaders, HttpStatusCodes } from "./Constants";
import { MinimalQueryIterator } from "./IteratorUtilities";
import { sendMessage } from "./MessageHandler";
@ -348,10 +347,7 @@ export function getEndpoint(): string {
async function errorHandling(response: Response, action: string, params: unknown): Promise<void> {
const errorMessage = await response.text();
// Log the error where the user can see it
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error ${action}: ${errorMessage}, Payload: ${JSON.stringify(params)}`
);
logConsoleError(`Error ${action}: ${errorMessage}, Payload: ${JSON.stringify(params)}`);
if (response.status === HttpStatusCodes.Forbidden) {
sendMessage({ type: MessageTypes.ForbiddenError, reason: errorMessage });
return;

View File

@ -1,8 +1,7 @@
import * as ViewModels from "../../Contracts/ViewModels";
import { userContext } from "../../UserContext";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleError, logConsoleInfo } from "../../Utils/NotificationConsoleUtils";
import Explorer from "../Explorer";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import { ContainerSampleGenerator } from "./ContainerSampleGenerator";
export class DataSamplesUtil {
@ -21,18 +20,16 @@ export class DataSamplesUtil {
if (this.hasContainer(databaseName, containerName, this.container.databases())) {
const msg = `The container ${containerName} in database ${databaseName} already exists. Please delete it and retry.`;
this.container.showOkModalDialog(DataSamplesUtil.DialogTitle, msg);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
return;
}
await generator
.createSampleContainerAsync()
.catch((error) =>
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Error creating sample container: ${error}`)
);
.catch((error) => logConsoleError(`Error creating sample container: ${error}`));
const msg = `The sample ${containerName} in database ${databaseName} has been successfully created.`;
this.container.showOkModalDialog(DataSamplesUtil.DialogTitle, msg);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, msg);
logConsoleInfo(msg);
}
/**

View File

@ -36,6 +36,7 @@ import { decryptJWTToken, getAuthorizationHeader } from "../Utils/AuthorizationU
import { stringToBlob } from "../Utils/BlobUtils";
import { fromContentUri, toRawContentUri } from "../Utils/GitHubUtils";
import * as NotificationConsoleUtils from "../Utils/NotificationConsoleUtils";
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../Utils/NotificationConsoleUtils";
import * as PricingUtils from "../Utils/PricingUtils";
import * as ComponentRegisterer from "./ComponentRegisterer";
import { ArcadiaWorkspaceItem } from "./Controls/Arcadia/ArcadiaMenuPicker";
@ -43,7 +44,7 @@ import { CommandButtonComponentProps } from "./Controls/CommandButton/CommandBut
import { DialogProps, TextFieldProps } from "./Controls/Dialog";
import { GalleryTab } from "./Controls/NotebookGallery/GalleryViewerComponent";
import { CommandBarComponentAdapter } from "./Menus/CommandBar/CommandBarComponentAdapter";
import { ConsoleData, ConsoleDataType } from "./Menus/NotificationConsole/NotificationConsoleComponent";
import { ConsoleData } from "./Menus/NotificationConsole/NotificationConsoleComponent";
import * as FileSystemUtil from "./Notebook/FileSystemUtil";
import { NotebookContentItem, NotebookContentItemType } from "./Notebook/NotebookContentItem";
import { NotebookUtil } from "./Notebook/NotebookUtil";
@ -736,8 +737,7 @@ export default class Explorer {
onPrimaryButtonClick: async () => {
const startTime = TelemetryProcessor.traceStart(Action.EnableAzureSynapseLink);
const logId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
const clearInProgressMessage = logConsoleProgress(
"Enabling Azure Synapse Link for this account. This may take a few minutes before you can enable analytical store for this account."
);
this.isSynapseLinkUpdating(true);
@ -755,19 +755,13 @@ export default class Explorer {
},
}
);
NotificationConsoleUtils.clearInProgressMessageWithId(logId);
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
"Enabled Azure Synapse Link for this account"
);
clearInProgressMessage();
logConsoleInfo("Enabled Azure Synapse Link for this account");
TelemetryProcessor.traceSuccess(Action.EnableAzureSynapseLink, {}, startTime);
this.databaseAccount(databaseAccount);
} catch (error) {
NotificationConsoleUtils.clearInProgressMessageWithId(logId);
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Enabling Azure Synapse Link for this account failed. ${getErrorMessage(error)}`
);
clearInProgressMessage();
logConsoleError(`Enabling Azure Synapse Link for this account failed. ${getErrorMessage(error)}`);
TelemetryProcessor.traceFailure(Action.EnableAzureSynapseLink, {}, startTime);
} finally {
this.isSynapseLinkUpdating(false);
@ -894,10 +888,7 @@ export default class Explorer {
},
startKey
);
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error while refreshing databases: ${errorMessage}`
);
logConsoleError(`Error while refreshing databases: ${errorMessage}`);
}
);
@ -1118,20 +1109,20 @@ export default class Explorer {
private _resetNotebookWorkspace = async () => {
this._closeModalDialog();
const id = NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, "Resetting notebook workspace");
const clearInProgressMessage = logConsoleProgress("Resetting notebook workspace");
try {
await this.notebookManager?.notebookClient.resetWorkspace();
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, "Successfully reset notebook workspace");
logConsoleInfo("Successfully reset notebook workspace");
TelemetryProcessor.traceSuccess(Action.ResetNotebookWorkspace);
} catch (error) {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Failed to reset notebook workspace: ${error}`);
logConsoleError(`Failed to reset notebook workspace: ${error}`);
TelemetryProcessor.traceFailure(Action.ResetNotebookWorkspace, {
error: getErrorMessage(error),
errorStack: getErrorStack(error),
});
throw error;
} finally {
NotificationConsoleUtils.clearInProgressMessageWithId(id);
clearInProgressMessage();
}
};
@ -1688,11 +1679,7 @@ export default class Explorer {
clearMessage();
},
(error: any) => {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Could not download notebook ${getErrorMessage(error)}`
);
logConsoleError(`Could not download notebook ${getErrorMessage(error)}`);
clearMessage();
}
);
@ -1844,15 +1831,8 @@ export default class Explorer {
}
return this.notebookManager?.notebookContentClient.deleteContentItem(item).then(
() => {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, `Successfully deleted: ${item.path}`);
},
(reason: any) => {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Failed to delete "${item.path}": ${JSON.stringify(reason)}`
);
}
() => logConsoleInfo(`Successfully deleted: ${item.path}`),
(reason: any) => logConsoleError(`Failed to delete "${item.path}": ${JSON.stringify(reason)}`)
);
}
@ -1868,11 +1848,7 @@ export default class Explorer {
parent = parent || this.resourceTree.myNotebooksContentRoot;
const notificationProgressId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Creating new notebook in ${parent.path}`
);
const clearInProgressMessage = logConsoleProgress(`Creating new notebook in ${parent.path}`);
const startKey: number = TelemetryProcessor.traceStart(Action.CreateNewNotebook, {
dataExplorerArea: Constants.Areas.Notebook,
});
@ -1880,7 +1856,7 @@ export default class Explorer {
this.notebookManager?.notebookContentClient
.createNewNotebookFile(parent)
.then((newFile: NotebookContentItem) => {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, `Successfully created: ${newFile.name}`);
logConsoleInfo(`Successfully created: ${newFile.name}`);
TelemetryProcessor.traceSuccess(
Action.CreateNewNotebook,
{
@ -1893,7 +1869,7 @@ export default class Explorer {
.then(() => this.resourceTree.triggerRender())
.catch((error: any) => {
const errorMessage = `Failed to create a new notebook: ${getErrorMessage(error)}`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, errorMessage);
logConsoleError(errorMessage);
TelemetryProcessor.traceFailure(
Action.CreateNewNotebook,
{
@ -1904,7 +1880,7 @@ export default class Explorer {
startKey
);
})
.finally(() => NotificationConsoleUtils.clearInProgressMessageWithId(notificationProgressId));
.finally(clearInProgressMessage);
}
public refreshContentItem(item: NotebookContentItem): Promise<void> {

View File

@ -1,24 +1,22 @@
import * as ko from "knockout";
import Q from "q";
import { schemeCategory10 } from "d3-scale-chromatic";
import { selectAll, select } from "d3-selection";
import { zoom, zoomIdentity } from "d3-zoom";
import { scaleOrdinal } from "d3-scale";
import { forceSimulation, forceLink, forceCollide, forceManyBody } from "d3-force";
import { interpolateNumber, interpolate } from "d3-interpolate";
import { BaseType } from "d3";
import { map as d3Map } from "d3-collection";
import { drag, D3DragEvent } from "d3-drag";
import { D3DragEvent, drag } from "d3-drag";
import { forceCollide, forceLink, forceManyBody, forceSimulation } from "d3-force";
import { interpolate, interpolateNumber } from "d3-interpolate";
import { scaleOrdinal } from "d3-scale";
import { schemeCategory10 } from "d3-scale-chromatic";
import { select, selectAll } from "d3-selection";
import { zoom, zoomIdentity } from "d3-zoom";
import * as ko from "knockout";
import Q from "q";
import _ from "underscore";
import { NeighborType } from "../../../Contracts/ViewModels";
import { GraphData, D3Node, D3Link } from "./GraphData";
import { HashMap } from "../../../Common/HashMap";
import { BaseType } from "d3";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils";
import { GraphConfig } from "../../Tabs/GraphTab";
import { GraphExplorer } from "./GraphExplorer";
import * as Constants from "../../../Common/Constants";
import { HashMap } from "../../../Common/HashMap";
import { NeighborType } from "../../../Contracts/ViewModels";
import { logConsoleError } from "../../../Utils/NotificationConsoleUtils";
import { GraphConfig } from "../../Tabs/GraphTab";
import { D3Link, D3Node, GraphData } from "./GraphData";
import { GraphExplorer } from "./GraphExplorer";
export interface D3GraphIconMap {
[key: string]: { data: string; format: string };
@ -1005,7 +1003,7 @@ export class D3ForceGraph implements GraphRenderer {
*/
private loadNeighbors(v: D3Node, pageAction: PAGE_ACTION) {
if (!this.graphDataWrapper.hasVertexId(v.id)) {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Clicked node not in graph data. id: ${v.id}`);
logConsoleError(`Clicked node not in graph data. id: ${v.id}`);
return;
}

View File

@ -1,37 +1,36 @@
import { FeedOptions, ItemDefinition, QueryIterator, Resource } from "@azure/cosmos";
import * as Q from "q";
import * as React from "react";
import * as LeftPane from "./LeftPaneComponent";
import { MiddlePaneComponent } from "./MiddlePaneComponent";
import * as InputTypeaheadComponent from "../../Controls/InputTypeahead/InputTypeaheadComponent";
import * as NodeProperties from "./NodePropertiesComponent";
import * as D3ForceGraph from "./D3ForceGraph";
import { GraphVizComponentProps } from "./GraphVizComponent";
import * as GraphData from "./GraphData";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils";
import * as GraphUtil from "./GraphUtil";
import * as DataModels from "../../../Contracts/DataModels";
import * as ViewModels from "../../../Contracts/ViewModels";
import * as GremlinClient from "./GremlinClient";
import * as StorageUtility from "../../../Shared/StorageUtility";
import { ArraysByKeyCache } from "./ArraysByKeyCache";
import { EdgeInfoCache } from "./EdgeInfoCache";
import * as TabComponent from "../../Controls/Tabs/TabComponent";
import { LocalStorageUtility, StorageKey } from "../../../Shared/StorageUtility";
import { QueryContainerComponent } from "./QueryContainerComponent";
import { GraphConfig } from "../../Tabs/GraphTab";
import { EditorReact } from "../../Controls/Editor/EditorReact";
import LoadGraphIcon from "../../../../images/LoadGraph.png";
import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
import * as Constants from "../../../Common/Constants";
import { InputProperty } from "../../../Contracts/ViewModels";
import { QueryIterator, ItemDefinition, Resource } from "@azure/cosmos";
import LoadingIndicatorIcon from "../../../../images/LoadingIndicator_3Squares.gif";
import * as Constants from "../../../Common/Constants";
import { queryDocuments } from "../../../Common/dataAccess/queryDocuments";
import { queryDocumentsPage } from "../../../Common/dataAccess/queryDocumentsPage";
import { getErrorMessage } from "../../../Common/ErrorHandlingUtils";
import { FeedOptions } from "@azure/cosmos";
import * as DataModels from "../../../Contracts/DataModels";
import * as ViewModels from "../../../Contracts/ViewModels";
import { InputProperty } from "../../../Contracts/ViewModels";
import * as StorageUtility from "../../../Shared/StorageUtility";
import { LocalStorageUtility, StorageKey } from "../../../Shared/StorageUtility";
import { Action } from "../../../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../../Utils/NotificationConsoleUtils";
import { EditorReact } from "../../Controls/Editor/EditorReact";
import * as InputTypeaheadComponent from "../../Controls/InputTypeahead/InputTypeaheadComponent";
import * as TabComponent from "../../Controls/Tabs/TabComponent";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import { GraphConfig } from "../../Tabs/GraphTab";
import { ArraysByKeyCache } from "./ArraysByKeyCache";
import * as D3ForceGraph from "./D3ForceGraph";
import { EdgeInfoCache } from "./EdgeInfoCache";
import * as GraphData from "./GraphData";
import * as GraphUtil from "./GraphUtil";
import { GraphVizComponentProps } from "./GraphVizComponent";
import * as GremlinClient from "./GremlinClient";
import * as LeftPane from "./LeftPaneComponent";
import { MiddlePaneComponent } from "./MiddlePaneComponent";
import * as NodeProperties from "./NodePropertiesComponent";
import { QueryContainerComponent } from "./QueryContainerComponent";
export interface GraphAccessor {
applyFilter: () => void;
@ -697,13 +696,13 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
* @param cmd
*/
public submitToBackend(cmd: string): Q.Promise<GremlinClient.GremlinRequestResult> {
const id = GraphExplorer.reportToConsole(ConsoleDataType.InProgress, `Executing: ${cmd}`);
const clearConsoleProgress = GraphExplorer.reportToConsole(ConsoleDataType.InProgress, `Executing: ${cmd}`);
this.setExecuteCounter(this.executeCounter + 1);
return this.gremlinClient.execute(cmd).then(
(result: GremlinClient.GremlinRequestResult) => {
this.setExecuteCounter(this.executeCounter - 1);
GraphExplorer.clearConsoleProgress(id);
clearConsoleProgress();
if (result.isIncomplete) {
const msg = `The query results are too large and only partial results are displayed for: ${cmd}`;
GraphExplorer.reportToConsole(ConsoleDataType.Error, msg);
@ -718,7 +717,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
(err: string) => {
this.setExecuteCounter(this.executeCounter - 1);
GraphExplorer.reportToConsole(ConsoleDataType.Error, `Gremlin query failed: ${cmd}`, err);
GraphExplorer.clearConsoleProgress(id);
clearConsoleProgress();
throw err;
}
);
@ -1083,13 +1082,26 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
* @param errorData additional errors
* @return id
*/
public static reportToConsole(type: ConsoleDataType, msg: string, ...errorData: any[]): string {
public static reportToConsole(type: ConsoleDataType.InProgress, msg: string, ...errorData: any[]): () => void;
public static reportToConsole(type: ConsoleDataType.Info, msg: string, ...errorData: any[]): void;
public static reportToConsole(type: ConsoleDataType.Error, msg: string, ...errorData: any[]): void;
public static reportToConsole(type: ConsoleDataType, msg: string, ...errorData: any[]): void | (() => void) {
let errorDataStr: string = "";
if (errorData && errorData.length > 0) {
console.error(msg, errorData);
errorDataStr = ": " + JSON.stringify(errorData);
}
return NotificationConsoleUtils.logConsoleMessage(type, `${msg}${errorDataStr}`);
const consoleMessage = `${msg}${errorDataStr}`;
switch (type) {
case ConsoleDataType.Error:
return logConsoleError(consoleMessage);
case ConsoleDataType.Info:
return logConsoleInfo(consoleMessage);
case ConsoleDataType.InProgress:
return logConsoleProgress(consoleMessage);
}
}
private setNodePropertiesViewMode(viewMode: NodeProperties.Mode) {
@ -1368,7 +1380,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
let { id } = d;
if (typeof id !== "string") {
const error = `Vertex id is not a string: ${JSON.stringify(id)}.`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, error);
logConsoleError(error);
throw new Error(error);
}
@ -1380,7 +1392,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
pk = pk[0]["_value"];
} else {
const error = `Vertex pk is not a string nor a non-empty array: ${JSON.stringify(pk)}.`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, error);
logConsoleError(error);
throw new Error(error);
}
}
@ -1767,7 +1779,10 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
const queryInfoStr = `${this.currentDocDBQueryInfo.query} (${this.currentDocDBQueryInfo.index + 1}-${
this.currentDocDBQueryInfo.index + GraphExplorer.ROOT_LIST_PAGE_SIZE
})`;
const id = GraphExplorer.reportToConsole(ConsoleDataType.InProgress, `Executing: ${queryInfoStr}`);
const clearConsoleProgress = GraphExplorer.reportToConsole(
ConsoleDataType.InProgress,
`Executing: ${queryInfoStr}`
);
try {
const results: ViewModels.QueryResults = await queryDocumentsPage(
@ -1776,7 +1791,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
this.currentDocDBQueryInfo.index
);
GraphExplorer.clearConsoleProgress(id);
clearConsoleProgress();
this.currentDocDBQueryInfo.index = results.lastItemIndex + 1;
this.setState({ hasMoreRoots: results.hasMoreResults });
RU = results.requestCharge.toString();
@ -1793,7 +1808,7 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
return { requestCharge: RU };
} catch (error) {
GraphExplorer.clearConsoleProgress(id);
clearConsoleProgress();
const errorMsg = `Failed to query: ${this.currentDocDBQueryInfo.query}. Reason:${getErrorMessage(error)}`;
GraphExplorer.reportToConsole(ConsoleDataType.Error, errorMsg);
this.setState({
@ -2003,8 +2018,4 @@ export class GraphExplorer extends React.Component<GraphExplorerProps, GraphExpl
</React.Fragment>
);
}
private static clearConsoleProgress(id: string) {
NotificationConsoleUtils.clearInProgressMessageWithId(id);
}
}

View File

@ -3,11 +3,10 @@
*/
import * as Q from "q";
import { GremlinSimpleClient, Result } from "./GremlinSimpleClient";
import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import { HashMap } from "../../../Common/HashMap";
import { getErrorMessage, handleError } from "../../../Common/ErrorHandlingUtils";
import { HashMap } from "../../../Common/HashMap";
import { logConsoleInfo } from "../../../Utils/NotificationConsoleUtils";
import { GremlinSimpleClient, Result } from "./GremlinSimpleClient";
export interface GremlinClientParameters {
endpoint: string;
@ -77,9 +76,7 @@ export class GremlinClient {
this.abortPendingRequest(requestId, errorMessage, result.requestCharge);
}
},
infoCallback: (msg: string) => {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, msg);
},
infoCallback: logConsoleInfo,
});
}

View File

@ -1,52 +1,49 @@
import { EMPTY, merge, of, timer, concat, Subject, Subscriber, Observable, Observer, from } from "rxjs";
import { webSocket } from "rxjs/webSocket";
import { StateObservable } from "redux-observable";
import { ofType } from "redux-observable";
import {
mergeMap,
tap,
retryWhen,
delayWhen,
map,
switchMap,
take,
filter,
catchError,
first,
concatMap,
timeout,
} from "rxjs/operators";
import {
AppState,
ServerConfig as JupyterServerConfig,
JupyterHostRecordProps,
RemoteKernelProps,
castToSessionId,
createKernelRef,
KernelRef,
ContentRef,
KernelInfo,
actions,
AppState,
castToSessionId,
ContentRef,
createKernelRef,
JupyterHostRecordProps,
KernelInfo,
KernelRef,
RemoteKernelProps,
selectors,
ServerConfig as JupyterServerConfig,
} from "@nteract/core";
import { message, JupyterMessage, Channels, createMessage, childOf, ofMessageType } from "@nteract/messaging";
import { sessions, kernels } from "rx-jupyter";
import { Channels, childOf, createMessage, JupyterMessage, message, ofMessageType } from "@nteract/messaging";
import { RecordOf } from "immutable";
import { AnyAction } from "redux";
import { ofType, StateObservable } from "redux-observable";
import { kernels, sessions } from "rx-jupyter";
import { concat, EMPTY, from, merge, Observable, Observer, of, Subject, Subscriber, timer } from "rxjs";
import {
catchError,
concatMap,
delayWhen,
filter,
first,
map,
mergeMap,
retryWhen,
switchMap,
take,
tap,
timeout,
} from "rxjs/operators";
import { webSocket } from "rxjs/webSocket";
import * as Constants from "../../../Common/Constants";
import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils";
import { ConsoleDataType } from "../../Menus/NotificationConsole/NotificationConsoleComponent";
import * as CdbActions from "./actions";
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
import { Areas } from "../../../Common/Constants";
import { Action as TelemetryAction, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants";
import { CdbAppState } from "./types";
import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor";
import { decryptJWTToken } from "../../../Utils/AuthorizationUtils";
import * as TextFile from "./contents/file/text-file";
import { NotebookUtil } from "../NotebookUtil";
import { logConsoleError, logConsoleInfo } from "../../../Utils/NotificationConsoleUtils";
import * as FileSystemUtil from "../FileSystemUtil";
import * as cdbActions from "../NotebookComponent/actions";
import { Areas } from "../../../Common/Constants";
import { NotebookUtil } from "../NotebookUtil";
import * as CdbActions from "./actions";
import * as TextFile from "./contents/file/text-file";
import { CdbAppState } from "./types";
interface NotebookServiceConfig extends JupyterServerConfig {
userPuid?: string;
@ -311,7 +308,7 @@ export const launchWebSocketKernelEpic = (
if (currentKernelspecs) {
kernelSpecToLaunch = currentKernelspecs.defaultKernelName;
const msg = `No kernelspec name specified to launch, using default kernel: ${kernelSpecToLaunch}`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, msg);
logConsoleInfo(msg);
logFailureToTelemetry(state$.value, "Launching alternate kernel", msg);
} else {
return of(
@ -337,7 +334,7 @@ export const launchWebSocketKernelEpic = (
kernelSpecToLaunch = currentKernelspecs.defaultKernelName;
msg += ` Using default kernel: ${kernelSpecToLaunch}`;
}
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, msg);
logConsoleInfo(msg);
logFailureToTelemetry(state$.value, "Launching alternate kernel", msg);
}
@ -634,7 +631,7 @@ const notificationsToUserEpic = (action$: Observable<any>, state$: StateObservab
case actions.RESTART_KERNEL_SUCCESSFUL: {
const title = "Kernel restart";
const msg = "Kernel successfully restarted";
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, msg);
logConsoleInfo(msg);
logFailureToTelemetry(state$.value, title, msg);
break;
}
@ -645,7 +642,7 @@ const notificationsToUserEpic = (action$: Observable<any>, state$: StateObservab
case actions.SAVE_FAILED: {
const title = "Save failure";
const msg = `Failed to save notebook: ${(action as actions.SaveFailed).payload.error}`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
logFailureToTelemetry(state$.value, title, msg);
break;
}
@ -654,7 +651,7 @@ const notificationsToUserEpic = (action$: Observable<any>, state$: StateObservab
const filepath = selectors.filepath(state$.value, { contentRef: typedAction.payload.contentRef });
const title = "Fetching content failure";
const msg = `Failed to fetch notebook content: ${filepath}, error: ${typedAction.payload.error}`;
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
logFailureToTelemetry(state$.value, title, msg);
break;
}
@ -679,7 +676,7 @@ const handleKernelConnectionLostEpic = (
const state = state$.value;
const msg = "Notebook was disconnected from kernel";
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
logFailureToTelemetry(state, "Error", "Kernel connection error");
const host = selectors.currentHost(state);
@ -692,7 +689,7 @@ const handleKernelConnectionLostEpic = (
if (delayMs > Constants.Notebook.kernelRestartMaxDelayMs) {
const msg =
"Restarted kernel too many times. Please reload the page to enable Data Explorer to restart the kernel automatically.";
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
logFailureToTelemetry(state, "Kernel restart error", msg);
const explorer = window.dataExplorer;
@ -810,7 +807,7 @@ const closeUnsupportedMimetypesEpic = (
);
const msg = `${filepath} cannot be rendered. Please download the file, in order to view it outside of Data Explorer.`;
explorer.showOkModalDialog("File cannot be rendered", msg);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
}
return EMPTY;
})
@ -838,7 +835,7 @@ const closeContentFailedToFetchEpic = (
);
const msg = `Failed to load file: ${filepath}.`;
explorer.showOkModalDialog("Failure to load", msg);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, msg);
logConsoleError(msg);
}
return EMPTY;
})

View File

@ -1,15 +1,14 @@
/**
* Notebook container related stuff
*/
import * as DataModels from "../../Contracts/DataModels";
import * as Constants from "../../Common/Constants";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import * as Logger from "../../Common/Logger";
import { getErrorMessage } from "../../Common/ErrorHandlingUtils";
import * as Logger from "../../Common/Logger";
import * as DataModels from "../../Contracts/DataModels";
import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
export class NotebookContainerClient {
private reconnectingNotificationId: string;
private clearReconnectionAttemptMessage? = () => {};
private isResettingWorkspace: boolean;
constructor(
@ -61,9 +60,9 @@ export class NotebookContainerClient {
},
});
if (response.ok) {
if (this.reconnectingNotificationId) {
NotificationConsoleUtils.clearInProgressMessageWithId(this.reconnectingNotificationId);
this.reconnectingNotificationId = "";
if (this.clearReconnectionAttemptMessage) {
this.clearReconnectionAttemptMessage();
this.clearReconnectionAttemptMessage = undefined;
}
const memoryUsageInfo = await response.json();
if (memoryUsageInfo) {
@ -76,9 +75,8 @@ export class NotebookContainerClient {
return undefined;
} catch (error) {
Logger.logError(getErrorMessage(error), "NotebookContainerClient/getMemoryUsage");
if (!this.reconnectingNotificationId) {
this.reconnectingNotificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
if (!this.clearReconnectionAttemptMessage) {
this.clearReconnectionAttemptMessage = logConsoleProgress(
"Connection lost with Notebook server. Attempting to reconnect..."
);
}

View File

@ -1,9 +1,8 @@
import * as ko from "knockout";
import Q from "q";
import * as ViewModels from "../../Contracts/ViewModels";
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
import { ContextualPaneBase } from "./ContextualPaneBase";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
export interface StringInputPaneOpenOptions {
paneTitle: string;
@ -39,19 +38,13 @@ export class StringInputPane extends ContextualPaneBase {
this.formErrors("");
this.formErrorsDetails("");
const id: string = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`${this.openOptions.inProgressMessage} ${this.stringInput()}`
);
const clearInProgressMessage = logConsoleProgress(`${this.openOptions.inProgressMessage} ${this.stringInput()}`);
this.isExecuting(true);
this.openOptions
.onSubmit(this.stringInput())
.then(
(value: any) => {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`${this.openOptions.successMessage}: ${this.stringInput()}`
);
logConsoleInfo(`${this.openOptions.successMessage}: ${this.stringInput()}`);
this.close();
this.paneDeferred.resolve(value);
},
@ -70,16 +63,13 @@ export class StringInputPane extends ContextualPaneBase {
this.formErrors(this.openOptions.errorMessage);
this.formErrorsDetails(`${this.openOptions.errorMessage}: ${error}`);
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`${this.openOptions.errorMessage} ${this.stringInput()}: ${error}`
);
logConsoleError(`${this.openOptions.errorMessage} ${this.stringInput()}: ${error}`);
this.paneDeferred.reject(error);
}
)
.finally(() => {
this.isExecuting(false);
NotificationConsoleUtils.clearInProgressMessageWithId(id);
clearInProgressMessage();
});
}

View File

@ -1,25 +1,24 @@
import { FeedOptions } from "@azure/cosmos";
import * as ko from "knockout";
import Q from "q";
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
import { AuthType } from "../../AuthType";
import { ConsoleDataType } from "../../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { FeedOptions } from "@azure/cosmos";
import * as Constants from "../../Common/Constants";
import * as Entities from "./Entities";
import * as HeadersUtility from "../../Common/HeadersUtility";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import * as TableConstants from "./Constants";
import * as TableEntityProcessor from "./TableEntityProcessor";
import * as ViewModels from "../../Contracts/ViewModels";
import Explorer from "../Explorer";
import { configContext } from "../../ConfigContext";
import { handleError } from "../../Common/ErrorHandlingUtils";
import { createDocument } from "../../Common/dataAccess/createDocument";
import { deleteDocument } from "../../Common/dataAccess/deleteDocument";
import { queryDocuments } from "../../Common/dataAccess/queryDocuments";
import { updateDocument } from "../../Common/dataAccess/updateDocument";
import { handleError } from "../../Common/ErrorHandlingUtils";
import * as HeadersUtility from "../../Common/HeadersUtility";
import { configContext } from "../../ConfigContext";
import * as ViewModels from "../../Contracts/ViewModels";
import { userContext } from "../../UserContext";
import { getAuthorizationHeader } from "../../Utils/AuthorizationUtils";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
import Explorer from "../Explorer";
import * as TableConstants from "./Constants";
import * as Entities from "./Entities";
import * as TableEntityProcessor from "./TableEntityProcessor";
export interface CassandraTableKeys {
partitionKeys: CassandraTableKey[];
@ -144,10 +143,7 @@ export class CassandraAPIDataClient extends TableDataClient {
collection: ViewModels.Collection,
entity: Entities.ITableEntity
): Q.Promise<Entities.ITableEntity> {
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Adding new row to table ${collection.id()}`
);
const clearInProgressMessage = logConsoleProgress(`Adding new row to table ${collection.id()}`);
let properties = "(";
let values = "(";
for (let property in entity) {
@ -171,7 +167,7 @@ export class CassandraAPIDataClient extends TableDataClient {
(data: any) => {
entity[TableConstants.EntityKeyNames.RowKey] = entity[this.getCassandraPartitionKeyProperty(collection)];
entity[TableConstants.EntityKeyNames.RowKey]._ = entity[TableConstants.EntityKeyNames.RowKey]._.toString();
NotificationConsoleUtils.logConsoleInfo(`Successfully added new row to table ${collection.id()}`);
logConsoleInfo(`Successfully added new row to table ${collection.id()}`);
deferred.resolve(entity);
},
(error) => {
@ -179,9 +175,7 @@ export class CassandraAPIDataClient extends TableDataClient {
deferred.reject(error);
}
)
.finally(() => {
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
});
.finally(clearInProgressMessage);
return deferred.promise;
}
@ -341,17 +335,11 @@ export class CassandraAPIDataClient extends TableDataClient {
}
const deferred: Q.Deferred<any> = Q.defer();
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Creating a new keyspace with query ${createKeyspaceQuery}`
);
const clearInProgressMessage = logConsoleProgress(`Creating a new keyspace with query ${createKeyspaceQuery}`);
this.createOrDeleteQuery(cassandraEndpoint, resourceId, createKeyspaceQuery)
.then(
(data: any) => {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`Successfully created a keyspace with query ${createKeyspaceQuery}`
);
logConsoleInfo(`Successfully created a keyspace with query ${createKeyspaceQuery}`);
deferred.resolve();
},
(error) => {
@ -363,9 +351,7 @@ export class CassandraAPIDataClient extends TableDataClient {
deferred.reject(error);
}
)
.finally(() => {
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
});
.finally(clearInProgressMessage);
return deferred.promise.timeout(Constants.ClientDefaults.requestTimeoutMs);
}
@ -387,17 +373,11 @@ export class CassandraAPIDataClient extends TableDataClient {
const deferred = Q.defer();
createKeyspacePromise.then(
() => {
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Creating a new table with query ${createTableQuery}`
);
const clearInProgressMessage = logConsoleProgress(`Creating a new table with query ${createTableQuery}`);
this.createOrDeleteQuery(cassandraEndpoint, resourceId, createTableQuery)
.then(
(data: any) => {
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`Successfully created a table with query ${createTableQuery}`
);
logConsoleInfo(`Successfully created a table with query ${createTableQuery}`);
deferred.resolve();
},
(error) => {
@ -405,9 +385,7 @@ export class CassandraAPIDataClient extends TableDataClient {
deferred.reject(error);
}
)
.finally(() => {
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
});
.finally(clearInProgressMessage);
},
(reason) => {
deferred.reject(reason);
@ -420,10 +398,7 @@ export class CassandraAPIDataClient extends TableDataClient {
if (!!collection.cassandraKeys) {
return Q.resolve(collection.cassandraKeys);
}
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Fetching keys for table ${collection.id()}`
);
const clearInProgressMessage = logConsoleProgress(`Fetching keys for table ${collection.id()}`);
const authType = userContext.authType;
const apiEndpoint: string =
authType === AuthType.EncryptedToken
@ -448,10 +423,7 @@ export class CassandraAPIDataClient extends TableDataClient {
.then(
(data: CassandraTableKeys) => {
collection.cassandraKeys = data;
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`Successfully fetched keys for table ${collection.id()}`
);
logConsoleInfo(`Successfully fetched keys for table ${collection.id()}`);
deferred.resolve(data);
},
(error: any) => {
@ -459,9 +431,7 @@ export class CassandraAPIDataClient extends TableDataClient {
deferred.reject(error);
}
)
.done(() => {
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
});
.done(clearInProgressMessage);
return deferred.promise;
}
@ -469,10 +439,7 @@ export class CassandraAPIDataClient extends TableDataClient {
if (!!collection.cassandraSchema) {
return Q.resolve(collection.cassandraSchema);
}
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Fetching schema for table ${collection.id()}`
);
const clearInProgressMessage = logConsoleProgress(`Fetching schema for table ${collection.id()}`);
const authType = userContext.authType;
const apiEndpoint: string =
authType === AuthType.EncryptedToken
@ -497,10 +464,7 @@ export class CassandraAPIDataClient extends TableDataClient {
.then(
(data: any) => {
collection.cassandraSchema = data.columns;
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`Successfully fetched schema for table ${collection.id()}`
);
logConsoleInfo(`Successfully fetched schema for table ${collection.id()}`);
deferred.resolve(data.columns);
},
(error: any) => {
@ -508,9 +472,7 @@ export class CassandraAPIDataClient extends TableDataClient {
deferred.reject(error);
}
)
.done(() => {
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
});
.done(clearInProgressMessage);
return deferred.promise;
}

View File

@ -21,11 +21,10 @@ import * as DataModels from "../../Contracts/DataModels";
import * as ViewModels from "../../Contracts/ViewModels";
import { Action } from "../../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleError } from "../../Utils/NotificationConsoleUtils";
import * as QueryUtils from "../../Utils/QueryUtils";
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
import Explorer from "../Explorer";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import { AccessibleVerticalList } from "../Tree/AccessibleVerticalList";
import DocumentId from "../Tree/DocumentId";
import template from "./DocumentsTab.html";
@ -727,7 +726,7 @@ export default class DocumentsTab extends TabsBase {
(error) => {
this.isExecutionError(true);
const errorMessage = getErrorMessage(error);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, errorMessage);
logConsoleError(errorMessage);
if (this.onLoadStartKey != null && this.onLoadStartKey != undefined) {
TelemetryProcessor.traceFailure(
Action.Tab,

View File

@ -7,9 +7,8 @@ import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstan
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import { userContext } from "../../UserContext";
import { isInvalidParentFrameOrigin, isReadyMessage } from "../../Utils/MessageValidation";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleError, logConsoleInfo, logConsoleProgress } from "../../Utils/NotificationConsoleUtils";
import Explorer from "../Explorer";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import template from "./MongoShellTab.html";
import TabsBase from "./TabsBase";
@ -184,13 +183,11 @@ export default class MongoShellTab extends TabsBase {
switch (logType) {
case LogType.Information:
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, dataToLog);
break;
return logConsoleInfo(dataToLog);
case LogType.Warning:
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, dataToLog);
break;
return logConsoleError(dataToLog);
case LogType.InProgress:
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.InProgress, dataToLog);
return logConsoleProgress(dataToLog);
}
}
}

View File

@ -21,11 +21,10 @@ import { Action, ActionModifiers, Source } from "../../Shared/Telemetry/Telemetr
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import { userContext } from "../../UserContext";
import * as NotebookConfigurationUtils from "../../Utils/NotebookConfigurationUtils";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleInfo } from "../../Utils/NotificationConsoleUtils";
import { CommandButtonComponentProps } from "../Controls/CommandButton/CommandButtonComponent";
import Explorer from "../Explorer";
import * as CommandBarComponentButtonFactory from "../Menus/CommandBar/CommandBarComponentButtonFactory";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import { KernelSpecsDisplay, NotebookClientV2 } from "../Notebook/NotebookClientV2";
import { NotebookComponentAdapter } from "../Notebook/NotebookComponent/NotebookComponentAdapter";
import { NotebookContentItem } from "../Notebook/NotebookContentItem";
@ -62,11 +61,7 @@ export default class NotebookTabV2 extends TabsBase {
}
this.notebookPath = ko.observable(options.notebookContentItem.path);
this.container.notebookServerInfo.subscribe((newValue: DataModels.NotebookWorkspaceConnectionInfo) => {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, "New notebook server info received.");
});
this.container.notebookServerInfo.subscribe(() => logConsoleInfo("New notebook server info received."));
this.notebookComponentAdapter = new NotebookComponentAdapter({
contentItem: options.notebookContentItem,
notebooksBasePath: this.container.getNotebookBasePath(),

View File

@ -13,9 +13,8 @@ import { IJunoResponse, JunoClient } from "../../Juno/JunoClient";
import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants";
import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor";
import { userContext } from "../../UserContext";
import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils";
import { logConsoleError } from "../../Utils/NotificationConsoleUtils";
import Explorer from "../Explorer";
import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent";
import { DatabaseSettingsTabV2 } from "../Tabs/SettingsTabV2";
import Collection from "./Collection";
@ -101,10 +100,7 @@ export default class Database implements ViewModels.Database {
},
startKey
);
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Error,
`Error while fetching database settings for database ${this.id()}: ${errorMessage}`
);
logConsoleError(`Error while fetching database settings for database ${this.id()}: ${errorMessage}`);
throw error;
}
);

View File

@ -1,13 +1,12 @@
import ko from "knockout";
import { HttpStatusCodes } from "../Common/Constants";
import { handleError } from "../Common/ErrorHandlingUtils";
import { configContext } from "../ConfigContext";
import { AuthorizeAccessComponent } from "../Explorer/Controls/GitHub/AuthorizeAccessComponent";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import { JunoClient } from "../Juno/JunoClient";
import { isInvalidParentFrameOrigin } from "../Utils/MessageValidation";
import * as NotificationConsoleUtils from "../Utils/NotificationConsoleUtils";
import { logConsoleInfo } from "../Utils/NotificationConsoleUtils";
import { GitHubConnectorMsgType, IGitHubConnectorParams } from "./GitHubConnector";
import { handleError } from "../Common/ErrorHandlingUtils";
window.addEventListener("message", (event: MessageEvent) => {
if (isInvalidParentFrameOrigin(event)) {
@ -70,7 +69,7 @@ export class GitHubOAuthService {
const response = await this.junoClient.getGitHubToken(params.code);
if (response.status === HttpStatusCodes.OK && !response.data.error) {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, "Successfully connected to GitHub");
logConsoleInfo("Successfully connected to GitHub");
this.token(response.data);
} else {
let errorMsg = response.data.error;
@ -80,7 +79,7 @@ export class GitHubOAuthService {
throw new Error(errorMsg);
}
} catch (error) {
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Error, `Failed to connect to GitHub: ${error}`);
logConsoleInfo(`Failed to connect to GitHub: ${error}`);
this.token({ error });
}
}

View File

@ -1,20 +1,19 @@
import { IGalleryItem, JunoClient } from "../Juno/JunoClient";
import * as NotificationConsoleUtils from "./NotificationConsoleUtils";
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
import {
GalleryTab,
SortBy,
GalleryViewerComponent,
} from "../Explorer/Controls/NotebookGallery/GalleryViewerComponent";
import Explorer from "../Explorer/Explorer";
import { IChoiceGroupOption, IChoiceGroupProps, IProgressIndicatorProps } from "office-ui-fabric-react";
import { TextFieldProps } from "../Explorer/Controls/Dialog";
import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHandlingUtils";
import { HttpStatusCodes } from "../Common/Constants";
import { trace, traceFailure, traceStart, traceSuccess } from "../Shared/Telemetry/TelemetryProcessor";
import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants";
import { Notebook } from "@nteract/commutable";
import { NotebookV4 } from "@nteract/commutable/lib/v4";
import { IChoiceGroupOption, IChoiceGroupProps, IProgressIndicatorProps } from "office-ui-fabric-react";
import { HttpStatusCodes } from "../Common/Constants";
import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHandlingUtils";
import { TextFieldProps } from "../Explorer/Controls/Dialog";
import {
GalleryTab,
GalleryViewerComponent,
SortBy,
} from "../Explorer/Controls/NotebookGallery/GalleryViewerComponent";
import Explorer from "../Explorer/Explorer";
import { IGalleryItem, JunoClient } from "../Juno/JunoClient";
import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants";
import { trace, traceFailure, traceStart, traceSuccess } from "../Shared/Telemetry/TelemetryProcessor";
import { logConsoleInfo, logConsoleProgress } from "./NotificationConsoleUtils";
const defaultSelectedAbuseCategory = "Other";
const abuseCategories: IChoiceGroupOption[] = [
@ -228,11 +227,7 @@ export function downloadItem(
`Download ${name} from gallery as a copy to your notebooks to run and/or edit the notebook.`,
"Download",
async () => {
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Downloading ${name} to My Notebooks`
);
const clearInProgressMessage = logConsoleProgress(`Downloading ${name} to My Notebooks`);
const startKey = traceStart(Action.NotebooksGalleryDownload, {
notebookId: data.id,
downloadCount: data.downloads,
@ -249,10 +244,7 @@ export function downloadItem(
removeNotebookViewerLink(notebook, data.newCellId);
await container.importAndOpenContent(data.name, JSON.stringify(notebook));
NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.Info,
`Successfully downloaded ${name} to My Notebooks`
);
logConsoleInfo(`Successfully downloaded ${name} to My Notebooks`);
const increaseDownloadResponse = await junoClient.increaseNotebookDownloadCount(data.id);
if (increaseDownloadResponse.data) {
@ -279,7 +271,7 @@ export function downloadItem(
handleError(error, "GalleryUtils/downloadItem", `Failed to download ${data.name}`);
}
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
clearInProgressMessage();
},
"Cancel",
undefined
@ -405,11 +397,7 @@ export function deleteItem(
beforeDelete();
}
const name = data.name;
const notificationId = NotificationConsoleUtils.logConsoleMessage(
ConsoleDataType.InProgress,
`Removing ${name} from gallery`
);
const clearInProgressMessage = logConsoleProgress(`Removing ${name} from gallery`);
const startKey = traceStart(Action.NotebooksGalleryDelete, { notebookId: data.id });
try {
@ -420,7 +408,7 @@ export function deleteItem(
traceSuccess(Action.NotebooksGalleryDelete, { notebookId: data.id }, startKey);
NotificationConsoleUtils.logConsoleMessage(ConsoleDataType.Info, `Successfully removed ${name} from gallery`);
logConsoleInfo(`Successfully removed ${name} from gallery`);
onComplete(response.data);
} catch (error) {
traceFailure(
@ -436,7 +424,7 @@ export function deleteItem(
}
}
NotificationConsoleUtils.clearInProgressMessageWithId(notificationId);
clearInProgressMessage();
},
"Cancel",
undefined

View File

@ -3,79 +3,29 @@ import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/Notificat
const _global = typeof self === "undefined" ? window : self;
/**
* @deprecated
* Use logConsoleInfo, logConsoleError, logConsoleProgress instead
* */
export function logConsoleMessage(type: ConsoleDataType, message: string, id?: string): string {
const dataExplorer = _global.dataExplorer;
if (dataExplorer) {
const date = new Date();
const formattedDate: string = new Intl.DateTimeFormat("en-EN", {
hour12: true,
hour: "numeric",
minute: "numeric",
}).format(date);
if (!id) {
id = _.uniqueId();
}
dataExplorer.logConsoleData({ type, date: formattedDate, message, id });
}
return id || "";
}
export function clearInProgressMessageWithId(id: string): void {
_global.dataExplorer?.deleteInProgressConsoleDataWithId(id);
}
export function logConsoleProgress(message: string): () => void {
const type = ConsoleDataType.InProgress;
function log(type: ConsoleDataType, message: string): () => void {
const dataExplorer = _global.dataExplorer;
if (dataExplorer) {
const id = _.uniqueId();
const date = new Date();
const formattedDate: string = new Intl.DateTimeFormat("en-EN", {
const date = new Intl.DateTimeFormat("en-EN", {
hour12: true,
hour: "numeric",
minute: "numeric",
}).format(date);
dataExplorer.logConsoleData({ type, date: formattedDate, message, id });
return () => {
dataExplorer.deleteInProgressConsoleDataWithId(id);
}).format(new Date());
dataExplorer.logConsoleData({ type, date, message, id });
return () => dataExplorer.deleteInProgressConsoleDataWithId(id);
}
return () => undefined;
}
export const logConsoleProgress = (msg: string): (() => void) => log(ConsoleDataType.InProgress, msg);
export const logConsoleError = (msg: string): void => {
log(ConsoleDataType.Error, msg);
};
} else {
return () => {
return;
export const logConsoleInfo = (msg: string): void => {
log(ConsoleDataType.Info, msg);
};
}
}
export function logConsoleError(message: string): void {
const type = ConsoleDataType.Error;
const dataExplorer = _global.dataExplorer;
if (dataExplorer) {
const id = _.uniqueId();
const date = new Date();
const formattedDate: string = new Intl.DateTimeFormat("en-EN", {
hour12: true,
hour: "numeric",
minute: "numeric",
}).format(date);
dataExplorer.logConsoleData({ type, date: formattedDate, message, id });
}
}
export function logConsoleInfo(message: string): void {
const type = ConsoleDataType.Info;
const dataExplorer = _global.dataExplorer;
if (dataExplorer) {
const id = _.uniqueId();
const date = new Date();
const formattedDate: string = new Intl.DateTimeFormat("en-EN", {
hour12: true,
hour: "numeric",
minute: "numeric",
}).format(date);
dataExplorer.logConsoleData({ type, date: formattedDate, message, id });
}
}