import { Label, MessageBar, MessageBarType, Stack, Text, TextField } from "office-ui-fabric-react"; import * as React from "react"; import * as Constants from "../../../../Common/Constants"; import { configContext, Platform } from "../../../../ConfigContext"; import * as DataModels from "../../../../Contracts/DataModels"; import * as ViewModels from "../../../../Contracts/ViewModels"; import * as AutoPilotUtils from "../../../../Utils/AutoPilotUtils"; import Explorer from "../../../Explorer"; import { getTextFieldStyles, getThroughputApplyShortDelayMessage, subComponentStackProps, throughputUnit, titleAndInputStackProps } from "../SettingsRenderUtils"; import { getMinRUs, hasDatabaseSharedThroughput } from "../SettingsUtils"; import { ThroughputInputAutoPilotV3Component } from "./ThroughputInputComponents/ThroughputInputAutoPilotV3Component"; export interface ScaleComponentProps { collection: ViewModels.Collection; container: Explorer; isFixedContainer: boolean; onThroughputChange: (newThroughput: number) => void; throughput: number; throughputBaseline: number; autoPilotThroughput: number; autoPilotThroughputBaseline: number; isAutoPilotSelected: boolean; wasAutopilotOriginallySet: boolean; onAutoPilotSelected: (isAutoPilotSelected: boolean) => void; onMaxAutoPilotThroughputChange: (newThroughput: number) => void; onScaleSaveableChange: (isScaleSaveable: boolean) => void; onScaleDiscardableChange: (isScaleDiscardable: boolean) => void; initialNotification: DataModels.Notification; } export class ScaleComponent extends React.Component { private isEmulator: boolean; constructor(props: ScaleComponentProps) { super(props); this.isEmulator = configContext.platform === Platform.Emulator; } public isAutoScaleEnabled = (): boolean => { const accountCapabilities: DataModels.Capability[] = this.props.container?.databaseAccount()?.properties ?.capabilities; const enableAutoScaleCapability = accountCapabilities && accountCapabilities.find((capability: DataModels.Capability) => { return ( capability && capability.name && capability.name.toLowerCase() === Constants.CapabilityNames.EnableAutoScale.toLowerCase() ); }); return !!enableAutoScaleCapability; }; private getStorageCapacityTitle = (): JSX.Element => { // Mongo container with system partition key still treat as "Fixed" const isFixed = !this.props.collection.partitionKey || (this.props.container.isPreferredApiMongoDB() && this.props.collection.partitionKey.systemKey); const capacity: string = isFixed ? "Fixed" : "Unlimited"; return ( {capacity} ); }; public getThroughputTitle = (): string => { if (this.props.isAutoPilotSelected) { return AutoPilotUtils.getAutoPilotHeaderText(); } const minThroughput: string = getMinRUs(this.props.collection, this.props.container).toLocaleString(); const maxThroughput: string = !this.props.isFixedContainer ? "unlimited" : "10000"; return `Throughput (${minThroughput} - ${maxThroughput} RU/s)`; }; public getInitialNotificationElement = (): JSX.Element => { const offer = this.props.collection?.offer && this.props.collection.offer(); if ( offer && Object.keys(offer).find(value => { return value === "headers"; }) && !!(offer as DataModels.OfferWithHeaders).headers[Constants.HttpHeaders.offerReplacePending] ) { const throughput = offer?.content?.offerAutopilotSettings?.maxThroughput; const targetThroughput = offer.content?.offerAutopilotSettings?.targetMaxThroughput || offer?.content?.offerThroughput; return getThroughputApplyShortDelayMessage( this.props.isAutoPilotSelected, throughput, throughputUnit, this.props.collection.databaseId, this.props.collection.id(), targetThroughput ); } return undefined; }; private getThroughputInputComponent = (): JSX.Element => ( ); public render(): JSX.Element { return ( {this.getInitialNotificationElement() && ( {this.getInitialNotificationElement()} )} {!this.isAutoScaleEnabled() && ( {this.getThroughputInputComponent()} {this.getStorageCapacityTitle()} )} {/* TODO: Replace link with call to the Azure Support blade */} {this.isAutoScaleEnabled() && ( Throughput (RU/s) Your account has custom settings that prevents setting throughput at the container level. Please work with your Cosmos DB engineering team point of contact to make changes. )} ); } }