-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathOpenConfirmationViewStep.ts
More file actions
140 lines (127 loc) · 6.81 KB
/
OpenConfirmationViewStep.ts
File metadata and controls
140 lines (127 loc) · 6.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.md in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { AzExtUserInput, AzureWizardPromptStep, CopilotUserInput, GoBackError, openUrl, UserCancelledError, type ConfirmationViewProperty, type IActionContext } from "@microsoft/vscode-azext-utils";
import * as vscode from 'vscode';
import { type WebviewPanel } from 'vscode';
import { localize } from "../utils/localize";
import { ConfirmationViewController } from "./ConfirmationViewController";
export const SharedState = {
itemsToClear: 0,
cancelled: true,
copilotClicked: false,
editingPicks: false,
currentPanel: undefined as WebviewPanel | undefined,
};
export class OpenConfirmationViewStep<T extends IActionContext> extends AzureWizardPromptStep<T> {
private readonly viewConfig: () => ConfirmationViewProperty[];
private readonly title: string;
private readonly tabTitle: string;
private readonly description: string;
private readonly commandName: string;
public constructor(title: string, tabTitle: string, description: string, commandName: string, viewConfig: () => ConfirmationViewProperty[]) {
super();
this.title = title;
this.tabTitle = tabTitle
this.description = description;
this.viewConfig = viewConfig;
this.commandName = commandName;
}
public async prompt(context: T): Promise<void> {
if (SharedState.currentPanel) {
SharedState.currentPanel.dispose();
SharedState.currentPanel = undefined;
}
const confirmationView = new ConfirmationViewController({
title: this.title,
tabTitle: this.tabTitle,
description: this.description,
commandName: this.commandName,
items: this.viewConfig()
});
confirmationView.revealToForeground(vscode.ViewColumn.Active);
await new Promise<void>((resolve, reject) => {
confirmationView.onDisposed(async () => {
try {
if (SharedState.itemsToClear > 0) {
context.telemetry.properties.editingPicks = 'true';
SharedState.editingPicks = true;
if (context.ui instanceof CopilotUserInput) {
context.ui = new AzExtUserInput(context);
}
throw new GoBackError(SharedState.itemsToClear);
}
if (SharedState.cancelled) {
context.telemetry.properties.cancelClicked = 'true';
throw new UserCancelledError('openConfirmationViewStep');
}
} catch (error) {
reject(error);
} finally {
const greatButton: vscode.MessageItem = {
title: 'Great',
}
const notHelpfulButton: vscode.MessageItem = {
title: 'Unhelpful'
}
const surveyButton: vscode.MessageItem = {
title: localize('provideFeedback', 'Provide Feedback'),
}
const buttons = [greatButton, notHelpfulButton, surveyButton];
if (SharedState.editingPicks && SharedState.itemsToClear === 0 && SharedState.copilotClicked) {
resolve();
const message = localize('editingPicksandCopilotMessage', 'How was your experience using Copilot and revising your selections?');
const result = await vscode.window.showInformationMessage(message, ...buttons);
await confirmationViewButtonActions(context, result);
} else if (!SharedState.cancelled && !SharedState.copilotClicked && !SharedState.editingPicks) {
resolve();
const message = localize('confirmMessage', 'How was your experience using the summary view?');
const result = await vscode.window.showInformationMessage(message, ...buttons);
await confirmationViewButtonActions(context, result);
} else if (SharedState.editingPicks && SharedState.itemsToClear === 0) {
resolve();
const message = localize('editingPicksMessage', 'How was your experience revising your selections?');
const result = await vscode.window.showInformationMessage(message, ...buttons);
await confirmationViewButtonActions(context, result);
} else if (SharedState.copilotClicked && !SharedState.cancelled) {
resolve();
context.telemetry.properties.isCopilotEvent = 'true';
context.telemetry.properties.copilotClicked = 'true';
const message = localize('copilotMessage', 'How was your experience using Copilot and the summary view?');
const result = await vscode.window.showInformationMessage(message, ...buttons);
if (result === surveyButton) {
await confirmationViewButtonActions(context, result);
} else if (result === greatButton) {
context.telemetry.properties.copilotButtonHelpful = 'true';
} else if (result === notHelpfulButton) {
context.telemetry.properties.copilotButtonNotHelpful = 'true';
}
} else {
resolve();
}
}
});
// reset the shared state
SharedState.itemsToClear = 0;
SharedState.cancelled = true;
SharedState.copilotClicked = false;
SharedState.editingPicks = false;
});
}
public shouldPrompt(): boolean {
return this.viewConfig().length > 0;
}
}
export async function confirmationViewButtonActions(context: IActionContext, result: vscode.MessageItem | undefined): Promise<void> {
if (result) {
if (result.title === 'Great') {
context.telemetry.properties.confirmationViewHelpful = 'true';
} else if (result.title === 'Unhelpful') {
context.telemetry.properties.confirmationViewNotHelpful = 'true';
} else if (result.title === 'Provide Feedback') {
const confirmationViewSurveyLink = 'https://aka.ms/AAx0tw1'
await openUrl(confirmationViewSurveyLink);
}
}
}