/** * Accordion top class */ import { Image, Link, Stack, Text } from "@fluentui/react"; import * as React from "react"; import AddDatabaseIcon from "../../../images/AddDatabase.svg"; import NewQueryIcon from "../../../images/AddSqlQuery_16x16.svg"; import NewStoredProcedureIcon from "../../../images/AddStoredProcedure.svg"; import OpenQueryIcon from "../../../images/BrowseQuery.svg"; import ConnectIcon from "../../../images/Connect_color.svg"; import ContainersIcon from "../../../images/Containers.svg"; import CostIcon from "../../../images/Cost.svg"; import GreenCheckIcon from "../../../images/Green_check.svg"; import NewContainerIcon from "../../../images/Hero-new-container.svg"; import NewNotebookIcon from "../../../images/Hero-new-notebook.svg"; import SampleIcon from "../../../images/Hero-sample.svg"; import LinkIcon from "../../../images/Link_blue.svg"; import NotebookIcon from "../../../images/notebook/Notebook-resource.svg"; import NotebooksIcon from "../../../images/Notebooks.svg"; import QuickStartIcon from "../../../images/Quickstart_Lightning.svg"; import ScaleAndSettingsIcon from "../../../images/Scale_15x15.svg"; import CollectionIcon from "../../../images/tree-collection.svg"; import { AuthType } from "../../AuthType"; import * as Constants from "../../Common/Constants"; import * as ViewModels from "../../Contracts/ViewModels"; import { useSidePanel } from "../../hooks/useSidePanel"; import { userContext } from "../../UserContext"; import { getCollectionName, getDatabaseName } from "../../Utils/APITypeUtils"; import { FeaturePanelLauncher } from "../Controls/FeaturePanel/FeaturePanelLauncher"; import { DataSamplesUtil } from "../DataSamples/DataSamplesUtil"; import Explorer from "../Explorer"; import * as MostRecentActivity from "../MostRecentActivity/MostRecentActivity"; import { useNotebook } from "../Notebook/useNotebook"; import { AddDatabasePanel } from "../Panes/AddDatabasePanel/AddDatabasePanel"; import { BrowseQueriesPane } from "../Panes/BrowseQueriesPane/BrowseQueriesPane"; import { useDatabases } from "../useDatabases"; import { useSelectedNode } from "../useSelectedNode"; export interface SplashScreenItem { iconSrc: string; title: string; info?: string; description: string; onClick: () => void; } export interface SplashScreenProps { explorer: Explorer; } export class SplashScreen extends React.Component { private static readonly seeMoreItemTitle: string = "See more Cosmos DB documentation"; private static readonly seeMoreItemUrl: string = "https://aka.ms/cosmosdbdocument"; private static readonly dataModelingUrl = "https://docs.microsoft.com/azure/cosmos-db/modeling-data"; private static readonly throughputEstimatorUrl = "https://cosmos.azure.com/capacitycalculator"; private static readonly failoverUrl = "https://docs.microsoft.com/azure/cosmos-db/high-availability"; private readonly container: Explorer; private subscriptions: Array<{ dispose: () => void }>; constructor(props: SplashScreenProps) { super(props); this.container = props.explorer; this.subscriptions = []; } public componentWillUnmount() { while (this.subscriptions.length) { this.subscriptions.pop().dispose(); } } public componentDidMount() { this.subscriptions.push( { dispose: useNotebook.subscribe( () => this.setState({}), (state) => state.isNotebookEnabled ), }, { dispose: useSelectedNode.subscribe(() => this.setState({})) } ); } private clearMostRecent = (): void => { MostRecentActivity.mostRecentActivity.clear(userContext.databaseAccount?.id); this.setState({}); }; public render(): JSX.Element { const mainItems = this.createMainItems(); return (
Welcome to Cosmos DB
Globally distributed, multi-model database service for any scale
{mainItems.map((item) => ( this.onSplashScreenItemKeyPress(event, item.onClick)} tabIndex={0} role="button" >
{item.title}
{item.description}
))}
{userContext.features.enableNewQuickstart ? "Why Cosmos DB" : "Common Tasks"}
{userContext.features.enableNewQuickstart ? this.getNotebookItems() : this.getCommonTasksItems()}
{userContext.features.enableNewQuickstart ? "Top 3 things you need to know" : "Recents"}
{userContext.features.enableNewQuickstart ? this.top3Items() : this.getRecentItems()}
{userContext.features.enableNewQuickstart ? "Learning Resources" : "Tips"}
{userContext.features.enableNewQuickstart ? this.getLearningResourceItems() : this.getTipItems()}
); } /** * This exists to enable unit testing */ public createDataSampleUtil(): DataSamplesUtil { return new DataSamplesUtil(this.container); } /** * public for testing purposes */ public createMainItems(): SplashScreenItem[] { const dataSampleUtil = this.createDataSampleUtil(); if (userContext.features.enableNewQuickstart) { const launchQuickstartBtn = { iconSrc: QuickStartIcon, title: "Launch quick start", description: "Launch a quick start tutorial to get started with sample data", // TODO: replace onClick function onClick: () => 1, }; const newContainerBtn = { iconSrc: ContainersIcon, title: `New ${getCollectionName()}`, description: "Create a new container for storage and throughput", onClick: () => this.container.onNewCollectionClicked(), }; const connectBtn = { iconSrc: ConnectIcon, title: "Connect", description: "Prefer using your own choice of tooling? Find the connection string you need to connect", // TODO: replace onClick function onClick: () => 2, }; return [launchQuickstartBtn, newContainerBtn, connectBtn]; } else { const heroes: SplashScreenItem[] = []; if (dataSampleUtil.isSampleContainerCreationSupported()) { heroes.push({ iconSrc: SampleIcon, title: "Start with Sample", description: "Get started with a sample provided by Cosmos DB", onClick: () => dataSampleUtil.createSampleContainerAsync(), }); } heroes.push({ iconSrc: NewContainerIcon, title: `New ${getCollectionName()}`, description: "Create a new container for storage and throughput", onClick: () => this.container.onNewCollectionClicked(), }); if (useNotebook.getState().isPhoenixNotebooks) { heroes.push({ iconSrc: NewNotebookIcon, title: "New Notebook", description: "Create a notebook to start querying, visualizing, and modeling your data", onClick: () => this.container.onNewNotebookClicked(), }); } return heroes; } } private createCommonTaskItems(): SplashScreenItem[] { const items: SplashScreenItem[] = []; if (userContext.authType === AuthType.ResourceToken) { return items; } if (!useSelectedNode.getState().isDatabaseNodeOrNoneSelected()) { if (userContext.apiType === "SQL" || userContext.apiType === "Gremlin") { items.push({ iconSrc: NewQueryIcon, onClick: () => { const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); selectedCollection && selectedCollection.onNewQueryClick(selectedCollection, undefined); }, title: "New SQL Query", description: undefined, }); } else if (userContext.apiType === "Mongo") { items.push({ iconSrc: NewQueryIcon, onClick: () => { const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); selectedCollection && selectedCollection.onNewMongoQueryClick(selectedCollection, undefined); }, title: "New Query", description: undefined, }); } if (userContext.apiType === "SQL") { items.push({ iconSrc: OpenQueryIcon, title: "Open Query", description: undefined, onClick: () => useSidePanel .getState() .openSidePanel("Open Saved Queries", ), }); } if (userContext.apiType !== "Cassandra") { items.push({ iconSrc: NewStoredProcedureIcon, title: "New Stored Procedure", description: undefined, onClick: () => { const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); selectedCollection && selectedCollection.onNewStoredProcedureClick(selectedCollection, undefined); }, }); } /* Scale & Settings */ const isShared = useDatabases.getState().findSelectedDatabase()?.isDatabaseShared(); const label = isShared ? "Settings" : "Scale & Settings"; items.push({ iconSrc: ScaleAndSettingsIcon, title: label, description: undefined, onClick: () => { const selectedCollection: ViewModels.Collection = useSelectedNode.getState().findSelectedCollection(); selectedCollection && selectedCollection.onSettingsClick(); }, }); } else { items.push({ iconSrc: AddDatabaseIcon, title: "New " + getDatabaseName(), description: undefined, onClick: async () => { const throughputCap = userContext.databaseAccount?.properties.capacity?.totalThroughputLimit; if (throughputCap && throughputCap !== -1) { await useDatabases.getState().loadAllOffers(); } useSidePanel .getState() .openSidePanel( "New " + getDatabaseName(), ); }, }); } return items; } private decorateOpenCollectionActivity({ databaseId, collectionId }: MostRecentActivity.OpenCollectionItem) { return { iconSrc: NotebookIcon, title: collectionId, description: "Data", onClick: () => { const collection = useDatabases.getState().findCollection(databaseId, collectionId); collection?.openTab(); }, }; } private decorateOpenNotebookActivity({ name, path }: MostRecentActivity.OpenNotebookItem) { return { info: path, iconSrc: CollectionIcon, title: name, description: "Notebook", onClick: () => { const notebookItem = this.container.createNotebookContentItemFile(name, path); notebookItem && this.container.openNotebook(notebookItem); }, }; } private createRecentItems(): SplashScreenItem[] { return MostRecentActivity.mostRecentActivity.getItems(userContext.databaseAccount?.id).map((activity) => { switch (activity.type) { default: { const unknownActivity: never = activity; throw new Error(`Unknown activity: ${unknownActivity}`); } case MostRecentActivity.Type.OpenNotebook: return this.decorateOpenNotebookActivity(activity); case MostRecentActivity.Type.OpenCollection: return this.decorateOpenCollectionActivity(activity); } }); } private createTipsItems(): SplashScreenItem[] { return [ { iconSrc: undefined, title: "Data Modeling", description: "Learn more about modeling", onClick: () => window.open(SplashScreen.dataModelingUrl), }, { iconSrc: undefined, title: "Cost & Throughput Calculation", description: "Learn more about cost calculation", onClick: () => window.open(SplashScreen.throughputEstimatorUrl), }, { iconSrc: undefined, title: "Configure automatic failover", description: "Learn more about Cosmos DB high-availability", onClick: () => window.open(SplashScreen.failoverUrl), }, ]; } private onSplashScreenItemKeyPress(event: React.KeyboardEvent, callback: () => void) { if (event.charCode === Constants.KeyCodes.Space || event.charCode === Constants.KeyCodes.Enter) { callback(); event.stopPropagation(); } } private getNotebookItems(): JSX.Element { return ( Notebook - Easy to develop Notebook - Enterprise ready Notebook - Cost effective ); } private getCommonTasksItems(): JSX.Element { const commonTaskItems = this.createCommonTaskItems(); return (
    {commonTaskItems.map((item) => (
  • this.onSplashScreenItemKeyPress(event, item.onClick)} tabIndex={0} role="button" > {item.title}
  • ))}
); } private top3Items(): JSX.Element { return ( Advanced Modeling Patterns Learn advanced strategies for managing relationships between data entities to optimize your database. Partitioning Best Practices Learn to apply data model and partitioning strategies to support an efficient and scalable NoSQL database. Plan Your Resource Requirements Familiarize yourself with the various configuration options for a new Azure Cosmos DB SQL API account. ); } private getRecentItems(): JSX.Element { const recentItems = this.createRecentItems()?.filter((item) => item.description !== "Notebook"); return (
    {recentItems.map((item, index) => (
  • {item.title}
    {item.description}
  • ))}
{recentItems.length > 0 && this.clearMostRecent()}>Clear Recents}
); } private getLearningResourceItems(): JSX.Element { return ( Get Started using th SQL API with the SDK Learn about the Azure Cosmos DB SDK, then download and use in a .NET application. Master Complex Queries Learn how to author complex queries using cross-products and correlated subqueries. Migrate Your Data Migrate data into and out of Azure Cosmos DB SQL API using Azure services and open-source solutions. ); } private getTipItems(): JSX.Element { const tipsItems = this.createTipsItems(); return (
    {tipsItems.map((item) => (
  • this.onSplashScreenItemKeyPress(event, item.onClick)} tabIndex={0} role="link" >
    {item.title}
    {item.description}
  • ))}
  • {SplashScreen.seeMoreItemTitle}
); } }