From 821f665e78160d397b84bc69ef97fd86c7e8d899 Mon Sep 17 00:00:00 2001 From: Steve Faulkner Date: Wed, 14 Oct 2020 22:25:13 -0500 Subject: [PATCH] Remove window.dataExplorerPlatform (#279) More cleanup for #253 - Remove window.dataExplorerPlatform - Remove explorer factories --- src/Common/CosmosClient.test.ts | 1 - .../ScaleComponent.test.tsx | 6 ++--- .../SettingsSubComponents/ScaleComponent.tsx | 6 ++--- .../ScaleComponent.test.tsx.snap | 4 +-- src/Explorer/Explorer.ts | 13 +++------ .../CommandBarComponentButtonFactory.ts | 3 +-- src/Explorer/Panes/AddCollectionPane.ts | 4 +-- src/Explorer/Panes/AddDatabasePane.ts | 3 +-- src/Explorer/Tabs/DatabaseSettingsTab.ts | 11 +++----- src/Explorer/Tabs/MongoShellTab.ts | 5 ++-- src/Explorer/Tabs/SettingsTab.ts | 9 +++---- src/Explorer/Tree/Collection.ts | 6 ++--- src/Main.ts | 7 ----- src/Platform/Emulator/ExplorerFactory.ts | 27 ------------------- src/Platform/Emulator/Main.ts | 22 +++++++++++++-- src/Platform/Hosted/ExplorerFactory.ts | 15 ----------- src/Platform/Hosted/Main.ts | 11 +++----- src/Platform/Portal/ExplorerFactory.ts | 9 ------- src/Platform/Portal/Main.ts | 4 +-- src/PlatformType.ts | 10 ------- src/TokenProviders/TokenProviderFactory.ts | 10 +++---- src/Utils/AuthorizationUtils.test.ts | 11 +++++--- src/Utils/AuthorizationUtils.ts | 6 ++--- src/global.d.ts | 2 -- tsconfig.strict.json | 1 - 25 files changed, 63 insertions(+), 143 deletions(-) delete mode 100644 src/Platform/Emulator/ExplorerFactory.ts delete mode 100644 src/Platform/Hosted/ExplorerFactory.ts delete mode 100644 src/Platform/Portal/ExplorerFactory.ts delete mode 100644 src/PlatformType.ts diff --git a/src/Common/CosmosClient.test.ts b/src/Common/CosmosClient.test.ts index e65ed2b35..08aaee386 100644 --- a/src/Common/CosmosClient.test.ts +++ b/src/Common/CosmosClient.test.ts @@ -112,7 +112,6 @@ describe("endpoint", () => { describe("requestPlugin", () => { beforeEach(() => { - delete window.dataExplorerPlatform; resetConfigContext(); }); diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.test.tsx index 1cd52824b..e2f452432 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.test.tsx @@ -5,7 +5,6 @@ import { container, collection } from "../TestUtils"; import { ThroughputInputAutoPilotV3Component } from "./ThroughputInputComponents/ThroughputInputAutoPilotV3Component"; import Explorer from "../../../Explorer"; import * as Constants from "../../../../Common/Constants"; -import { PlatformType } from "../../../../PlatformType"; import * as DataModels from "../../../../Contracts/DataModels"; import { throughputUnit } from "../SettingsRenderUtils"; import * as SharedConstants from "../../../../Shared/Constants"; @@ -13,7 +12,6 @@ import ko from "knockout"; describe("ScaleComponent", () => { const nonNationalCloudContainer = new Explorer(); - nonNationalCloudContainer.getPlatformType = () => PlatformType.Portal; nonNationalCloudContainer.isRunningOnNationalCloud = () => false; const targetThroughput = 6000; @@ -119,7 +117,7 @@ describe("ScaleComponent", () => { it("getThroughputTitle", () => { let scaleComponent = new ScaleComponent(baseProps); - expect(scaleComponent.getThroughputTitle()).toEqual("Throughput (6,000 - 40,000 RU/s)"); + expect(scaleComponent.getThroughputTitle()).toEqual("Throughput (6,000 - unlimited RU/s)"); let newProps = { ...baseProps, container: nonNationalCloudContainer }; scaleComponent = new ScaleComponent(newProps); @@ -132,7 +130,7 @@ describe("ScaleComponent", () => { it("canThroughputExceedMaximumValue", () => { let scaleComponent = new ScaleComponent(baseProps); - expect(scaleComponent.canThroughputExceedMaximumValue()).toEqual(false); + expect(scaleComponent.canThroughputExceedMaximumValue()).toEqual(true); const newProps = { ...baseProps, container: nonNationalCloudContainer }; scaleComponent = new ScaleComponent(newProps); diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.tsx b/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.tsx index 326a74fb7..a7884ec76 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/ScaleComponent.tsx @@ -5,7 +5,6 @@ import * as ViewModels from "../../../../Contracts/ViewModels"; import * as DataModels from "../../../../Contracts/DataModels"; import * as SharedConstants from "../../../../Shared/Constants"; import Explorer from "../../../Explorer"; -import { PlatformType } from "../../../../PlatformType"; import { getTextFieldStyles, subComponentStackProps, @@ -78,7 +77,7 @@ export class ScaleComponent extends React.Component { }; public getMaxRUThroughputInputLimit = (): number => { - if (this.props.container?.getPlatformType() === PlatformType.Hosted && this.props.collection.partitionKey) { + if (configContext.platform === Platform.Hosted && this.props.collection.partitionKey) { return SharedConstants.CollectionCreation.DefaultCollectionRUs1Million; } @@ -100,8 +99,7 @@ export class ScaleComponent extends React.Component { public canThroughputExceedMaximumValue = (): boolean => { const isPublicAzurePortal: boolean = - this.props.container.getPlatformType() === PlatformType.Portal && - !this.props.container.isRunningOnNationalCloud(); + configContext.platform === Platform.Portal && !this.props.container.isRunningOnNationalCloud(); const hasPartitionKey = !!this.props.collection.partitionKey; return isPublicAzurePortal && hasPartitionKey; diff --git a/src/Explorer/Controls/Settings/SettingsSubComponents/__snapshots__/ScaleComponent.test.tsx.snap b/src/Explorer/Controls/Settings/SettingsSubComponents/__snapshots__/ScaleComponent.test.tsx.snap index 0221539a4..0b6aaa749 100644 --- a/src/Explorer/Controls/Settings/SettingsSubComponents/__snapshots__/ScaleComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/SettingsSubComponents/__snapshots__/ScaleComponent.test.tsx.snap @@ -39,13 +39,13 @@ exports[`ScaleComponent renders with correct intiial notification 1`] = ` } > ( () => - this.getPlatformType() === PlatformType.Portal && - !this.isRunningOnNationalCloud() && - !this.isPreferredApiGraph() + configContext.platform === Platform.Portal && !this.isRunningOnNationalCloud() && !this.isPreferredApiGraph() ); this.isRightPanelV2Enabled = ko.computed(() => this.isFeatureEnabled(Constants.Features.enableRightPanelV2) @@ -1793,7 +1790,7 @@ export default class Explorer { const message: any = event.data.data; const inputs: ViewModels.DataExplorerInputsFrame = message.inputs; - const isRunningInPortal = window.dataExplorerPlatform == PlatformType.Portal; + const isRunningInPortal = configContext.platform === Platform.Portal; const isRunningInDevMode = process.env.NODE_ENV === "development"; if (inputs && configContext.BACKEND_ENDPOINT && isRunningInPortal && isRunningInDevMode) { inputs.extensionEndpoint = configContext.PROXY_PATH; @@ -2009,10 +2006,6 @@ export default class Explorer { this._panes.forEach((pane: ContextualPaneBase) => pane.close()); } - public getPlatformType(): PlatformType { - return window.dataExplorerPlatform; - } - public isRunningOnNationalCloud(): boolean { return ( this.serverId() === Constants.ServerIds.blackforest || diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts index 3fcc4b853..2ae8df481 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentButtonFactory.ts @@ -1,5 +1,4 @@ import * as ViewModels from "../../../Contracts/ViewModels"; -import { PlatformType } from "../../../PlatformType"; import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants"; import { Areas } from "../../../Common/Constants"; import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; @@ -159,7 +158,7 @@ export class CommandBarComponentButtonFactory { public static createControlCommandBarButtons(container: Explorer): CommandButtonComponentProps[] { const buttons: CommandButtonComponentProps[] = []; - if (window.dataExplorerPlatform === PlatformType.Hosted) { + if (configContext.platform === Platform.Hosted) { return buttons; } diff --git a/src/Explorer/Panes/AddCollectionPane.ts b/src/Explorer/Panes/AddCollectionPane.ts index 3933f120d..f92adda43 100644 --- a/src/Explorer/Panes/AddCollectionPane.ts +++ b/src/Explorer/Panes/AddCollectionPane.ts @@ -14,8 +14,6 @@ import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstan import { configContext, Platform } from "../../ConfigContext"; import { ContextualPaneBase } from "./ContextualPaneBase"; import { DynamicListItem } from "../Controls/DynamicList/DynamicListComponent"; -import { HashMap } from "../../Common/HashMap"; -import { PlatformType } from "../../PlatformType"; import { refreshCachedResources } from "../../Common/DocumentClientUtilityBase"; import { createCollection } from "../../Common/dataAccess/createCollection"; @@ -327,7 +325,7 @@ export default class AddCollectionPane extends ContextualPaneBase { if ( configContext.platform !== Platform.Emulator && !this.container.isTryCosmosDBSubscription() && - this.container.getPlatformType() !== PlatformType.Portal + configContext.platform !== Platform.Portal ) { const offerThroughput: number = this._getThroughput(); return offerThroughput <= 100000; diff --git a/src/Explorer/Panes/AddDatabasePane.ts b/src/Explorer/Panes/AddDatabasePane.ts index bc465022b..656ab4457 100644 --- a/src/Explorer/Panes/AddDatabasePane.ts +++ b/src/Explorer/Panes/AddDatabasePane.ts @@ -11,7 +11,6 @@ import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import { ContextualPaneBase } from "./ContextualPaneBase"; import { createDatabase } from "../../Common/dataAccess/createDatabase"; -import { PlatformType } from "../../PlatformType"; import { configContext, Platform } from "../../ConfigContext"; export default class AddDatabasePane extends ContextualPaneBase { @@ -183,7 +182,7 @@ export default class AddDatabasePane extends ContextualPaneBase { if ( configContext.platform !== Platform.Emulator && !this.container.isTryCosmosDBSubscription() && - this.container.getPlatformType() !== PlatformType.Portal + configContext.platform !== Platform.Portal ) { const offerThroughput: number = this.throughput(); return offerThroughput <= 100000; diff --git a/src/Explorer/Tabs/DatabaseSettingsTab.ts b/src/Explorer/Tabs/DatabaseSettingsTab.ts index 49b67b689..ce6bf76d6 100644 --- a/src/Explorer/Tabs/DatabaseSettingsTab.ts +++ b/src/Explorer/Tabs/DatabaseSettingsTab.ts @@ -13,7 +13,6 @@ import SaveIcon from "../../../images/save-cosmos.svg"; import TabsBase from "./TabsBase"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { Action } from "../../Shared/Telemetry/TelemetryConstants"; -import { PlatformType } from "../../PlatformType"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import Explorer from "../Explorer"; import { updateOffer } from "../../Common/dataAccess/updateOffer"; @@ -200,16 +199,14 @@ export default class DatabaseSettingsTab extends TabsBase implements ViewModels. return configContext.platform !== Platform.Emulator; }); - this.shouldDisplayPortalUsePrompt = ko.pureComputed( - () => this.container.getPlatformType() === PlatformType.Hosted - ); + this.shouldDisplayPortalUsePrompt = ko.pureComputed(() => configContext.platform === Platform.Hosted); this.canThroughputExceedMaximumValue = ko.pureComputed( - () => this.container.getPlatformType() === PlatformType.Portal && !this.container.isRunningOnNationalCloud() + () => configContext.platform === Platform.Portal && !this.container.isRunningOnNationalCloud() ); this.canRequestSupport = ko.pureComputed(() => { if ( configContext.platform === Platform.Emulator || - this.container.getPlatformType() === PlatformType.Hosted || + configContext.platform === Platform.Hosted || this.canThroughputExceedMaximumValue() ) { return false; @@ -273,7 +270,7 @@ export default class DatabaseSettingsTab extends TabsBase implements ViewModels. }); this.maxRUThroughputInputLimit = ko.pureComputed(() => { - if (this.container && this.container.getPlatformType() === PlatformType.Hosted) { + if (configContext.platform === Platform.Hosted) { return SharedConstants.CollectionCreation.DefaultCollectionRUs1Million; } diff --git a/src/Explorer/Tabs/MongoShellTab.ts b/src/Explorer/Tabs/MongoShellTab.ts index 36b9d2711..04b9528b7 100644 --- a/src/Explorer/Tabs/MongoShellTab.ts +++ b/src/Explorer/Tabs/MongoShellTab.ts @@ -10,10 +10,9 @@ import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstan import { ConsoleDataType } from "../Menus/NotificationConsole/NotificationConsoleComponent"; import { HashMap } from "../../Common/HashMap"; import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; -import { PlatformType } from "../../PlatformType"; import Explorer from "../Explorer"; import { userContext } from "../../UserContext"; -import { configContext } from "../../ConfigContext"; +import { configContext, Platform } from "../../ConfigContext"; export default class MongoShellTab extends TabsBase { public url: ko.Computed; @@ -31,7 +30,7 @@ export default class MongoShellTab extends TabsBase { const accountName = account && account.name; const mongoEndpoint = account && (account.properties.mongoEndpoint || account.properties.documentEndpoint); - this._runtimeEndpoint = window.dataExplorerPlatform === PlatformType.Hosted ? configContext.BACKEND_ENDPOINT : ""; + this._runtimeEndpoint = configContext.platform === Platform.Hosted ? configContext.BACKEND_ENDPOINT : ""; const extensionEndpoint: string = configContext.BACKEND_ENDPOINT || this._runtimeEndpoint || ""; let baseUrl = "/content/mongoshell/dist/"; if (this._container.serverId() === "localhost") { diff --git a/src/Explorer/Tabs/SettingsTab.ts b/src/Explorer/Tabs/SettingsTab.ts index 77354ea36..43fa9f714 100644 --- a/src/Explorer/Tabs/SettingsTab.ts +++ b/src/Explorer/Tabs/SettingsTab.ts @@ -14,7 +14,6 @@ import SaveIcon from "../../../images/save-cosmos.svg"; import TabsBase from "./TabsBase"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; -import { PlatformType } from "../../PlatformType"; import { RequestOptions } from "@azure/cosmos/dist-esm"; import Explorer from "../Explorer"; import { updateOffer } from "../../Common/dataAccess/updateOffer"; @@ -494,7 +493,7 @@ export default class SettingsTab extends TabsBase implements ViewModels.WaitsFor this.canThroughputExceedMaximumValue = ko.pureComputed(() => { const isPublicAzurePortal: boolean = - this.container.getPlatformType() === PlatformType.Portal && !this.container.isRunningOnNationalCloud(); + configContext.platform === Platform.Portal && !this.container.isRunningOnNationalCloud(); const hasPartitionKey = !!this.collection.partitionKey; return isPublicAzurePortal && hasPartitionKey; @@ -513,7 +512,7 @@ export default class SettingsTab extends TabsBase implements ViewModels.WaitsFor return false; } - if (this.container.getPlatformType() === PlatformType.Hosted) { + if (configContext.platform === Platform.Hosted) { return false; } @@ -526,7 +525,7 @@ export default class SettingsTab extends TabsBase implements ViewModels.WaitsFor }); this.shouldDisplayPortalUsePrompt = ko.pureComputed( - () => this.container.getPlatformType() === PlatformType.Hosted && !!this.collection.partitionKey + () => configContext.platform === Platform.Hosted && !!this.collection.partitionKey ); this.minRUs = ko.computed(() => { @@ -597,7 +596,7 @@ export default class SettingsTab extends TabsBase implements ViewModels.WaitsFor }); this.maxRUThroughputInputLimit = ko.pureComputed(() => { - if (this.container && this.container.getPlatformType() === PlatformType.Hosted && this.collection.partitionKey) { + if (configContext.platform === Platform.Hosted && this.collection.partitionKey) { return SharedConstants.CollectionCreation.DefaultCollectionRUs1Million; } diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index c20d30885..1d451cbef 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -14,7 +14,6 @@ import { readCollectionQuotaInfo } from "../../Common/dataAccess/readCollectionQ import * as Logger from "../../Common/Logger"; import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; -import { PlatformType } from "../../PlatformType"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import * as NotificationConsoleUtils from "../../Utils/NotificationConsoleUtils"; @@ -36,7 +35,7 @@ import DocumentId from "./DocumentId"; import StoredProcedure from "./StoredProcedure"; import Trigger from "./Trigger"; import UserDefinedFunction from "./UserDefinedFunction"; -import { configContext } from "../../ConfigContext"; +import { configContext, Platform } from "../../ConfigContext"; import Explorer from "../Explorer"; import { userContext } from "../../UserContext"; import TabsBase from "../Tabs/TabsBase"; @@ -1030,9 +1029,8 @@ export default class Collection implements ViewModels.Collection { } public uploadFiles = (fileList: FileList): Q.Promise => { - const platformType: string = PlatformType[(window).dataExplorerPlatform]; // TODO: right now web worker is not working with AAD flow. Use main thread for upload for now until we have backend upload capability - if (platformType === PlatformType[PlatformType.Hosted] && window.authType === AuthType.AAD) { + if (configContext.platform === Platform.Hosted && window.authType === AuthType.AAD) { return this._uploadFilesCors(fileList); } const documentUploader: Worker = new UploadWorker(); diff --git a/src/Main.ts b/src/Main.ts index 5ca620229..4845fc4e0 100644 --- a/src/Main.ts +++ b/src/Main.ts @@ -65,7 +65,6 @@ import { BindingHandlersRegisterer } from "./Bindings/BindingHandlersRegisterer" import * as Emulator from "./Platform/Emulator/Main"; import Hosted from "./Platform/Hosted/Main"; import * as Portal from "./Platform/Portal/Main"; -import { PlatformType } from "./PlatformType"; import { AuthType } from "./AuthType"; import { initializeIcons } from "office-ui-fabric-react/lib/Icons"; @@ -81,8 +80,6 @@ window.authType = AuthType.AAD; initializeConfiguration().then(config => { if (config.platform === Platform.Hosted) { try { - // TODO Remove. All window variables should move to src/Config file - window.dataExplorerPlatform = PlatformType.Hosted; Hosted.initializeExplorer().then( (explorer: Explorer) => { applyExplorerBindings(explorer); @@ -108,14 +105,10 @@ initializeConfiguration().then(config => { console.log(e); } } else if (config.platform === Platform.Emulator) { - // TODO Remove. All window variables should move to src/Config file - window.dataExplorerPlatform = PlatformType.Emulator; window.authType = AuthType.MasterKey; const explorer = Emulator.initializeExplorer(); applyExplorerBindings(explorer); } else if (config.platform === Platform.Portal) { - // TODO Remove. All window variables should move to src/Config file - window.dataExplorerPlatform = PlatformType.Portal; TelemetryProcessor.trace(Action.InitializeDataExplorer, ActionModifiers.Open, {}); const explorer = Portal.initializeExplorer(); TelemetryProcessor.trace(Action.InitializeDataExplorer, ActionModifiers.IFrameReady, {}); diff --git a/src/Platform/Emulator/ExplorerFactory.ts b/src/Platform/Emulator/ExplorerFactory.ts deleted file mode 100644 index 6f4774b37..000000000 --- a/src/Platform/Emulator/ExplorerFactory.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { AccountKind, TagNames, DefaultAccountExperience } from "../../Common/Constants"; - -import Explorer from "../../Explorer/Explorer"; - -export default class EmulatorExplorerFactory { - public static createExplorer(): Explorer { - const explorer: Explorer = new Explorer(); - explorer.databaseAccount({ - name: "", - id: "", - location: "", - type: "", - kind: AccountKind.DocumentDB, - tags: { - [TagNames.defaultExperience]: DefaultAccountExperience.DocumentDB - }, - properties: { - documentEndpoint: "", - tableEndpoint: "", - gremlinEndpoint: "", - cassandraEndpoint: "" - } - }); - explorer.isAccountReady(true); - return explorer; - } -} diff --git a/src/Platform/Emulator/Main.ts b/src/Platform/Emulator/Main.ts index 08b32237d..7cc62b094 100644 --- a/src/Platform/Emulator/Main.ts +++ b/src/Platform/Emulator/Main.ts @@ -1,6 +1,24 @@ -import EmulatorExplorerFactory from "./ExplorerFactory"; import Explorer from "../../Explorer/Explorer"; +import { AccountKind, DefaultAccountExperience, TagNames } from "../../Common/Constants"; export function initializeExplorer(): Explorer { - return EmulatorExplorerFactory.createExplorer(); + const explorer = new Explorer(); + explorer.databaseAccount({ + name: "", + id: "", + location: "", + type: "", + kind: AccountKind.DocumentDB, + tags: { + [TagNames.defaultExperience]: DefaultAccountExperience.DocumentDB + }, + properties: { + documentEndpoint: "", + tableEndpoint: "", + gremlinEndpoint: "", + cassandraEndpoint: "" + } + }); + explorer.isAccountReady(true); + return explorer; } diff --git a/src/Platform/Hosted/ExplorerFactory.ts b/src/Platform/Hosted/ExplorerFactory.ts deleted file mode 100644 index dc1b1be2e..000000000 --- a/src/Platform/Hosted/ExplorerFactory.ts +++ /dev/null @@ -1,15 +0,0 @@ -import Explorer from "../../Explorer/Explorer"; - -export default class HostedExplorerFactory { - public createExplorer(): Explorer { - const explorer = new Explorer(); - - return explorer; - } - - public static reInitializeDocumentClientUtilityForExplorer(explorer: Explorer): void { - if (!!explorer) { - explorer.notificationConsoleData([]); - } - } -} diff --git a/src/Platform/Hosted/Main.ts b/src/Platform/Hosted/Main.ts index 6f75d3909..f7a0e1eb8 100644 --- a/src/Platform/Hosted/Main.ts +++ b/src/Platform/Hosted/Main.ts @@ -1,7 +1,5 @@ import * as Constants from "../../Common/Constants"; -import * as ViewModels from "../../Contracts/ViewModels"; import AuthHeadersUtil from "./Authorization"; -import HostedExplorerFactory from "./ExplorerFactory"; import Q from "q"; import { AccessInputMetadata, @@ -211,7 +209,7 @@ export default class Main { Main._getAccessInputMetadata(Main._encryptedToken).then( () => { if (explorer.isConnectExplorerVisible()) { - HostedExplorerFactory.reInitializeDocumentClientUtilityForExplorer(explorer); + explorer.notificationConsoleData([]); explorer.hideConnectExplorerForm(); } @@ -378,8 +376,7 @@ export default class Main { } private static _instantiateExplorer(): Explorer { - const hostedExplorerFactory = new HostedExplorerFactory(); - const explorer = hostedExplorerFactory.createExplorer(); + const explorer = new Explorer(); // workaround to resolve cyclic refs with view explorer.renewExplorerShareAccess = Main.renewExplorerAccess; window.addEventListener("message", explorer.handleMessage.bind(explorer), false); @@ -483,7 +480,7 @@ export default class Main { Main._accessInputMetadata = Main._getAccessInputMetadataFromAccountEndpoint(properties.accountEndpoint); if (explorer.isConnectExplorerVisible()) { - HostedExplorerFactory.reInitializeDocumentClientUtilityForExplorer(explorer); + explorer.notificationConsoleData([]); explorer.hideConnectExplorerForm(); } @@ -570,7 +567,7 @@ export default class Main { this._explorer.hideConnectExplorerForm(); const masterKey = Main._getMasterKey(keys); - HostedExplorerFactory.reInitializeDocumentClientUtilityForExplorer(this._explorer); + this._explorer.notificationConsoleData([]); Main._setExplorerReady(this._explorer, masterKey, account, authorizationToken); } diff --git a/src/Platform/Portal/ExplorerFactory.ts b/src/Platform/Portal/ExplorerFactory.ts deleted file mode 100644 index 06c2b0aaa..000000000 --- a/src/Platform/Portal/ExplorerFactory.ts +++ /dev/null @@ -1,9 +0,0 @@ -import Explorer from "../../Explorer/Explorer"; - -export default class PortalExplorerFactory { - public createExplorer(): Explorer { - var explorer = new Explorer(); - - return explorer; - } -} diff --git a/src/Platform/Portal/Main.ts b/src/Platform/Portal/Main.ts index cfce9ac2f..1e9af9e29 100644 --- a/src/Platform/Portal/Main.ts +++ b/src/Platform/Portal/Main.ts @@ -1,10 +1,8 @@ -import PortalExplorerFactory from "./ExplorerFactory"; import "../../Explorer/Tables/DataTable/DataTableBindingManager"; import Explorer from "../../Explorer/Explorer"; export function initializeExplorer(): Explorer { - const portalExplorerFactory = new PortalExplorerFactory(); - const explorer = portalExplorerFactory.createExplorer(); + const explorer = new Explorer(); window.addEventListener("message", explorer.handleMessage.bind(explorer), false); return explorer; diff --git a/src/PlatformType.ts b/src/PlatformType.ts deleted file mode 100644 index ccd5fcedc..000000000 --- a/src/PlatformType.ts +++ /dev/null @@ -1,10 +0,0 @@ -// TODO: Should be owned by parent iframe -export enum PlatformType { - // RuntimeProxy and MongoEmulator no longer used, but kept here to preserve enum structure - RuntimeProxy, - MongoEmulator, - - Hosted, - Emulator, - Portal -} diff --git a/src/TokenProviders/TokenProviderFactory.ts b/src/TokenProviders/TokenProviderFactory.ts index f2d9d7dca..3beb6cb26 100644 --- a/src/TokenProviders/TokenProviderFactory.ts +++ b/src/TokenProviders/TokenProviderFactory.ts @@ -1,17 +1,17 @@ +import { configContext, Platform } from "../ConfigContext"; import * as ViewModels from "../Contracts/ViewModels"; -import { PlatformType } from "../PlatformType"; import { PortalTokenProvider } from "./PortalTokenProvider"; export class TokenProviderFactory { private constructor() {} public static create(): ViewModels.TokenProvider { - const platformType = window.dataExplorerPlatform; + const platformType = configContext.platform; switch (platformType) { - case PlatformType.Portal: - case PlatformType.Hosted: + case Platform.Portal: + case Platform.Hosted: return new PortalTokenProvider(); - case PlatformType.Emulator: + case Platform.Emulator: default: // should never get into this state throw new Error(`Unknown platform ${platformType}`); diff --git a/src/Utils/AuthorizationUtils.test.ts b/src/Utils/AuthorizationUtils.test.ts index c3836bd5d..51faee8b6 100644 --- a/src/Utils/AuthorizationUtils.test.ts +++ b/src/Utils/AuthorizationUtils.test.ts @@ -1,9 +1,9 @@ import * as Constants from "../Common/Constants"; import * as AuthorizationUtils from "./AuthorizationUtils"; import { AuthType } from "../AuthType"; -import { PlatformType } from "../PlatformType"; import Explorer from "../Explorer/Explorer"; import { updateUserContext } from "../UserContext"; +import { Platform, updateConfigContext } from "../ConfigContext"; jest.mock("../Explorer/Explorer"); describe("AuthorizationUtils", () => { @@ -65,12 +65,13 @@ describe("AuthorizationUtils", () => { beforeEach(() => { jest.clearAllMocks(); window.dataExplorer = explorer; - window.dataExplorerPlatform = PlatformType.Hosted; + updateConfigContext({ + platform: Platform.Hosted + }); }); afterEach(() => { window.dataExplorer = undefined; - window.dataExplorerPlatform = undefined; }); it("should not open token renewal prompt if status code is undefined", () => { @@ -89,7 +90,9 @@ describe("AuthorizationUtils", () => { }); it("should not open token renewal prompt if running on a different platform", () => { - window.dataExplorerPlatform = PlatformType.Portal; + updateConfigContext({ + platform: Platform.Portal + }); AuthorizationUtils.displayTokenRenewalPromptForStatus(Constants.HttpStatusCodes.Unauthorized); expect(explorer.displayGuestAccessTokenRenewalPrompt).not.toHaveBeenCalled(); }); diff --git a/src/Utils/AuthorizationUtils.ts b/src/Utils/AuthorizationUtils.ts index 5c9cfb191..73c66d0a3 100644 --- a/src/Utils/AuthorizationUtils.ts +++ b/src/Utils/AuthorizationUtils.ts @@ -3,8 +3,7 @@ import * as ViewModels from "../Contracts/ViewModels"; import AuthHeadersUtil from "../Platform/Hosted/Authorization"; import { AuthType } from "../AuthType"; import * as Logger from "../Common/Logger"; -import { PlatformType } from "../PlatformType"; -import { configContext } from "../ConfigContext"; +import { configContext, Platform } from "../ConfigContext"; import { userContext } from "../UserContext"; export function getAuthorizationHeader(): ViewModels.AuthorizationTokenHeaderMetadata { @@ -57,13 +56,12 @@ export function decryptJWTToken(token: string) { } export function displayTokenRenewalPromptForStatus(httpStatusCode: number): void { - const platformType = window.dataExplorerPlatform; const explorer = window.dataExplorer; if ( httpStatusCode == null || httpStatusCode != Constants.HttpStatusCodes.Unauthorized || - platformType !== PlatformType.Hosted + configContext.platform !== Platform.Hosted ) { return; } diff --git a/src/global.d.ts b/src/global.d.ts index 3b55f9dd2..f33de89cc 100644 --- a/src/global.d.ts +++ b/src/global.d.ts @@ -1,11 +1,9 @@ import { AuthType } from "./AuthType"; -import { PlatformType } from "./PlatformType"; import Explorer from "./Explorer/Explorer"; declare global { interface Window { authType: AuthType; - dataExplorerPlatform: PlatformType; dataExplorer: Explorer; __REACT_DEVTOOLS_GLOBAL_HOOK__: any; $: any; diff --git a/tsconfig.strict.json b/tsconfig.strict.json index da8886945..94bd2d8fa 100644 --- a/tsconfig.strict.json +++ b/tsconfig.strict.json @@ -56,7 +56,6 @@ "./src/GitHub/GitHubConnector.ts", "./src/Index.ts", "./src/NotebookWorkspaceManager/NotebookWorkspaceResourceProviderMockClients.ts", - "./src/PlatformType.ts", "./src/ReactDevTools.ts", "./src/ResourceProvider/IResourceProviderClient.ts", "./src/Shared/ExplorerSettings.ts",