microsoft/vscode-react-native

Public

mirrored from https://github.com/microsoft/vscode-react-nativeAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
bumo-glob-cli-fix

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

src/extension/services/experimentService/experiments/RNTPreviewPrompt.ts

78lines · modeblame

88671796RedMickey5 years ago1// Copyright (c) Microsoft Corporation. All rights reserved.
2// Licensed under the MIT license. See LICENSE file in the project root for details.
3
4import * as vscode from "vscode";
5import { IExperiment } from "../IExperiment";
34472878RedMickey5 years ago6import {
7ExperimentConfig,
8ExperimentParameters,
9ExperimentResult,
10ExperimentStatuses,
11} from "../experimentService";
88671796RedMickey5 years ago12import { PROMPT_TITLES } from "../experimentsStrings";
13
14export default class RNTPreviewPrompt implements IExperiment {
34472878RedMickey5 years ago15public async run(
16newExpConfig: ExperimentConfig,
17curExpParameters?: ExperimentParameters,
18): Promise<ExperimentResult> {
88671796RedMickey5 years ago19if (
34472878RedMickey5 years ago20curExpParameters &&
21(curExpParameters.promptShown ||
22newExpConfig.popCoveragePercent === curExpParameters.popCoveragePercent)
88671796RedMickey5 years ago23) {
24return {
25resultStatus: ExperimentStatuses.DISABLED,
26updatedExperimentParameters: curExpParameters,
27};
28}
29
34472878RedMickey5 years ago30const updatedExperimentParameters = this.showPrompIfThresholdIsNotExceeded(
31newExpConfig,
32curExpParameters,
33);
88671796RedMickey5 years ago34
35return {
36resultStatus: ExperimentStatuses.ENABLED,
37updatedExperimentParameters,
38};
39}
40
34472878RedMickey5 years ago41private showPrompIfThresholdIsNotExceeded(
42newExpConfig: ExperimentConfig,
43promptParameters?: ExperimentParameters,
44) {
88671796RedMickey5 years ago45if (promptParameters) {
46promptParameters.popCoveragePercent = newExpConfig.popCoveragePercent;
47} else {
34472878RedMickey5 years ago48promptParameters = Object.assign({}, newExpConfig, {
49extensionId: "msjsdiag.vscode-react-native-preview",
50promptShown: false,
51});
88671796RedMickey5 years ago52}
53
54if (newExpConfig.popCoveragePercent > Math.random()) {
55const buttonText = "Open extension";
09f6024fHeniker4 years ago56void vscode.window
34472878RedMickey5 years ago57.showInformationMessage(PROMPT_TITLES.RNT_PREVIEW_PROMPT, buttonText)
88671796RedMickey5 years ago58.then(selection => {
59if (selection === buttonText && promptParameters) {
09f6024fHeniker4 years ago60void vscode.commands.executeCommand(
34472878RedMickey5 years ago61"workbench.extensions.search",
62promptParameters.extensionId,
63);
09f6024fHeniker4 years ago64void vscode.commands.executeCommand(
34472878RedMickey5 years ago65"extension.open",
66promptParameters.extensionId,
67);
88671796RedMickey5 years ago68}
69});
70
71promptParameters.promptShown = true;
72} else {
73promptParameters.promptShown = false;
74}
75
76return promptParameters;
77}
78}