Skip to content

Commit

Permalink
Add doNotAskAgain button for Sign In and Select Organization windows (#…
Browse files Browse the repository at this point in the history
…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]>
  • Loading branch information
ivanduplenskikh and winstliu authored Feb 12, 2024
1 parent 4651edc commit 956a7cb
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,11 @@
"command": "azure-pipelines.configure-pipeline",
"title": "Configure Pipeline",
"category": "Azure Pipelines"
},
{
"command": "azure-pipelines.reset-state",
"title": "Reset 'do not ask again' messages",
"category": "Azure Pipelines"
}
],
"menus": {
Expand Down
4 changes: 3 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import * as vscode from 'vscode';
import * as languageclient from 'vscode-languageclient/node';

import * as logger from './logger';
import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, SchemaAssociationNotification } from './schema-association-service';
import { getSchemaAssociation, locateSchemaFile, onDidSelectOrganization, resetDoNotAskState, SchemaAssociationNotification } from './schema-association-service';
import { schemaContributor, CUSTOM_SCHEMA_REQUEST, CUSTOM_CONTENT_REQUEST } from './schema-contributor';
import { telemetryHelper } from './helpers/telemetryHelper';
import { getAzureAccountExtensionApi } from './extensionApis';
Expand Down Expand Up @@ -115,6 +115,8 @@ async function activateYmlContributor(context: vscode.ExtensionContext) {
context.subscriptions.push(onDidSelectOrganization(async workspaceFolder => {
await loadSchema(context, client, workspaceFolder);
}));

context.subscriptions.push(vscode.commands.registerCommand("azure-pipelines.reset-state", async () => await resetDoNotAskState(context)));
}

// Find the schema and notify the server.
Expand Down
29 changes: 27 additions & 2 deletions src/schema-association-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,17 @@ export const onDidSelectOrganization = selectOrganizationEvent.event;
const seenOrganizations = new Set<string>();
const lastUpdated1ESPTSchema = new Map<string, Date>();

export const DO_NOT_ASK_SIGN_IN_KEY = "DO_NOT_ASK_SIGN_IN_KEY";
export const DO_NOT_ASK_SELECT_ORG_KEY = "DO_NOT_ASK_SELECT_ORG_KEY";

let repoId1espt: string | undefined = undefined;

export async function resetDoNotAskState(context: vscode.ExtensionContext) {
await context.globalState.update(DO_NOT_ASK_SIGN_IN_KEY, undefined);
await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, undefined);
logger.log("State is reset");
}

export async function locateSchemaFile(
context: vscode.ExtensionContext,
workspaceFolder: vscode.WorkspaceFolder | undefined): Promise<string> {
Expand Down Expand Up @@ -105,6 +114,12 @@ async function autoDetectSchema(
// can't return until the sessions are also available.
// This only returns false if there is no login.
if (!(await azureAccountApi.waitForSubscriptions())) {
const doNotAskAgainSignIn = context.globalState.get<boolean>(DO_NOT_ASK_SIGN_IN_KEY);
if (doNotAskAgainSignIn) {
logger.log(`Not prompting for login - do not ask again was set`, 'SchemaDetection');
return undefined;
}

logger.log(`Waiting for login`, 'SchemaDetection');

try {
Expand All @@ -117,7 +132,7 @@ async function autoDetectSchema(

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

Expand Down Expand Up @@ -190,6 +207,12 @@ async function autoDetectSchema(
`Using cached information for ${workspaceFolder.name}: ${organizationName}, ${session?.tenantId}`,
'SchemaDetection');
} else {
const doNotAskAgainSelectOrg = context.globalState.get<boolean>(DO_NOT_ASK_SELECT_ORG_KEY);
if (doNotAskAgainSelectOrg) {
logger.log(`Not prompting for organization - do not ask again was set`, 'SchemaDetection');
return;
}

logger.log(`Prompting for organization for ${workspaceFolder.name}`, 'SchemaDetection');

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

selectOrganizationEvent.fire(workspaceFolder);
} else if (action === Messages.doNotAskAgain) {
await context.globalState.update(DO_NOT_ASK_SELECT_ORG_KEY, true);
}
});
return undefined;
Expand Down

0 comments on commit 956a7cb

Please sign in to comment.