From 07d242f9728a455dbf109c468bd4012a6e26423a Mon Sep 17 00:00:00 2001 From: JustinKol <144163838+JustinKol@users.noreply.github.com> Date: Wed, 4 Oct 2023 14:23:22 -0400 Subject: [PATCH] Fixed setup save queries within serverless accounts (#1626) * Fixed setup save queries within serverless accounts * Fixed format * ran prettier --- src/Common/QueriesClient.ts | 50 ++++++++++++------- src/Contracts/DataModels.ts | 2 +- .../Panes/SaveQueryPane/SaveQueryPane.tsx | 1 + 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/Common/QueriesClient.ts b/src/Common/QueriesClient.ts index 7e7fd03cd..0fd79a902 100644 --- a/src/Common/QueriesClient.ts +++ b/src/Common/QueriesClient.ts @@ -13,6 +13,7 @@ import { createDocument } from "./dataAccess/createDocument"; import { deleteDocument } from "./dataAccess/deleteDocument"; import { queryDocuments } from "./dataAccess/queryDocuments"; import { handleError } from "./ErrorHandlingUtils"; +import { isServerlessAccount } from "Utils/CapabilityUtils"; export class QueriesClient { private static readonly PartitionKey: DataModels.PartitionKey = { @@ -32,25 +33,36 @@ export class QueriesClient { } const clearMessage = NotificationConsoleUtils.logConsoleProgress("Setting up account for saving queries"); - return createCollection({ - collectionId: SavedQueries.CollectionName, - createNewDatabase: true, - databaseId: SavedQueries.DatabaseName, - partitionKey: QueriesClient.PartitionKey, - offerThroughput: SavedQueries.OfferThroughput, - databaseLevelThroughput: false, - }) - .then( - (collection: DataModels.Collection) => { - NotificationConsoleUtils.logConsoleInfo("Successfully set up account for saving queries"); - return Promise.resolve(collection); - }, - (error: any) => { - handleError(error, "setupQueriesCollection", "Failed to set up account for saving queries"); - return Promise.reject(error); - }, - ) - .finally(() => clearMessage()); + + if (isServerlessAccount()) { + return createCollection({ + collectionId: SavedQueries.CollectionName, + createNewDatabase: true, + databaseId: SavedQueries.DatabaseName, + partitionKey: QueriesClient.PartitionKey, + databaseLevelThroughput: false, + }); + } else { + return createCollection({ + collectionId: SavedQueries.CollectionName, + createNewDatabase: true, + databaseId: SavedQueries.DatabaseName, + partitionKey: QueriesClient.PartitionKey, + offerThroughput: SavedQueries.OfferThroughput, + databaseLevelThroughput: false, + }) + .then( + (collection: DataModels.Collection) => { + NotificationConsoleUtils.logConsoleInfo("Successfully set up account for saving queries"); + return Promise.resolve(collection); + }, + (error: any) => { + handleError(error, "setupQueriesCollection", "Failed to set up account for saving queries"); + return Promise.reject(error); + }, + ) + .finally(() => clearMessage()); + } } public async saveQuery(query: DataModels.Query): Promise { diff --git a/src/Contracts/DataModels.ts b/src/Contracts/DataModels.ts index 4e82f803b..bb66d1508 100644 --- a/src/Contracts/DataModels.ts +++ b/src/Contracts/DataModels.ts @@ -318,7 +318,7 @@ export interface CreateCollectionParams { collectionId: string; databaseId: string; databaseLevelThroughput: boolean; - offerThroughput: number; + offerThroughput?: number; analyticalStorageTtl?: number; autoPilotMaxThroughput?: number; indexingPolicy?: IndexingPolicy; diff --git a/src/Explorer/Panes/SaveQueryPane/SaveQueryPane.tsx b/src/Explorer/Panes/SaveQueryPane/SaveQueryPane.tsx index ea04dc71a..b7c43a08f 100644 --- a/src/Explorer/Panes/SaveQueryPane/SaveQueryPane.tsx +++ b/src/Explorer/Panes/SaveQueryPane/SaveQueryPane.tsx @@ -113,6 +113,7 @@ export const SaveQueryPane: FunctionComponent = ({ }, startKey, ); + closeSidePanel(); } catch (error) { const errorMessage = getErrorMessage(error); traceFailure(