diff --git a/src/Explorer/Explorer.tsx b/src/Explorer/Explorer.tsx index ad0816a6a..e1835da4d 100644 --- a/src/Explorer/Explorer.tsx +++ b/src/Explorer/Explorer.tsx @@ -1,5 +1,8 @@ import { Link } from "@fluentui/react/lib/Link"; import { isPublicInternetAccessAllowed } from "Common/DatabaseAccountUtility"; +import { sendMessage } from "Common/MessageHandler"; +import { Platform } from "ConfigContext"; +import { MessageTypes } from "Contracts/ExplorerContracts"; import { IGalleryItem } from "Juno/JunoClient"; import { allowedNotebookServerUrls, validateEndpoint } from "Utils/EndpointValidation"; import * as ko from "knockout"; @@ -23,7 +26,7 @@ import { PhoenixClient } from "../Phoenix/PhoenixClient"; import * as ExplorerSettings from "../Shared/ExplorerSettings"; import { Action, ActionModifiers } from "../Shared/Telemetry/TelemetryConstants"; import * as TelemetryProcessor from "../Shared/Telemetry/TelemetryProcessor"; -import { userContext } from "../UserContext"; +import { isAccountNewerThanThresholdInMs, userContext } from "../UserContext"; import { getCollectionName, getUploadName } from "../Utils/APITypeUtils"; import { stringToBlob } from "../Utils/BlobUtils"; import { isCapabilityEnabled } from "../Utils/CapabilityUtils"; @@ -258,6 +261,45 @@ export default class Explorer { // TODO: return result } + private getRandomInt(max: number) { + return Math.floor(Math.random() * max); + } + + public openNPSSurveyDialog(): void { + if (!Platform.Portal) { + return; + } + + const NINETY_DAYS_IN_MS = 7776000000; + const ONE_DAY_IN_MS = 86400000; + const isAccountNewerThanNinetyDays = isAccountNewerThanThresholdInMs( + userContext.databaseAccount?.systemData?.createdAt || "", + NINETY_DAYS_IN_MS + ); + + // Try Cosmos DB subscription - survey shown to random 25% of users at day 1 in Data Explorer. + if (userContext.isTryCosmosDBSubscription) { + if ( + isAccountNewerThanThresholdInMs(userContext.databaseAccount?.systemData?.createdAt || "", ONE_DAY_IN_MS) && + this.getRandomInt(100) < 25 + ) { + sendMessage(MessageTypes.DisplayNPSSurvey); + } + } else { + // An existing account is lesser than 90 days old. For existing account show to random 10 % of users in Data Explorer. + if (isAccountNewerThanNinetyDays) { + if (this.getRandomInt(100) < 10) { + sendMessage(MessageTypes.DisplayNPSSurvey); + } + } else { + // An existing account is greater than 90 days. For existing account show to random 25 % of users in Data Explorer. + if (this.getRandomInt(100) < 25) { + sendMessage(MessageTypes.DisplayNPSSurvey); + } + } + } + } + public async refreshDatabaseForResourceToken(): Promise { const databaseId = userContext.parsedResourceToken?.databaseId; const collectionId = userContext.parsedResourceToken?.collectionId; diff --git a/src/Explorer/Panes/AddCollectionPanel.tsx b/src/Explorer/Panes/AddCollectionPanel.tsx index 6882bda00..f3c834145 100644 --- a/src/Explorer/Panes/AddCollectionPanel.tsx +++ b/src/Explorer/Panes/AddCollectionPanel.tsx @@ -1425,6 +1425,10 @@ export class AddCollectionPanel extends React.Component