diff --git a/src/Common/dataAccess/readCollections.ts b/src/Common/dataAccess/readCollections.ts index c067afe49..4d77a0597 100644 --- a/src/Common/dataAccess/readCollections.ts +++ b/src/Common/dataAccess/readCollections.ts @@ -1,15 +1,15 @@ -import * as DataModels from "../../Contracts/DataModels"; import { AuthType } from "../../AuthType"; +import * as DataModels from "../../Contracts/DataModels"; import { DefaultAccountExperienceType } from "../../DefaultAccountExperienceType"; -import { client } from "../CosmosClient"; -import { handleError } from "../ErrorHandlingUtils"; -import { listSqlContainers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; +import { userContext } from "../../UserContext"; import { listCassandraTables } from "../../Utils/arm/generatedClients/2020-04-01/cassandraResources"; -import { listMongoDBCollections } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; import { listGremlinGraphs } from "../../Utils/arm/generatedClients/2020-04-01/gremlinResources"; +import { listMongoDBCollections } from "../../Utils/arm/generatedClients/2020-04-01/mongoDBResources"; +import { listSqlContainers } from "../../Utils/arm/generatedClients/2020-04-01/sqlResources"; import { listTables } from "../../Utils/arm/generatedClients/2020-04-01/tableResources"; import { logConsoleProgress } from "../../Utils/NotificationConsoleUtils"; -import { userContext } from "../../UserContext"; +import { client } from "../CosmosClient"; +import { handleError } from "../ErrorHandlingUtils"; export async function readCollections(databaseId: string): Promise { const clearMessage = logConsoleProgress(`Querying containers for database ${databaseId}`); @@ -17,7 +17,6 @@ export async function readCollections(databaseId: string): Promise, options: RequestOptions = {} ): Promise { let collection: Collection; @@ -43,7 +41,6 @@ export async function updateCollection( if ( userContext.authType === AuthType.AAD && !userContext.useSDKOperations && - userContext.defaultExperience !== DefaultAccountExperienceType.MongoDB && userContext.defaultExperience !== DefaultAccountExperienceType.Table ) { collection = await updateCollectionWithARM(databaseId, collectionId, newCollection); @@ -69,7 +66,7 @@ export async function updateCollection( async function updateCollectionWithARM( databaseId: string, collectionId: string, - newCollection: Collection + newCollection: Partial ): Promise { const subscriptionId = userContext.subscriptionId; const resourceGroup = userContext.resourceGroup; @@ -85,6 +82,15 @@ async function updateCollectionWithARM( return updateGremlinGraph(databaseId, collectionId, subscriptionId, resourceGroup, accountName, newCollection); case DefaultAccountExperienceType.Table: return updateTable(collectionId, subscriptionId, resourceGroup, accountName, newCollection); + case DefaultAccountExperienceType.MongoDB: + return updateMongoDBCollection( + databaseId, + collectionId, + subscriptionId, + resourceGroup, + accountName, + newCollection + ); default: throw new Error(`Unsupported default experience type: ${defaultExperience}`); } @@ -96,7 +102,7 @@ async function updateSqlContainer( subscriptionId: string, resourceGroup: string, accountName: string, - newCollection: Collection + newCollection: Partial ): Promise { const getResponse = await getSqlContainer(subscriptionId, resourceGroup, accountName, databaseId, collectionId); if (getResponse && getResponse.properties && getResponse.properties.resource) { @@ -115,35 +121,26 @@ async function updateSqlContainer( throw new Error(`Sql container to update does not exist. Database id: ${databaseId} Collection id: ${collectionId}`); } -export async function updateMongoDBCollectionThroughRP( +export async function updateMongoDBCollection( databaseId: string, collectionId: string, - newCollection: MongoDBCollectionResource, - updateOptions?: CreateUpdateOptions -): Promise { - const subscriptionId = userContext.subscriptionId; - const resourceGroup = userContext.resourceGroup; - const accountName = userContext.databaseAccount.name; - + subscriptionId: string, + resourceGroup: string, + accountName: string, + newCollection: Partial +): Promise { const getResponse = await getMongoDBCollection(subscriptionId, resourceGroup, accountName, databaseId, collectionId); if (getResponse && getResponse.properties && getResponse.properties.resource) { - const updateParams: MongoDBCollectionCreateUpdateParameters = { - properties: { - resource: newCollection, - options: updateOptions, - }, - }; - + getResponse.properties.resource = newCollection as SqlContainerResource & ExtendedResourceProperties; const updateResponse = await createUpdateMongoDBCollection( subscriptionId, resourceGroup, accountName, databaseId, collectionId, - updateParams + getResponse as MongoDBCollectionCreateUpdateParameters ); - - return updateResponse && (updateResponse.properties.resource as MongoDBCollectionResource); + return updateResponse && (updateResponse.properties.resource as Collection); } throw new Error( @@ -157,7 +154,7 @@ async function updateCassandraTable( subscriptionId: string, resourceGroup: string, accountName: string, - newCollection: Collection + newCollection: Partial ): Promise { const getResponse = await getCassandraTable(subscriptionId, resourceGroup, accountName, databaseId, collectionId); if (getResponse && getResponse.properties && getResponse.properties.resource) { @@ -184,7 +181,7 @@ async function updateGremlinGraph( subscriptionId: string, resourceGroup: string, accountName: string, - newCollection: Collection + newCollection: Partial ): Promise { const getResponse = await getGremlinGraph(subscriptionId, resourceGroup, accountName, databaseId, collectionId); if (getResponse && getResponse.properties && getResponse.properties.resource) { @@ -208,7 +205,7 @@ async function updateTable( subscriptionId: string, resourceGroup: string, accountName: string, - newCollection: Collection + newCollection: Partial ): Promise { const getResponse = await getTable(subscriptionId, resourceGroup, accountName, collectionId); if (getResponse && getResponse.properties && getResponse.properties.resource) { diff --git a/src/Explorer/Controls/Settings/SettingsComponent.test.tsx b/src/Explorer/Controls/Settings/SettingsComponent.test.tsx index c6432aec2..538a8249c 100644 --- a/src/Explorer/Controls/Settings/SettingsComponent.test.tsx +++ b/src/Explorer/Controls/Settings/SettingsComponent.test.tsx @@ -1,11 +1,10 @@ import { shallow } from "enzyme"; import ko from "knockout"; import React from "react"; -import { updateCollection, updateMongoDBCollectionThroughRP } from "../../../Common/dataAccess/updateCollection"; +import { updateCollection } from "../../../Common/dataAccess/updateCollection"; import { updateOffer } from "../../../Common/dataAccess/updateOffer"; import * as DataModels from "../../../Contracts/DataModels"; import * as ViewModels from "../../../Contracts/ViewModels"; -import { MongoDBCollectionResource } from "../../../Utils/arm/generatedClients/2020-04-01/types"; import Explorer from "../../Explorer"; import { CollectionSettingsTabV2 } from "../../Tabs/SettingsTabV2"; import { SettingsComponent, SettingsComponentProps, SettingsComponentState } from "./SettingsComponent"; @@ -23,13 +22,8 @@ jest.mock("../../../Common/dataAccess/updateCollection", () => ({ changeFeedPolicy: undefined, analyticalStorageTtl: undefined, geospatialConfig: undefined, - } as DataModels.Collection), - updateMongoDBCollectionThroughRP: jest.fn().mockReturnValue({ - id: undefined, - shardKey: undefined, indexes: [], - analyticalStorageTtl: undefined, - } as MongoDBCollectionResource), + }), })); jest.mock("../../../Common/dataAccess/updateOffer", () => ({ updateOffer: jest.fn().mockReturnValue({} as DataModels.Offer), @@ -193,7 +187,6 @@ describe("SettingsComponent", () => { }; await settingsComponentInstance.onSaveClick(); expect(updateCollection).toBeCalled(); - expect(updateMongoDBCollectionThroughRP).toBeCalled(); expect(updateOffer).toBeCalled(); }); diff --git a/src/Explorer/Controls/Settings/SettingsComponent.tsx b/src/Explorer/Controls/Settings/SettingsComponent.tsx index 63c1c4b79..8aa91f50e 100644 --- a/src/Explorer/Controls/Settings/SettingsComponent.tsx +++ b/src/Explorer/Controls/Settings/SettingsComponent.tsx @@ -6,7 +6,7 @@ import { AuthType } from "../../../AuthType"; import * as Constants from "../../../Common/Constants"; import { getIndexTransformationProgress } from "../../../Common/dataAccess/getIndexTransformationProgress"; import { readMongoDBCollectionThroughRP } from "../../../Common/dataAccess/readMongoDBCollection"; -import { updateCollection, updateMongoDBCollectionThroughRP } from "../../../Common/dataAccess/updateCollection"; +import { updateCollection } from "../../../Common/dataAccess/updateCollection"; import { updateOffer } from "../../../Common/dataAccess/updateOffer"; import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils"; import * as DataModels from "../../../Contracts/DataModels"; @@ -782,12 +782,12 @@ export class SettingsComponent extends React.Component