From 3d02f072625a0fe736a038469aa99f8e756607fa Mon Sep 17 00:00:00 2001 From: Armando Trejo Oliver Date: Thu, 24 Aug 2023 12:56:31 -0700 Subject: [PATCH] Add poolId as parameter to allocateContainer (#1588) --- src/Explorer/Explorer.tsx | 16 ++++++++-------- .../CommandBar/CommandBarComponentAdapter.tsx | 8 +++++--- src/Explorer/Menus/CommandBar/CommandBarUtil.tsx | 6 +++--- .../CommandBar/ConnectionStatusComponent.tsx | 11 +++++++---- .../Panes/CopyNotebookPane/CopyNotebookPane.tsx | 6 +++--- src/Explorer/QueryCopilot/QueryCopilotTab.tsx | 3 ++- .../QueryCopilot/Shared/QueryCopilotClient.ts | 10 +++++++--- src/Explorer/Tabs/QuickstartTab.tsx | 3 ++- src/Explorer/Tree/Collection.ts | 12 ++++++------ src/Utils/GalleryUtils.ts | 4 ++-- 10 files changed, 45 insertions(+), 34 deletions(-) diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index 19811a437..6df15f9eb 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -385,7 +385,7 @@ export default class Explorer { this._isInitializingNotebooks = false; } - public async allocateContainer(): Promise { + public async allocateContainer(poolId: PoolIdType): Promise { const notebookServerInfo = useNotebook.getState().notebookServerInfo; const isAllocating = useNotebook.getState().isAllocating; if ( @@ -395,7 +395,7 @@ export default class Explorer { ) { const provisionData: IProvisionData = { cosmosEndpoint: userContext?.databaseAccount?.properties?.documentEndpoint, - poolId: PoolIdType.QueryCopilot, + poolId: poolId, }; const connectionStatus: ContainerConnectionInfo = { status: ConnectionStatusType.Connecting, @@ -755,7 +755,7 @@ export default class Explorer { throw new Error(`Invalid notebookContentItem: ${notebookContentItem}`); } if (notebookContentItem.type === NotebookContentItemType.Notebook && useNotebook.getState().isPhoenixNotebooks) { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); } const notebookTabs = useTabs @@ -980,7 +980,7 @@ export default class Explorer { } if (useNotebook.getState().isPhoenixNotebooks) { if (isGithubTree) { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); parent = parent || this.resourceTree.myNotebooksContentRoot; this.createNewNoteBook(parent, isGithubTree); } else { @@ -989,7 +989,7 @@ export default class Explorer { undefined, "Create", async () => { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); parent = parent || this.resourceTree.myNotebooksContentRoot; this.createNewNoteBook(parent, isGithubTree); }, @@ -1068,7 +1068,7 @@ export default class Explorer { public async openNotebookTerminal(kind: ViewModels.TerminalKind): Promise { if (useNotebook.getState().isPhoenixFeatures) { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); const notebookServerInfo = useNotebook.getState().notebookServerInfo; if (notebookServerInfo && notebookServerInfo.notebookServerEndpoint !== undefined) { this.connectToNotebookTerminal(kind); @@ -1212,7 +1212,7 @@ export default class Explorer { await useNotebook.getState().getPhoenixStatus(); } if (useNotebook.getState().isPhoenixNotebooks) { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); } // We still use github urls like https://github.com/Azure-Samples/cosmos-notebooks/blob/master/CSharp_quickstarts/GettingStarted_CSharp.ipynb @@ -1249,7 +1249,7 @@ export default class Explorer { undefined, "Upload", async () => { - await this.allocateContainer(); + await this.allocateContainer(PoolIdType.DefaultPoolId); parent = parent || this.resourceTree.myNotebooksContentRoot; this.uploadFilePanel(parent); }, diff --git a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx index 9b69e2a9b..3eaf0507b 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarComponentAdapter.tsx @@ -5,10 +5,10 @@ */ import { CommandBar as FluentCommandBar, ICommandBarItemProps } from "@fluentui/react"; import { useNotebook } from "Explorer/Notebook/useNotebook"; -import * as React from "react"; import { userContext } from "UserContext"; +import * as React from "react"; import create, { UseStore } from "zustand"; -import { ConnectionStatusType, StyleConstants } from "../../../Common/Constants"; +import { ConnectionStatusType, PoolIdType, StyleConstants } from "../../../Common/Constants"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; import Explorer from "../../Explorer"; import { useSelectedNode } from "../../useSelectedNode"; @@ -76,7 +76,9 @@ export const CommandBar: React.FC = ({ container }: Props) => { (useNotebook.getState().isPhoenixNotebooks || useNotebook.getState().isPhoenixFeatures) && connectionInfo?.status !== ConnectionStatusType.Connect ) { - uiFabricControlButtons.unshift(CommandBarUtil.createConnectionStatus(container, "connectionStatus")); + uiFabricControlButtons.unshift( + CommandBarUtil.createConnectionStatus(container, PoolIdType.DefaultPoolId, "connectionStatus") + ); } return ( diff --git a/src/Explorer/Menus/CommandBar/CommandBarUtil.tsx b/src/Explorer/Menus/CommandBar/CommandBarUtil.tsx index e3cf556a6..c3172da63 100644 --- a/src/Explorer/Menus/CommandBar/CommandBarUtil.tsx +++ b/src/Explorer/Menus/CommandBar/CommandBarUtil.tsx @@ -9,7 +9,7 @@ import { import * as React from "react"; import _ from "underscore"; import ChevronDownIcon from "../../../../images/Chevron_down.svg"; -import { StyleConstants } from "../../../Common/Constants"; +import { PoolIdType, StyleConstants } from "../../../Common/Constants"; import { Action, ActionModifiers } from "../../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; import { CommandButtonComponentProps } from "../../Controls/CommandButton/CommandButtonComponent"; @@ -204,9 +204,9 @@ export const createMemoryTracker = (key: string): ICommandBarItemProps => { }; }; -export const createConnectionStatus = (container: Explorer, key: string): ICommandBarItemProps => { +export const createConnectionStatus = (container: Explorer, poolId: PoolIdType, key: string): ICommandBarItemProps => { return { key, - onRender: () => , + onRender: () => , }; }; diff --git a/src/Explorer/Menus/CommandBar/ConnectionStatusComponent.tsx b/src/Explorer/Menus/CommandBar/ConnectionStatusComponent.tsx index 520608acd..bf7e6be25 100644 --- a/src/Explorer/Menus/CommandBar/ConnectionStatusComponent.tsx +++ b/src/Explorer/Menus/CommandBar/ConnectionStatusComponent.tsx @@ -14,14 +14,15 @@ import { useId } from "@fluentui/react-hooks"; import { ActionButton, DefaultButton } from "@fluentui/react/lib/Button"; import * as React from "react"; import "../../../../less/hostedexplorer.less"; -import { ConnectionStatusType, ContainerStatusType, Notebook } from "../../../Common/Constants"; +import { ConnectionStatusType, ContainerStatusType, Notebook, PoolIdType } from "../../../Common/Constants"; import Explorer from "../../Explorer"; import { useNotebook } from "../../Notebook/useNotebook"; import "../CommandBar/ConnectionStatusComponent.less"; interface Props { container: Explorer; + poolId: PoolIdType; } -export const ConnectionStatus: React.FC = ({ container }: Props): JSX.Element => { +export const ConnectionStatus: React.FC = ({ container, poolId }: Props): JSX.Element => { const connectionInfo = useNotebook((state) => state.connectionInfo); const [second, setSecond] = React.useState("00"); const [minute, setMinute] = React.useState("00"); @@ -93,7 +94,7 @@ export const ConnectionStatus: React.FC = ({ container }: Props): JSX.Ele (connectionInfo.status === ConnectionStatusType.Connect || connectionInfo.status === ConnectionStatusType.Reconnect) ) { return ( - container.allocateContainer()}> + container.allocateContainer(poolId)}> @@ -133,7 +134,9 @@ export const ConnectionStatus: React.FC = ({ container }: Props): JSX.Ele id={buttonId} className={connectionInfo.status === ConnectionStatusType.Failed ? "commandReactBtn" : "connectedReactBtn"} onClick={(e: React.MouseEvent) => - connectionInfo.status === ConnectionStatusType.Failed ? container.allocateContainer() : e.preventDefault() + connectionInfo.status === ConnectionStatusType.Failed + ? container.allocateContainer(poolId) + : e.preventDefault() } > diff --git a/src/Explorer/Panes/CopyNotebookPane/CopyNotebookPane.tsx b/src/Explorer/Panes/CopyNotebookPane/CopyNotebookPane.tsx index f4834bac3..0c8a9a5f1 100644 --- a/src/Explorer/Panes/CopyNotebookPane/CopyNotebookPane.tsx +++ b/src/Explorer/Panes/CopyNotebookPane/CopyNotebookPane.tsx @@ -1,12 +1,12 @@ import { IDropdownOption } from "@fluentui/react"; import React, { FormEvent, FunctionComponent, useEffect, useState } from "react"; -import { HttpStatusCodes } from "../../../Common/Constants"; +import { HttpStatusCodes, PoolIdType } from "../../../Common/Constants"; import { getErrorMessage, handleError } from "../../../Common/ErrorHandlingUtils"; import { GitHubOAuthService } from "../../../GitHub/GitHubOAuthService"; -import { useSidePanel } from "../../../hooks/useSidePanel"; import { IPinnedRepo, JunoClient } from "../../../Juno/JunoClient"; import * as GitHubUtils from "../../../Utils/GitHubUtils"; import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils"; +import { useSidePanel } from "../../../hooks/useSidePanel"; import Explorer from "../../Explorer"; import { NotebookContentItem, NotebookContentItemType } from "../../Notebook/NotebookContentItem"; import { useNotebook } from "../../Notebook/useNotebook"; @@ -109,7 +109,7 @@ export const CopyNotebookPane: FunctionComponent = ({ }; isGithubTree = false; if (useNotebook.getState().isPhoenixNotebooks) { - await container.allocateContainer(); + await container.allocateContainer(PoolIdType.DefaultPoolId); } break; diff --git a/src/Explorer/QueryCopilot/QueryCopilotTab.tsx b/src/Explorer/QueryCopilot/QueryCopilotTab.tsx index b9b588f49..934183517 100644 --- a/src/Explorer/QueryCopilot/QueryCopilotTab.tsx +++ b/src/Explorer/QueryCopilot/QueryCopilotTab.tsx @@ -18,6 +18,7 @@ import { } from "@fluentui/react"; import { useBoolean } from "@fluentui/react-hooks"; import { + PoolIdType, QueryCopilotSampleContainerId, QueryCopilotSampleContainerSchema, ShortenedQueryCopilotSampleContainerSchema, @@ -180,7 +181,7 @@ export const QueryCopilotTab: React.FC = ({ explorer }: Query const generateSQLQuery = async (): Promise => { try { if (shouldAllocateContainer && userContext.features.enableCopilotPhoenixGateaway) { - await explorer.allocateContainer(); + await explorer.allocateContainer(PoolIdType.QueryCopilot); setShouldAllocateContainer(false); } diff --git a/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts b/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts index 8ea00bc9b..e27a93386 100644 --- a/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts +++ b/src/Explorer/QueryCopilot/Shared/QueryCopilotClient.ts @@ -1,4 +1,8 @@ -import { QueryCopilotSampleContainerSchema, ShortenedQueryCopilotSampleContainerSchema } from "Common/Constants"; +import { + PoolIdType, + QueryCopilotSampleContainerSchema, + ShortenedQueryCopilotSampleContainerSchema, +} from "Common/Constants"; import { handleError } from "Common/ErrorHandlingUtils"; import { createUri } from "Common/UrlUtility"; import Explorer from "Explorer/Explorer"; @@ -24,7 +28,7 @@ export const SendQueryRequest = async ({ .setChatMessages([...useQueryCopilot.getState().chatMessages, { source: 0, message: userPrompt }]); try { if (useQueryCopilot.getState().shouldAllocateContainer) { - await explorer.allocateContainer(); + await explorer.allocateContainer(PoolIdType.DefaultPoolId); useQueryCopilot.getState().setShouldAllocateContainer(false); } @@ -98,7 +102,7 @@ export const SubmitFeedback = async ({ contact: contact || "", }; if (shouldAllocateContainer && userContext.features.enableCopilotPhoenixGateaway) { - await explorer.allocateContainer(); + await explorer.allocateContainer(PoolIdType.DefaultPoolId); setShouldAllocateContainer(false); } const serverInfo = useNotebook.getState().notebookServerInfo; diff --git a/src/Explorer/Tabs/QuickstartTab.tsx b/src/Explorer/Tabs/QuickstartTab.tsx index 4d0bf6118..5de5d15f9 100644 --- a/src/Explorer/Tabs/QuickstartTab.tsx +++ b/src/Explorer/Tabs/QuickstartTab.tsx @@ -1,4 +1,5 @@ import { Spinner, SpinnerSize, Stack, Text } from "@fluentui/react"; +import { PoolIdType } from "Common/Constants"; import { configContext } from "ConfigContext"; import { NotebookWorkspaceConnectionInfo, PostgresFirewallRule } from "Contracts/DataModels"; import { NotebookTerminalComponent } from "Explorer/Controls/Notebook/NotebookTerminalComponent"; @@ -51,7 +52,7 @@ export const QuickstartTab: React.FC = ({ explorer }: Quicks }); useEffect(() => { - explorer.allocateContainer(); + explorer.allocateContainer(PoolIdType.DefaultPoolId); }, []); return ( diff --git a/src/Explorer/Tree/Collection.ts b/src/Explorer/Tree/Collection.ts index d09ca57f5..860ac0d2c 100644 --- a/src/Explorer/Tree/Collection.ts +++ b/src/Explorer/Tree/Collection.ts @@ -3,6 +3,9 @@ import { useNotebook } from "Explorer/Notebook/useNotebook"; import * as ko from "knockout"; import * as _ from "underscore"; import * as Constants from "../../Common/Constants"; +import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils"; +import * as Logger from "../../Common/Logger"; +import { fetchPortalNotifications } from "../../Common/PortalNotifications"; import { bulkCreateDocument } from "../../Common/dataAccess/bulkCreateDocument"; import { createDocument } from "../../Common/dataAccess/createDocument"; import { getCollectionUsageSizeInKB } from "../../Common/dataAccess/getCollectionDataUsageSize"; @@ -10,19 +13,16 @@ import { readCollectionOffer } from "../../Common/dataAccess/readCollectionOffer import { readStoredProcedures } from "../../Common/dataAccess/readStoredProcedures"; import { readTriggers } from "../../Common/dataAccess/readTriggers"; import { readUserDefinedFunctions } from "../../Common/dataAccess/readUserDefinedFunctions"; -import { getErrorMessage, getErrorStack } from "../../Common/ErrorHandlingUtils"; -import * as Logger from "../../Common/Logger"; -import { fetchPortalNotifications } from "../../Common/PortalNotifications"; import * as DataModels from "../../Contracts/DataModels"; import * as ViewModels from "../../Contracts/ViewModels"; import { UploadDetailsRecord } from "../../Contracts/ViewModels"; -import { useTabs } from "../../hooks/useTabs"; import { Action, ActionModifiers } from "../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../UserContext"; -import { SqlTriggerResource } from "../../Utils/arm/generatedClients/cosmos/types"; import { isServerlessAccount } from "../../Utils/CapabilityUtils"; import { logConsoleInfo } from "../../Utils/NotificationConsoleUtils"; +import { SqlTriggerResource } from "../../Utils/arm/generatedClients/cosmos/types"; +import { useTabs } from "../../hooks/useTabs"; import Explorer from "../Explorer"; import { useCommandBar } from "../Menus/CommandBar/CommandBarComponentAdapter"; import { CassandraAPIDataClient, CassandraTableKey, CassandraTableKeys } from "../Tables/TableDataClient"; @@ -526,7 +526,7 @@ export default class Collection implements ViewModels.Collection { public onSchemaAnalyzerClick = async () => { if (useNotebook.getState().isPhoenixFeatures) { - await this.container.allocateContainer(); + await this.container.allocateContainer(Constants.PoolIdType.DefaultPoolId); } useSelectedNode.getState().setSelectedNode(this); this.selectedSubnodeKind(ViewModels.CollectionTabKind.SchemaAnalyzer); diff --git a/src/Utils/GalleryUtils.ts b/src/Utils/GalleryUtils.ts index 635d46e2f..98fe185bc 100644 --- a/src/Utils/GalleryUtils.ts +++ b/src/Utils/GalleryUtils.ts @@ -1,7 +1,7 @@ import { IChoiceGroupOption, IChoiceGroupProps, IProgressIndicatorProps } from "@fluentui/react"; import { Notebook } from "@nteract/commutable"; import { NotebookV4 } from "@nteract/commutable/lib/v4"; -import { HttpStatusCodes } from "../Common/Constants"; +import { HttpStatusCodes, PoolIdType } from "../Common/Constants"; import { getErrorMessage, getErrorStack, handleError } from "../Common/ErrorHandlingUtils"; import { TextFieldProps, useDialog } from "../Explorer/Controls/Dialog"; import { @@ -229,7 +229,7 @@ export function downloadItem( "Download", async () => { if (useNotebook.getState().isPhoenixNotebooks) { - await container.allocateContainer(); + await container.allocateContainer(PoolIdType.DefaultPoolId); } const notebookServerInfo = useNotebook.getState().notebookServerInfo; if (notebookServerInfo && notebookServerInfo.notebookServerEndpoint !== undefined) {