From 50f83cde87494e1aad88a83f23c9265b05b86c6c Mon Sep 17 00:00:00 2001 From: Hardikkumar Nai <80053762+hardiknai-techm@users.noreply.github.com> Date: Thu, 27 May 2021 01:41:47 +0530 Subject: [PATCH] Remove Explorer.collectionCreationDefaults (#840) Co-authored-by: Steve Faulkner --- src/Contracts/ViewModels.ts | 20 +--------- .../SettingsComponent.test.tsx.snap | 40 ------------------- src/Explorer/Explorer.tsx | 5 --- .../CassandraAddCollectionPane.tsx | 4 +- .../GitHubReposPanel.test.tsx.snap | 10 ----- .../StringInputPane.test.tsx.snap | 10 ----- ...eteDatabaseConfirmationPanel.test.tsx.snap | 10 ----- src/Shared/AddCollectionUtility.ts | 2 +- src/UserContext.ts | 22 +++++++++- src/hooks/useKnockoutExplorer.ts | 1 + 10 files changed, 26 insertions(+), 98 deletions(-) diff --git a/src/Contracts/ViewModels.ts b/src/Contracts/ViewModels.ts index b74862008..25df44c7f 100644 --- a/src/Contracts/ViewModels.ts +++ b/src/Contracts/ViewModels.ts @@ -15,6 +15,7 @@ import StoredProcedure from "../Explorer/Tree/StoredProcedure"; import Trigger from "../Explorer/Tree/Trigger"; import UserDefinedFunction from "../Explorer/Tree/UserDefinedFunction"; import { SelfServeType } from "../SelfServe/SelfServeUtils"; +import { CollectionCreationDefaults } from "../UserContext"; import { SqlTriggerResource } from "../Utils/arm/generatedClients/cosmos/types"; import * as DataModels from "./DataModels"; import { SubscriptionType } from "./SubscriptionType"; @@ -411,25 +412,6 @@ export interface SelfServeFrameInputs { flights?: readonly string[]; } -export interface CollectionCreationDefaults { - storage: string; - throughput: ThroughputDefaults; -} - -export interface ThroughputDefaults { - fixed: number; - unlimited: - | number - | { - collectionThreshold: number; - lessThanOrEqualToThreshold: number; - greatThanThreshold: number; - }; - unlimitedmax: number; - unlimitedmin: number; - shared: number; -} - export class MonacoEditorSettings { public readonly language: string; public readonly readOnly: boolean; diff --git a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap index 7e616e44d..81ba20a46 100644 --- a/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap +++ b/src/Explorer/Controls/Settings/__snapshots__/SettingsComponent.test.tsx.snap @@ -33,16 +33,6 @@ exports[`SettingsComponent renders 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], @@ -136,16 +126,6 @@ exports[`SettingsComponent renders 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], @@ -252,16 +232,6 @@ exports[`SettingsComponent renders 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], @@ -355,16 +325,6 @@ exports[`SettingsComponent renders 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index fae2047ea..540d848d0 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -21,7 +21,6 @@ import { GitHubOAuthService } from "../GitHub/GitHubOAuthService"; import { IGalleryItem, JunoClient } from "../Juno/JunoClient"; import { NotebookWorkspaceManager } from "../NotebookWorkspaceManager/NotebookWorkspaceManager"; import { RouteHandler } from "../RouteHandlers/RouteHandler"; -import * as SharedConstants from "../Shared/Constants"; import { ExplorerSettings } from "../Shared/ExplorerSettings"; import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor"; @@ -93,7 +92,6 @@ export interface ExplorerParams { export default class Explorer { public collapsedResourceTreeWidth: number = ExplorerMetrics.CollapsedResourceTreeWidth; - public collectionCreationDefaults: ViewModels.CollectionCreationDefaults = SharedConstants.CollectionCreationDefaults; public isFixedCollectionWithSharedThroughputSupported: ko.Computed; public isServerlessEnabled: ko.Computed; public isAccountReady: ko.Observable; @@ -790,9 +788,6 @@ export default class Explorer { if (process.env.NODE_ENV === "development") { sessionStorage.setItem("portalDataExplorerInitMessage", JSON.stringify(inputs)); } - if (inputs.defaultCollectionThroughput) { - this.collectionCreationDefaults = inputs.defaultCollectionThroughput; - } this.isAccountReady(true); } } diff --git a/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx b/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx index 7fcb77f7d..03fb49ebe 100644 --- a/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx +++ b/src/Explorer/Panes/CassandraAddCollectionPane/CassandraAddCollectionPane.tsx @@ -28,12 +28,12 @@ export const CassandraAddCollectionPane: FunctionComponent { - const throughputDefaults = container.collectionCreationDefaults.throughput; + const throughputDefaults = userContext.collectionCreationDefaults.throughput; const [createTableQuery, setCreateTableQuery] = useState("CREATE TABLE "); const [keyspaceId, setKeyspaceId] = useState(""); const [tableId, setTableId] = useState(""); const [throughput, setThroughput] = useState( - AddCollectionUtility.getMaxThroughput(container.collectionCreationDefaults, container) + AddCollectionUtility.getMaxThroughput(userContext.collectionCreationDefaults, container) ); const [isAutoPilotSelected, setIsAutoPilotSelected] = useState(userContext.features.autoscaleDefault); diff --git a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap index cc763fb09..8a69edf54 100644 --- a/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap +++ b/src/Explorer/Panes/GitHubReposPanel/__snapshots__/GitHubReposPanel.test.tsx.snap @@ -22,16 +22,6 @@ exports[`GitHub Repos Panel should render Default properly 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], diff --git a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap index cd44f0ae8..2faa53f5d 100644 --- a/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap +++ b/src/Explorer/Panes/StringInputPane/__snapshots__/StringInputPane.test.tsx.snap @@ -12,16 +12,6 @@ exports[`StringInput Pane should render Create new directory properly 1`] = ` "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], diff --git a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap index c5d362d48..eb1a1196d 100644 --- a/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap +++ b/src/Explorer/Panes/__snapshots__/DeleteDatabaseConfirmationPanel.test.tsx.snap @@ -10,16 +10,6 @@ exports[`Delete Database Confirmation Pane submit() Should call delete database "canSaveQueries": [Function], "closeSidePanel": undefined, "collapsedResourceTreeWidth": 36, - "collectionCreationDefaults": Object { - "storage": "100", - "throughput": Object { - "fixed": 400, - "shared": 400, - "unlimited": 400, - "unlimitedmax": 1000000, - "unlimitedmin": 400, - }, - }, "commandBarComponentAdapter": CommandBarComponentAdapter { "container": [Circular], "isNotebookTabActive": [Function], diff --git a/src/Shared/AddCollectionUtility.ts b/src/Shared/AddCollectionUtility.ts index c81319a62..7e11d8b82 100644 --- a/src/Shared/AddCollectionUtility.ts +++ b/src/Shared/AddCollectionUtility.ts @@ -1,6 +1,6 @@ import { any } from "underscore"; -import { CollectionCreationDefaults } from "../Contracts/ViewModels"; import Explorer from "../Explorer/Explorer"; +import { CollectionCreationDefaults } from "../UserContext"; export const getMaxThroughput = (defaults: CollectionCreationDefaults, container: Explorer): number => { const throughput = defaults.throughput.unlimited; diff --git a/src/UserContext.ts b/src/UserContext.ts index 4655411ad..78b68ffec 100644 --- a/src/UserContext.ts +++ b/src/UserContext.ts @@ -2,7 +2,25 @@ import { AuthType } from "./AuthType"; import { DatabaseAccount } from "./Contracts/DataModels"; import { SubscriptionType } from "./Contracts/SubscriptionType"; import { extractFeatures, Features } from "./Platform/Hosted/extractFeatures"; -import { CollectionCreation } from "./Shared/Constants"; +import { CollectionCreation, CollectionCreationDefaults } from "./Shared/Constants"; + +interface ThroughputDefaults { + fixed: number; + unlimited: + | number + | { + collectionThreshold: number; + lessThanOrEqualToThreshold: number; + greatThanThreshold: number; + }; + unlimitedmax: number; + unlimitedmin: number; + shared: number; +} +export interface CollectionCreationDefaults { + storage: string; + throughput: ThroughputDefaults; +} interface UserContext { readonly authType?: AuthType; @@ -26,6 +44,7 @@ interface UserContext { readonly features: Features; readonly addCollectionFlight: string; readonly hasWriteAccess: boolean; + collectionCreationDefaults: CollectionCreationDefaults; } export type ApiType = "SQL" | "Mongo" | "Gremlin" | "Tables" | "Cassandra"; @@ -43,6 +62,7 @@ const userContext: UserContext = { useSDKOperations, addCollectionFlight: CollectionCreation.DefaultAddCollectionDefaultFlight, subscriptionType: CollectionCreation.DefaultSubscriptionType, + collectionCreationDefaults: CollectionCreationDefaults, }; function updateUserContext(newContext: Partial): void { diff --git a/src/hooks/useKnockoutExplorer.ts b/src/hooks/useKnockoutExplorer.ts index 1f197ed13..e57b4254f 100644 --- a/src/hooks/useKnockoutExplorer.ts +++ b/src/hooks/useKnockoutExplorer.ts @@ -299,6 +299,7 @@ function updateContextsFromPortalMessage(inputs: DataExplorerInputsFrame) { portalEnv: inputs.serverId as PortalEnv, hasWriteAccess: inputs.hasWriteAccess ?? true, addCollectionFlight: inputs.addCollectionDefaultFlight || CollectionCreation.DefaultAddCollectionDefaultFlight, + collectionCreationDefaults: inputs.defaultCollectionThroughput, }); if (inputs.features) { Object.assign(userContext.features, extractFeatures(new URLSearchParams(inputs.features)));