From 0ade4f8d63dca7620aa6e5c1cdd7aabf7b06fb1a Mon Sep 17 00:00:00 2001 From: Bowen Song Date: Mon, 20 Jan 2025 10:01:33 +0800 Subject: [PATCH] perf(auth): add nofitication for addAuthConfig command (#13064) * perf(auth): add nofitication for addAuthConfig command * fix: fix message and remove useless import * fix: add localization --- packages/cli/src/commands/models/addAuthConfig.ts | 4 +++- packages/cli/src/resource/strings.json | 5 +++++ packages/fx-core/resource/package.nls.json | 4 ++-- .../src/question/inputs/AddAuthActionInputs.ts | 2 +- packages/vscode-extension/package.nls.json | 4 +++- .../src/handlers/lifecycleHandlers.ts | 14 +++++++++++++- .../src/telemetry/extTelemetryEvents.ts | 1 + .../test/handlers/lifecycleHandlers.test.ts | 13 +++++++++---- 8 files changed, 37 insertions(+), 10 deletions(-) diff --git a/packages/cli/src/commands/models/addAuthConfig.ts b/packages/cli/src/commands/models/addAuthConfig.ts index 7c3bd429f3..acb0b21515 100644 --- a/packages/cli/src/commands/models/addAuthConfig.ts +++ b/packages/cli/src/commands/models/addAuthConfig.ts @@ -1,11 +1,12 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT license. import { CLICommand } from "@microsoft/teamsfx-api"; -import { commands } from "../../resource"; +import { commands, strings } from "../../resource"; import { TelemetryEvent } from "../../telemetry/cliTelemetryEvents"; import { ProjectFolderOption } from "../common"; import { getFxCore } from "../../activate"; import { AddAuthActionInputs, AddAuthActionOptions } from "@microsoft/teamsfx-core"; +import { logger } from "../../commonlib/logger"; export const addAuthConfigCommand: CLICommand = { name: "auth-config", @@ -18,6 +19,7 @@ export const addAuthConfigCommand: CLICommand = { const inputs = ctx.optionValues as AddAuthActionInputs; const core = getFxCore(); const res = await core.addAuthAction(inputs); + logger.info(strings.command.add["auth-config"].notification); return res; }, }; diff --git a/packages/cli/src/resource/strings.json b/packages/cli/src/resource/strings.json index 9397065879..23012882e1 100644 --- a/packages/cli/src/resource/strings.json +++ b/packages/cli/src/resource/strings.json @@ -39,6 +39,11 @@ "FoundNotTrust": "Local Certificate is found but not trusted.", "Success": "Local Certificate is found and is trusted." } + }, + "add":{ + "auth-config": { + "notification": "Teams Toolkit has successfully updated your project configuration (teamsapp.yaml) files with added action to support authentication flow. You can proceed to remote provision." + } } } } diff --git a/packages/fx-core/resource/package.nls.json b/packages/fx-core/resource/package.nls.json index 9bf71fec39..108d0a96a3 100644 --- a/packages/fx-core/resource/package.nls.json +++ b/packages/fx-core/resource/package.nls.json @@ -935,7 +935,7 @@ "error.kiota.FailedToGenerateAuthActions": "Unable to parse Open API spec and generate Auth actions in teamsapp.yml. Manually update the yml files, if required.", "core.addAuthActionQuestion.ApiSpecLocation.title": "Select an OpenAPI Description Document", "core.addAuthActionQuestion.ApiSpecLocation.placeholder": "Select an option", - "core.addAuthActionQuestion.ApiOperation.title": "Select an OpenAPI Description Document", - "core.addAuthActionQuestion.ApiOperation.placeholder": "Select an option", + "core.addAuthActionQuestion.ApiOperation.title": "Select an API to Add Auth Configuration", + "core.addAuthActionQuestion.ApiOperation.placeholder": "Select one or multiple options", "core.addAuthActionQuestion.authName.title": "Input the Name of Auth Configuration" } \ No newline at end of file diff --git a/packages/fx-core/src/question/inputs/AddAuthActionInputs.ts b/packages/fx-core/src/question/inputs/AddAuthActionInputs.ts index 5c3d63929b..06a3d82ed4 100644 --- a/packages/fx-core/src/question/inputs/AddAuthActionInputs.ts +++ b/packages/fx-core/src/question/inputs/AddAuthActionInputs.ts @@ -15,7 +15,7 @@ export interface AddAuthActionInputs extends Inputs { "plugin-manifest-path"?: string; /** @description Select an OpenAPI Description Document */ "openapi-spec-location"?: string; - /** @description Select an OpenAPI Description Document */ + /** @description Select an API to Add Auth Configuration */ "api-operation"?: string[]; /** @description Input the Name of Auth Configuration */ "auth-name"?: string; diff --git a/packages/vscode-extension/package.nls.json b/packages/vscode-extension/package.nls.json index 3c4924630d..071cc1011d 100644 --- a/packages/vscode-extension/package.nls.json +++ b/packages/vscode-extension/package.nls.json @@ -599,5 +599,7 @@ "teamstoolkit.walkthroughs.buildIntelligentApps.intelligentAppResources.description": "Explore these resources to build intelligent apps and enhance your development projects\n🗒️ [Generative AI for Beginners](https://github.com/microsoft/generative-ai-for-beginners/tree/main)\n✨ [Retrieval Augmented Generation (RAG)](https://learn.microsoft.com/en-us/azure/search/retrieval-augmented-generation-overview)\n📚 [AI Learning and Community Hub](https://learn.microsoft.com/en-us/ai/)", "teamstoolkit.m365.needSignIn.message": "You need to sign in your Microsoft 365 account.", "teamstoolkit.handler.createPluginWithManifest.error.missingParameter": "Invalid parameter in the createPluginWithManifest command. Usage: createPluginWithManifest(API_SPEC_PATH:string, PLUGIN_MANIFEST_PATH: string, { lastCommand: string }, OUTPUT_FOLDER?: string). Valid values for LAST_COMMAND: createPluginWithManifest, createDeclarativeCopilotWithManifest.", - "teamstoolkit.error.KiotaNotInstalled": "You need to install Microsoft Kiota extension with minimum version %s to use this feature." + "teamstoolkit.error.KiotaNotInstalled": "You need to install Microsoft Kiota extension with minimum version %s to use this feature.", + "teamstoolkit.handeler.addAuthConfig.notification": "Teams Toolkit has successfully updated your project configuration (teamsapp.yaml and teamsapp.local.yaml) files with added action to support authentication flow. You can proceed to remote provision.", + "teamstoolkit.handeler.addAuthConfig.notification.provision": "Provision" } diff --git a/packages/vscode-extension/src/handlers/lifecycleHandlers.ts b/packages/vscode-extension/src/handlers/lifecycleHandlers.ts index 06746cd169..a592f4a7c4 100644 --- a/packages/vscode-extension/src/handlers/lifecycleHandlers.ts +++ b/packages/vscode-extension/src/handlers/lifecycleHandlers.ts @@ -255,7 +255,19 @@ export async function copilotPluginAddAPIHandler(args: any[]) { export async function addAuthActionHandler(...args: unknown[]) { ExtTelemetry.sendTelemetryEvent(TelemetryEvent.AddAuthActionStart, getTriggerFromProperty(args)); const inputs = getSystemInputs(); - return await runCommand(Stage.addAuthAction, inputs); + const result = await runCommand(Stage.addAuthAction, inputs); + void vscode.window + .showInformationMessage( + localize("teamstoolkit.handeler.addAuthConfig.notification"), + localize("teamstoolkit.handeler.addAuthConfig.notification.provision") + ) + .then((selection) => { + if (selection === "Provision") { + ExtTelemetry.sendTelemetryEvent(TelemetryEvent.ProvisionFromAddAuthConfig); + void runCommand(Stage.provision); + } + }); + return result; } function handleTriggerKiotaCommand( diff --git a/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts b/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts index 225d94f80b..d5775ac3af 100644 --- a/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts +++ b/packages/vscode-extension/src/telemetry/extTelemetryEvents.ts @@ -320,6 +320,7 @@ export enum TelemetryEvent { AddAuthActionStart = "add-auth-action-start", AddAuthAction = "add-auth-action", + ProvisionFromAddAuthConfig = "provision-from-add-auth-config", } export enum TelemetryProperty { diff --git a/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts b/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts index fb3d397daa..4db9dd9dcc 100644 --- a/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts +++ b/packages/vscode-extension/test/handlers/lifecycleHandlers.test.ts @@ -599,11 +599,16 @@ describe("Lifecycle handlers", () => { it("happy path", async () => { sandbox.stub(globalVariables, "core").value(new MockCore()); - const addPluginHanlder = sandbox.spy(globalVariables.core, "addAuthAction"); - + const showMessageStub = sandbox + .stub(vscode.window, "showInformationMessage") + .callsFake((title: string, ...items: any[]) => { + return Promise.resolve(items[0]); + }); + const addAuthAction = sandbox.spy(globalVariables.core, "addAuthAction"); + const provisionction = sandbox.spy(globalVariables.core, "provisionResources"); await addAuthActionHandler(); - - sinon.assert.calledOnce(addPluginHanlder); + sandbox.assert.calledOnce(addAuthAction); + sandbox.assert.calledOnce(provisionction); }); }); });