Skip to content

Commit 956a7cb

Browse files
Add doNotAskAgain button for Sign In and Select Organization windows (#560)
* Add doNotAskAgain buttons for Sign In and Select Organization * Add reset state command, move check to separate line and change log messages * Update indent * Clarify what the setting does * Only check DNAA right before the prompts * Delete missed line * Clarify the method name --------- Co-authored-by: Winston Liu <[email protected]>
1 parent 4651edc commit 956a7cb

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@
119119
"command": "azure-pipelines.configure-pipeline",
120120
"title": "Configure Pipeline",
121121
"category": "Azure Pipelines"
122+
},
123+
{
124+
"command": "azure-pipelines.reset-state",
125+
"title": "Reset 'do not ask again' messages",
126+
"category": "Azure Pipelines"
122127
}
123128
],
124129
"menus": {

src/extension.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as vscode from 'vscode';
88
import * as languageclient from 'vscode-languageclient/node';
99

1010
import * as logger from './logger';
11-
import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, SchemaAssociationNotification } from './schema-association-service';
11+
import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, resetDoNotAskState, SchemaAssociationNotification } from './schema-association-service';
1212
import { schemaContributor, CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST } from './schema-contributor';
1313
import { telemetryHelper } from './helpers/telemetryHelper';
1414
import { getAzureAccountExtensionApi } from './extensionApis';
@@ -115,6 +115,8 @@ async function activateYmlContributor(context: vscode.ExtensionContext) {
115115
context.subscriptions.push(onDidSelectOrganization(async workspaceFolder => {
116116
await loadSchema(context, client, workspaceFolder);
117117
}));
118+
119+
context.subscriptions.push(vscode.commands.registerCommand("azure-pipelines.reset-state", async () => await resetDoNotAskState(context)));
118120
}
119121

120122
// Find the schema and notify the server.

src/schema-association-service.ts

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ export const onDidSelectOrganization = selectOrganizationEvent.event;
2828
const seenOrganizations = new Set<string>();
2929
const lastUpdated1ESPTSchema = new Map<string, Date>();
3030

31+
export const DO_NOT_ASK_SIGN_IN_KEY = "DO_NOT_ASK_SIGN_IN_KEY";
32+
export const DO_NOT_ASK_SELECT_ORG_KEY = "DO_NOT_ASK_SELECT_ORG_KEY";
33+
3134
let repoId1espt: string | undefined = undefined;
3235

36+
export async function resetDoNotAskState(context: vscode.ExtensionContext) {
37+
await context.globalState.update(DO_NOT_ASK_SIGN_IN_KEY, undefined);
38+
await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, undefined);
39+
logger.log("State is reset");
40+
}
41+
3342
export async function locateSchemaFile(
3443
context: vscode.ExtensionContext,
3544
workspaceFolder: vscode.WorkspaceFolder | undefined): Promise<string> {
@@ -105,6 +114,12 @@ async function autoDetectSchema(
105114
// can't return until the sessions are also available.
106115
// This only returns false if there is no login.
107116
if (!(await azureAccountApi.waitForSubscriptions())) {
117+
const doNotAskAgainSignIn = context.globalState.get<boolean>(DO_NOT_ASK_SIGN_IN_KEY);
118+
if (doNotAskAgainSignIn) {
119+
logger.log(`Not prompting for login - do not ask again was set`, 'SchemaDetection');
120+
return undefined;
121+
}
122+
108123
logger.log(`Waiting for login`, 'SchemaDetection');
109124

110125
try {
@@ -117,7 +132,7 @@ async function autoDetectSchema(
117132

118133
// Don't await this message so that we can return the fallback schema instead of blocking.
119134
// We'll detect the login in extension.ts and then re-request the schema.
120-
void vscode.window.showInformationMessage(Messages.signInForEnhancedIntelliSense, Messages.signInLabel)
135+
void vscode.window.showInformationMessage(Messages.signInForEnhancedIntelliSense, Messages.signInLabel, Messages.doNotAskAgain)
121136
.then(async action => {
122137
if (action === Messages.signInLabel) {
123138
await vscode.window.withProgress({
@@ -126,6 +141,8 @@ async function autoDetectSchema(
126141
}, async () => {
127142
await vscode.commands.executeCommand("azure-account.login");
128143
});
144+
} else if (action === Messages.doNotAskAgain) {
145+
await context.globalState.update(DO_NOT_ASK_SIGN_IN_KEY, true);
129146
}
130147
});
131148

@@ -190,6 +207,12 @@ async function autoDetectSchema(
190207
`Using cached information for ${workspaceFolder.name}: ${organizationName}, ${session?.tenantId}`,
191208
'SchemaDetection');
192209
} else {
210+
const doNotAskAgainSelectOrg = context.globalState.get<boolean>(DO_NOT_ASK_SELECT_ORG_KEY);
211+
if (doNotAskAgainSelectOrg) {
212+
logger.log(`Not prompting for organization - do not ask again was set`, 'SchemaDetection');
213+
return;
214+
}
215+
193216
logger.log(`Prompting for organization for ${workspaceFolder.name}`, 'SchemaDetection');
194217

195218
// Otherwise, we need to manually prompt.
@@ -199,7 +222,7 @@ async function autoDetectSchema(
199222
// We'll detect when they choose the organization in extension.ts and then re-request the schema.
200223
void vscode.window.showInformationMessage(
201224
format(Messages.selectOrganizationForEnhancedIntelliSense, workspaceFolder.name),
202-
Messages.selectOrganizationLabel)
225+
Messages.selectOrganizationLabel, Messages.doNotAskAgain)
203226
.then(async action => {
204227
if (action === Messages.selectOrganizationLabel) {
205228
// Lazily construct list of organizations so that we can immediately show the quick pick,
@@ -237,6 +260,8 @@ async function autoDetectSchema(
237260
});
238261

239262
selectOrganizationEvent.fire(workspaceFolder);
263+
} else if (action === Messages.doNotAskAgain) {
264+
await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, true);
240265
}
241266
});
242267
return undefined;

0 commit comments

Comments
 (0)