import { PrimaryButton } from "@fluentui/react"; import { useBoolean } from "@fluentui/react-hooks"; import React, { FunctionComponent, KeyboardEvent, useState } from "react"; import { Areas, NormalizedEventKey } from "../../../Common/Constants"; import { getErrorMessage, getErrorStack } from "../../../Common/ErrorHandlingUtils"; import { useSidePanel } from "../../../hooks/useSidePanel"; import { Action } from "../../../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../../../Shared/Telemetry/TelemetryProcessor"; import { userContext } from "../../../UserContext"; import { createOrUpdate } from "../../../Utils/arm/generatedClients/cosmosNotebooks/notebookWorkspaces"; import * as NotificationConsoleUtils from "../../../Utils/NotificationConsoleUtils"; import Explorer from "../../Explorer"; import { PanelInfoErrorComponent } from "../PanelInfoErrorComponent"; import { PanelLoadingScreen } from "../PanelLoadingScreen"; interface SetupNoteBooksPanelProps { explorer: Explorer; panelTitle: string; panelDescription: string; } export const SetupNoteBooksPanel: FunctionComponent = ({ explorer, panelTitle, panelDescription, }: SetupNoteBooksPanelProps): JSX.Element => { const closeSidePanel = useSidePanel((state) => state.closeSidePanel); const description = panelDescription; const [isLoading, { setTrue: setLoadingTrue, setFalse: setLoadingFalse }] = useBoolean(false); const [errorMessage, setErrorMessage] = useState(""); const [showErrorDetails, setShowErrorDetails] = useState(false); const onCompleteSetupClick = async () => { await setupNotebookWorkspace(); }; const onCompleteSetupKeyPress = async (event: KeyboardEvent) => { if (event.key === " " || event.key === NormalizedEventKey.Enter) { await setupNotebookWorkspace(); event.stopPropagation(); return false; } return true; }; const setupNotebookWorkspace = async (): Promise => { if (!explorer) { return; } const startKey: number = TelemetryProcessor.traceStart(Action.CreateNotebookWorkspace, { dataExplorerArea: Areas.ContextualPane, paneTitle: panelTitle, }); const clear = NotificationConsoleUtils.logConsoleProgress("Creating a new default notebook workspace"); try { setLoadingTrue(); await createOrUpdate( userContext.subscriptionId, userContext.resourceGroup, userContext.databaseAccount.name, "default" ); explorer.refreshExplorer(); closeSidePanel(); TelemetryProcessor.traceSuccess( Action.CreateNotebookWorkspace, { dataExplorerArea: Areas.ContextualPane, paneTitle: panelTitle, }, startKey ); NotificationConsoleUtils.logConsoleInfo("Successfully created a default notebook workspace for the account"); } catch (error) { const errorMessage = getErrorMessage(error); TelemetryProcessor.traceFailure( Action.CreateNotebookWorkspace, { dataExplorerArea: Areas.ContextualPane, paneTitle: panelTitle, error: errorMessage, errorStack: getErrorStack(error), }, startKey ); setErrorMessage(`Failed to setup a default notebook workspace: ${errorMessage}`); setShowErrorDetails(true); NotificationConsoleUtils.logConsoleError(`Failed to create a default notebook workspace: ${errorMessage}`); } finally { setLoadingFalse(); clear(); } }; return (
{errorMessage && ( )}
{description}
{isLoading && } ); };