import * as React from "react"; import { useBoolean } from "@uifabric/react-hooks"; import { HttpHeaders } from "../../../Common/Constants"; import { GenerateTokenResponse } from "../../../Contracts/DataModels"; import { configContext } from "../../../ConfigContext"; import { AuthType } from "../../../AuthType"; import { isResourceTokenConnectionString } from "../Helpers/ResourceTokenUtils"; interface Props { connectionString: string; login: () => void; setEncryptedToken: (token: string) => void; setConnectionString: (connectionString: string) => void; setAuthType: (authType: AuthType) => void; } export const ConnectExplorer: React.FunctionComponent = ({ setEncryptedToken, login, setAuthType, connectionString, setConnectionString }: Props) => { const [isFormVisible, { setTrue: showForm }] = useBoolean(false); return (

Azure Cosmos DB

Welcome to Azure Cosmos DB

{isFormVisible ? (
{ event.preventDefault(); if (isResourceTokenConnectionString(connectionString)) { setAuthType(AuthType.ResourceToken); return; } const headers = new Headers(); headers.append(HttpHeaders.connectionString, connectionString); const url = configContext.BACKEND_ENDPOINT + "/api/guest/tokens/generateToken"; const response = await fetch(url, { headers, method: "POST" }); if (!response.ok) { throw response; } // This API has a quirk where it must be parsed twice const result: GenerateTokenResponse = JSON.parse(await response.json()); console.log(result.readWrite || result.read); setEncryptedToken(decodeURIComponent(result.readWrite || result.read)); setAuthType(AuthType.ConnectionString); }} >

Connect to your account with connection string

{ setConnectionString(event.target.value); }} /> Error notification

Sign In with Azure Account

) : (

Connect to your account with connection string

)}
); };