From c4257bf4a97401e9722596cde7cccb028874e70a Mon Sep 17 00:00:00 2001 From: Tanuj Mittal Date: Fri, 11 Sep 2020 23:12:28 -0700 Subject: [PATCH] Revert "Add telemetry for OpenTerminal success/failure (#192)" (#198) This reverts commit 83b13de6852902c68038c3a0eee0a8d6ad8c1651. --- src/Common/MessageHandler.ts | 29 +++++------------- src/Shared/Telemetry/TelemetryConstants.ts | 3 +- src/Terminal/index.ts | 34 +++++++--------------- 3 files changed, 18 insertions(+), 48 deletions(-) diff --git a/src/Common/MessageHandler.ts b/src/Common/MessageHandler.ts index c225bc9d3..d9bbaae8b 100644 --- a/src/Common/MessageHandler.ts +++ b/src/Common/MessageHandler.ts @@ -48,31 +48,16 @@ export function sendCachedDataMessage( export function sendMessage(data: any): void { if (canSendMessage()) { - const dataExplorerWindow = getDataExplorerWindow(); - if (dataExplorerWindow) { - dataExplorerWindow.parent.postMessage( - { - signature: "pcIframe", - data: data - }, - dataExplorerWindow.document.referrer - ); - } + window.parent.postMessage( + { + signature: "pcIframe", + data: data + }, + window.document.referrer + ); } } -const getDataExplorerWindow = (): Window => { - // Traverse up the window to find a window with `dataExplorerPlatform` property - let dataExplorerWindow: Window = window; - // TODO: Need to `any` here since the window imports Explorer which can't be in strict mode yet - // eslint-disable-next-line @typescript-eslint/no-explicit-any - while (!(dataExplorerWindow as any).dataExplorerPlatform && dataExplorerWindow.parent) { - dataExplorerWindow = dataExplorerWindow.parent; - } - - return dataExplorerWindow; -}; - export function canSendMessage(): boolean { return window.parent !== window; } diff --git a/src/Shared/Telemetry/TelemetryConstants.ts b/src/Shared/Telemetry/TelemetryConstants.ts index 97a4c303f..53a03cd75 100644 --- a/src/Shared/Telemetry/TelemetryConstants.ts +++ b/src/Shared/Telemetry/TelemetryConstants.ts @@ -70,8 +70,7 @@ export enum Action { NotebooksGitHubManualRepoAdd, NotebooksGitHubManageRepo, NotebooksGitHubCommit, - NotebooksGitHubDisconnect, - OpenTerminal + NotebooksGitHubDisconnect } export const ActionModifiers = { diff --git a/src/Terminal/index.ts b/src/Terminal/index.ts index 605d290f7..6826ad0ff 100644 --- a/src/Terminal/index.ts +++ b/src/Terminal/index.ts @@ -4,8 +4,6 @@ import "@jupyterlab/terminal/style/index.css"; import "./index.css"; import { ServerConnection } from "@jupyterlab/services"; import { JupyterLabAppFactory } from "./JupyterLabAppFactory"; -import { Action } from "../Shared/Telemetry/TelemetryConstants"; -import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor"; const getUrlVars = (): { [key: string]: string } => { const vars: { [key: string]: string } = {}; @@ -16,7 +14,10 @@ const getUrlVars = (): { [key: string]: string } => { return vars; }; -const createServerSettings = (urlVars: { [key: string]: string }): ServerConnection.ISettings => { +const main = (): void => { + const urlVars = getUrlVars(); + console.log("URL parameters", urlVars); + let body: BodyInit; if (urlVars.hasOwnProperty("terminalEndpoint")) { body = JSON.stringify({ @@ -38,29 +39,14 @@ const createServerSettings = (urlVars: { [key: string]: string }): ServerConnect fetch: window.parent.fetch }; } + const serverSettings = ServerConnection.makeSettings(options); - return ServerConnection.makeSettings(options); -}; - -const main = async (): Promise => { - const urlVars = getUrlVars(); - const serverSettings = createServerSettings(urlVars); - - const startTime = TelemetryProcessor.traceStart(Action.OpenTerminal, { - baseUrl: serverSettings.baseUrl - }); - - try { - if (urlVars.hasOwnProperty("terminal")) { - await JupyterLabAppFactory.createTerminalApp(serverSettings); - } else { - throw new Error("Only terminal is supported"); - } - - TelemetryProcessor.traceSuccess(Action.OpenTerminal, startTime); - } catch (error) { - TelemetryProcessor.traceFailure(Action.OpenTerminal, startTime); + if (urlVars.hasOwnProperty("terminal")) { + JupyterLabAppFactory.createTerminalApp(serverSettings); + return; } + + throw new Error("Only terminal is supported"); }; window.addEventListener("load", main);