Skip to content

Commit 2e2ff7d

Browse files
sevokutnaum-ms
andauthored
Add HaTS Survey prompt (#2590)
--------- Co-authored-by: Tomasz Naumowicz <tnaumowicz@microsoft.com>
1 parent 67a6dbe commit 2e2ff7d

17 files changed

+347
-7
lines changed

package-lock.json

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
"@types/pg": "^8.11.11",
8484
"@types/react": "^18.3.18",
8585
"@types/react-dom": "^18.3.5",
86+
"@types/semver": "^7.3.12",
8687
"@types/uuid": "^10.0.0",
8788
"@types/vscode": "1.90.0",
8889
"@types/vscode-webview": "^1.57.5",

src/commands/openDocument/openDocument.ts

+8
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
import { type IActionContext } from '@microsoft/vscode-azext-utils';
77
import { AzExtResourceType } from '@microsoft/vscode-azureresources-api';
88
import { ViewColumn } from 'vscode';
9+
import { API } from '../../AzureDBExperiences';
910
import { DocumentFileDescriptor } from '../../docdb/fs/DocumentFileDescriptor';
1011
import { ext } from '../../extensionVariables';
1112
import { type DocumentDBItemResourceItem } from '../../tree/docdb/DocumentDBItemResourceItem';
1213
import { pickAppResource } from '../../utils/pickItem/pickAppResource';
14+
import { countExperienceUsageForSurvey } from '../../utils/survey';
15+
import { ExperienceKind, UsageImpact } from '../../utils/surveyTypes';
1316
import { DocumentsViewController } from '../../webviews/mongoClusters/documentView/documentsViewController';
1417

1518
export async function openDocumentDBItem(context: IActionContext, node?: DocumentDBItemResourceItem): Promise<void> {
@@ -30,6 +33,11 @@ export async function openDocumentDBItem(context: IActionContext, node?: Documen
3033
// Clear un-uploaded local changes to the document before opening https://github.com/microsoft/vscode-cosmosdb/issues/1619
3134
ext.fileSystem.fireChangedEvent(fsNode);
3235
await ext.fileSystem.showTextDocument(fsNode);
36+
37+
const experienceKind = [API.MongoDB, API.MongoClusters].includes(node.experience.api)
38+
? ExperienceKind.Mongo
39+
: ExperienceKind.NoSQL;
40+
countExperienceUsageForSurvey(experienceKind, UsageImpact.Low);
3341
}
3442

3543
export function openMongoDocumentView(

src/docdb/fs/DocumentFileDescriptor.ts

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { DocumentDBHiddenFields } from '../../constants';
1010
import { type EditableFileSystemItem } from '../../DatabasesFileSystem';
1111
import { type DocumentDBItemModel } from '../../tree/docdb/models/DocumentDBItemModel';
1212
import { extractPartitionKey } from '../../utils/document';
13+
import { promptAfterActionEventually } from '../../utils/survey';
14+
import { ExperienceKind, UsageImpact } from '../../utils/surveyTypes';
1315
import { getDocumentTreeItemLabel } from '../../utils/vscodeUtils';
1416
import { getCosmosClient } from '../getCosmosClient';
1517

@@ -74,6 +76,7 @@ export class DocumentFileDescriptor implements EditableFileSystemItem {
7476

7577
if (response.resource) {
7678
this.model.item = response.resource;
79+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, 'writeFile');
7780
} else {
7881
throw new Error('Failed to update the document');
7982
}

src/panels/DocumentTab.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import vscode from 'vscode';
99
import { type NoSqlQueryConnection } from '../docdb/NoSqlCodeLensProvider';
1010
import { DocumentSession } from '../docdb/session/DocumentSession';
1111
import { type CosmosDbRecordIdentifier } from '../docdb/types/queryResult';
12+
import { promptAfterActionEventually } from '../utils/survey';
13+
import { ExperienceKind, UsageImpact } from '../utils/surveyTypes';
1214
import { BaseTab, type CommandPayload } from './BaseTab';
1315

1416
type DocumentTabMode = 'add' | 'edit' | 'view';
@@ -169,7 +171,8 @@ export class DocumentTab extends BaseTab {
169171
}
170172

171173
private async saveDocument(documentText: string): Promise<void> {
172-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.document.saveDocument', async (context) => {
174+
const callbackId = 'cosmosDB.nosql.document.saveDocument';
175+
await callWithTelemetryAndErrorHandling(callbackId, async (context) => {
173176
const documentContent: JSONValue = JSON.parse(documentText) as JSONValue;
174177

175178
if (!this.isCosmosDbItemDefinition(documentContent)) {
@@ -190,6 +193,7 @@ export class DocumentTab extends BaseTab {
190193

191194
this.panel.title = `${this.documentId.id}.json`;
192195
});
196+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.High, callbackId);
193197
}
194198

195199
private isCosmosDbItemDefinition(documentContent: unknown): documentContent is ItemDefinition {

src/panels/QueryEditorTab.ts

+20-6
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { DocumentSession } from '../docdb/session/DocumentSession';
1414
import { QuerySession } from '../docdb/session/QuerySession';
1515
import { type CosmosDbRecordIdentifier, type ResultViewMetadata } from '../docdb/types/queryResult';
1616
import { getNoSqlQueryConnection } from '../docdb/utils/NoSqlQueryConnection';
17+
import { promptAfterActionEventually } from '../utils/survey';
18+
import { ExperienceKind, UsageImpact } from '../utils/surveyTypes';
1719
import * as vscodeUtil from '../utils/vscodeUtils';
1820
import { BaseTab, type CommandPayload } from './BaseTab';
1921
import { DocumentTab } from './DocumentTab';
@@ -258,7 +260,8 @@ export class QueryEditorTab extends BaseTab {
258260
}
259261

260262
private async runQuery(query: string, options: ResultViewMetadata): Promise<void> {
261-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.runQuery', async (context) => {
263+
const callbackId = 'cosmosDB.nosql.queryEditor.runQuery';
264+
await callWithTelemetryAndErrorHandling(callbackId, async (context) => {
262265
if (!this.connection) {
263266
throw new Error('No connection');
264267
}
@@ -271,6 +274,7 @@ export class QueryEditorTab extends BaseTab {
271274

272275
await session.run();
273276
});
277+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.High, callbackId);
274278
}
275279

276280
private async stopQuery(executionId: string): Promise<void> {
@@ -288,7 +292,8 @@ export class QueryEditorTab extends BaseTab {
288292
}
289293

290294
private async nextPage(executionId: string): Promise<void> {
291-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.nextPage', async (context) => {
295+
const callbackId = 'cosmosDB.nosql.queryEditor.nextPage';
296+
await callWithTelemetryAndErrorHandling(callbackId, async (context) => {
292297
context.telemetry.properties.executionId = executionId;
293298

294299
if (!this.connection) {
@@ -302,10 +307,12 @@ export class QueryEditorTab extends BaseTab {
302307

303308
await session.nextPage();
304309
});
310+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, callbackId);
305311
}
306312

307313
private async prevPage(executionId: string): Promise<void> {
308-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.prevPage', async (context) => {
314+
const callbackId = 'cosmosDB.nosql.queryEditor.prevPage';
315+
await callWithTelemetryAndErrorHandling(callbackId, async (context) => {
309316
context.telemetry.properties.executionId = executionId;
310317

311318
if (!this.connection) {
@@ -319,10 +326,12 @@ export class QueryEditorTab extends BaseTab {
319326

320327
await session.prevPage();
321328
});
329+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, callbackId);
322330
}
323331

324332
private async firstPage(executionId: string): Promise<void> {
325-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.firstPage', async (context) => {
333+
const callbackId = 'cosmosDB.nosql.queryEditor.firstPage';
334+
await callWithTelemetryAndErrorHandling(callbackId, async (context) => {
326335
context.telemetry.properties.executionId = executionId;
327336

328337
if (!this.connection) {
@@ -336,10 +345,12 @@ export class QueryEditorTab extends BaseTab {
336345

337346
await session.firstPage();
338347
});
348+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, callbackId);
339349
}
340350

341351
private async openDocument(mode: string, documentId?: CosmosDbRecordIdentifier): Promise<void> {
342-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.openDocument', () => {
352+
const callbackId = 'cosmosDB.nosql.queryEditor.openDocument';
353+
await callWithTelemetryAndErrorHandling(callbackId, () => {
343354
if (!this.connection) {
344355
throw new Error('No connection');
345356
}
@@ -354,10 +365,12 @@ export class QueryEditorTab extends BaseTab {
354365

355366
DocumentTab.render(this.connection, mode, documentId, this.getNextViewColumn());
356367
});
368+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, callbackId);
357369
}
358370

359371
private async deleteDocument(documentId: CosmosDbRecordIdentifier): Promise<void> {
360-
await callWithTelemetryAndErrorHandling('cosmosDB.nosql.queryEditor.deleteDocument', async () => {
372+
const callbackId = 'cosmosDB.nosql.queryEditor.deleteDocument';
373+
await callWithTelemetryAndErrorHandling(callbackId, async () => {
361374
if (!this.connection) {
362375
throw new Error('No connection');
363376
}
@@ -369,6 +382,7 @@ export class QueryEditorTab extends BaseTab {
369382
const session = new DocumentSession(this.connection, this.channel);
370383
await session.delete(documentId);
371384
});
385+
void promptAfterActionEventually(ExperienceKind.NoSQL, UsageImpact.Medium, callbackId);
372386
}
373387

374388
private getNextViewColumn(): vscode.ViewColumn {

src/tree/docdb/DocumentDBDatabaseResourceItem.ts

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { createContextValue } from '@microsoft/vscode-azext-utils';
88
import vscode, { type TreeItem } from 'vscode';
99
import { type Experience } from '../../AzureDBExperiences';
1010
import { getCosmosClient } from '../../docdb/getCosmosClient';
11+
import { countExperienceUsageForSurvey } from '../../utils/survey';
12+
import { ExperienceKind, UsageImpact } from '../../utils/surveyTypes';
1113
import { type CosmosDBTreeElement } from '../CosmosDBTreeElement';
1214
import { type TreeElementWithContextValue } from '../TreeElementWithContextValue';
1315
import { type TreeElementWithExperience } from '../TreeElementWithExperience';
@@ -32,6 +34,7 @@ export abstract class DocumentDBDatabaseResourceItem
3234
const cosmosClient = getCosmosClient(endpoint, credentials, isEmulator);
3335
const containers = await this.getContainers(cosmosClient);
3436

37+
countExperienceUsageForSurvey(ExperienceKind.NoSQL, UsageImpact.Low);
3538
return this.getChildrenImpl(containers);
3639
}
3740

src/tree/docdb/DocumentDBItemsResourceItem.ts

+4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import { createContextValue, createGenericElement, type IActionContext } from '@
88
import vscode, { type TreeItem } from 'vscode';
99
import { type Experience } from '../../AzureDBExperiences';
1010
import { getCosmosClient } from '../../docdb/getCosmosClient';
11+
import { countExperienceUsageForSurvey } from '../../utils/survey';
12+
import { ExperienceKind, UsageImpact } from '../../utils/surveyTypes';
1113
import { getBatchSizeSetting } from '../../utils/workspacUtils';
1214
import { type CosmosDBTreeElement } from '../CosmosDBTreeElement';
1315
import { type TreeElementWithContextValue } from '../TreeElementWithContextValue';
@@ -55,12 +57,14 @@ export abstract class DocumentDBItemsResourceItem
5557
context.telemetry.properties.parentContext = this.contextValue;
5658

5759
this.batchSize *= 2;
60+
countExperienceUsageForSurvey(ExperienceKind.NoSQL, UsageImpact.Medium);
5861
},
5962
],
6063
}) as CosmosDBTreeElement,
6164
);
6265
}
6366

67+
countExperienceUsageForSurvey(ExperienceKind.NoSQL, UsageImpact.Low);
6468
return result;
6569
}
6670

0 commit comments

Comments
 (0)