Skip to content

Commit

Permalink
refactor: show three buttons at most
Browse files Browse the repository at this point in the history
  • Loading branch information
yuqizhou77 committed Dec 11, 2024
1 parent 9b785f1 commit a88b6d5
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 14 deletions.
9 changes: 9 additions & 0 deletions packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,10 @@
{
"command": "fx-extension.teamsAgentTroubleshootError",
"when": "false"
},
{
"command": "fx-extension.findSimilarIssue",
"when": "false"
}
]
},
Expand Down Expand Up @@ -934,6 +938,11 @@
"title": "%teamstoolkit.commmands.teamsAgentResolve.title%",
"enablement": "fx-extension.isChatParticipantUIEntriesEnabled",
"category": "Teams"
},
{
"command": "fx-extension.findSimilarIssue",
"title": "%teamstoolkit.handlers.similarIssues%",
"category": "Teams"
}
],
"taskDefinitions": [
Expand Down
2 changes: 2 additions & 0 deletions packages/vscode-extension/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
"teamstoolkit.handlers.referLinkForMoreDetails": "Please refer to this link for more details: ",
"teamstoolkit.handlers.reportIssue": "Report Issue",
"teamstoolkit.handlers.similarIssues": "Similar Issues",
"teamstoolkit.handlers.similarIssues.message": " Or you could search for [similar issues](command:fx-extension.findSimilarIssue?%5B%22%s%22%5D) in GitHub.",
"_teamstoolkit.handlers.similarIssues.message.comment": "For command like [similar issues](command:xxx), please translate 'similar issues' and keep the string 'command:xxx'",
"teamstoolkit.handlers.resourceInfoNotFound": "Unable to load %s info for environment %s.",
"teamstoolkit.handlers.signIn365": "Sign in to Microsoft 365",
"teamstoolkit.handlers.signInAzure": "Sign in to Azure",
Expand Down
34 changes: 23 additions & 11 deletions packages/vscode-extension/src/error/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import VsCodeLogInstance from "../commonlib/log";
import { ExtensionSource, ExtensionErrors } from "./error";
import { MaximumNotificationOutputTroubleshootCount } from "../constants";
import { sleep } from "@microsoft/vscode-ui";
import * as util from "util";

export async function showError(e: UserError | SystemError) {
let notificationMessage = e.displayMessage ?? e.message;
Expand Down Expand Up @@ -111,25 +112,36 @@ export async function showError(e: UserError | SystemError) {
void commands.executeCommand("vscode.open", issueLink);
},
};
const similarIssueLink = Uri.parse(
`https://github.com/OfficeDev/TeamsFx/issues?q=is:issue+in:title+${errorCode}`
);

const similarIssues = {
title: localize("teamstoolkit.handlers.similarIssues"),
run: async (): Promise<void> => {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.FindSimilarIssues);
await commands.executeCommand("vscode.open", similarIssueLink);
await commands.executeCommand("fx-extension.findSimilarIssue", errorCode);
},
};
const buttons = recommendTestTool ? [runTestTool, issue] : [issue];
if (shouldRecommendTeamsAgent) {
if (buttons.length >= 2) {
buttons.push(troubleshootErrorWithTeamsAgentButton);
notificationMessage += util.format(
localize("teamstoolkit.handlers.similarIssues.message"),
errorCode
);
e.message += util.format(
localize("teamstoolkit.handlers.similarIssues.message"),
errorCode
);
} else {
buttons.push(similarIssues);
buttons.push(troubleshootErrorWithTeamsAgentButton);
}
} else {
buttons.push(similarIssues);
}
VsCodeLogInstance.error(`code:${errorCode}, message: ${e.message}`);
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
VsCodeLogInstance.debug(`Call stack: ${e.stack || e.innerError?.stack || ""}`);
const buttons = recommendTestTool
? [runTestTool, issue, similarIssues]
: [issue, similarIssues];
if (shouldRecommendTeamsAgent) {
buttons.push(troubleshootErrorWithTeamsAgentButton);
}

void window
.showErrorMessage(`[${errorCode}]: ${notificationMessage}`, ...buttons)
.then((button) => {
Expand Down
8 changes: 8 additions & 0 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ import {
} from "./handlers/migrationHandler";
import * as officeDevHandlers from "./handlers/officeDevHandlers";
import {
findGitHubSimilarIssue,
openAccountLinkHandler,
openAppManagement,
openAzureAccountHandler,
Expand Down Expand Up @@ -447,6 +448,13 @@ function registerActivateCommands(context: vscode.ExtensionContext) {
);
context.subscriptions.push(migrateTeamsTabAppCmd);

// Similar issue
const findSimilarIssue = vscode.commands.registerCommand(
"fx-extension.findSimilarIssue",
(...args) => Correlator.run(findGitHubSimilarIssue, args)
);
context.subscriptions.push(findSimilarIssue);

// Register local debug run icon
const runIconCmd = vscode.commands.registerCommand("fx-extension.selectAndDebug", (...args) =>
Correlator.run(selectAndDebugHandler, args)
Expand Down
15 changes: 15 additions & 0 deletions packages/vscode-extension/src/handlers/openLinkHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import { ExtensionSource, ExtensionErrors } from "../error/error";
import { getSubscriptionInfoFromEnv, getResourceGroupNameFromEnv } from "../utils/envTreeUtils";
import { localize } from "../utils/localizeUtils";
import { getWalkThroughId } from "../utils/projectStatusUtils";
import { commands, Uri } from "vscode";

export async function openEnvLinkHandler(args: any[]): Promise<Result<unknown, FxError>> {
ExtTelemetry.sendTelemetryEvent(TelemetryEvent.Documentation, {
Expand Down Expand Up @@ -268,3 +269,17 @@ export async function openResourceGroupInPortal(env: string): Promise<Result<Voi
return err(resourceInfoNotFoundError);
}
}

export async function findGitHubSimilarIssue(args?: any[]): Promise<Result<Void, FxError>> {
if (args && args.length > 0) {
const errorCode = args[0] as string;
const similarIssueLink = Uri.parse(

Check warning on line 276 in packages/vscode-extension/src/handlers/openLinkHandlers.ts

View check run for this annotation

Codecov / codecov/patch

packages/vscode-extension/src/handlers/openLinkHandlers.ts#L275-L276

Added lines #L275 - L276 were not covered by tests
`https://github.com/OfficeDev/TeamsFx/issues?q=is:issue+in:title+${errorCode}`
);

ExtTelemetry.sendTelemetryEvent(TelemetryEvent.FindSimilarIssues);
await commands.executeCommand("vscode.open", similarIssueLink);
return ok(Void);

Check warning on line 282 in packages/vscode-extension/src/handlers/openLinkHandlers.ts

View check run for this annotation

Codecov / codecov/patch

packages/vscode-extension/src/handlers/openLinkHandlers.ts#L280-L282

Added lines #L280 - L282 were not covered by tests
}
return ok(Void);

Check warning on line 284 in packages/vscode-extension/src/handlers/openLinkHandlers.ts

View check run for this annotation

Codecov / codecov/patch

packages/vscode-extension/src/handlers/openLinkHandlers.ts#L284

Added line #L284 was not covered by tests
}
9 changes: 6 additions & 3 deletions packages/vscode-extension/test/error/common.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,14 +108,13 @@ describe("common", async () => {
.callsFake((title: string, button: unknown, ...items: vscode.MessageItem[]) => {
return Promise.resolve(items[0]);
});
const sendTelemetryEventStub = sandbox.stub(ExtTelemetry, "sendTelemetryEvent");

const executeCommandStub = sandbox.stub(vscode.commands, "executeCommand");
const error = new SystemError("Core", "DecryptionError", "test");

await showError(error);
await showErrorMessageStub.firstCall.returnValue;

chai.assert.isTrue(sendTelemetryEventStub.called);
chai.assert.isTrue(executeCommandStub.called);
});

Expand Down Expand Up @@ -308,7 +307,11 @@ describe("common", async () => {
await job;
await showErrorMessageStub.firstCall.returnValue;

chai.assert.equal(showErrorMessageStub.firstCall.args.length, buttonNum + 2);
if (type == "system error") {
chai.assert.equal(showErrorMessageStub.firstCall.args.length, buttonNum + 1);
} else {
chai.assert.equal(showErrorMessageStub.firstCall.args.length, buttonNum + 2);
}
});

it(`showError - ${type} - recommend troubleshoot only`, async () => {
Expand Down

0 comments on commit a88b6d5

Please sign in to comment.