Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(vsc): not showing treeview when upgrade detects error #8538

Merged
merged 4 commits into from
Apr 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import {
isSPFxProject,
isTeamsFxProject,
setUriEventHandler,
unsetIsTeamsFxProject,
workspaceUri,
} from "./globalVariables";
import * as handlers from "./handlers";
Expand Down Expand Up @@ -1028,10 +1029,12 @@ async function runBackgroundAsyncTasks(

async function runTeamsFxBackgroundTasks() {
const upgradeable = isV3Enabled() && (await checkProjectUpgradable());
await handlers.autoOpenProjectHandler();
await handlers.promptSPFxUpgrade();
await TreeViewManagerInstance.updateTreeViewsByContent(upgradeable);
await AzureAccountManager.updateSubscriptionInfo();
if (isTeamsFxProject) {
await handlers.autoOpenProjectHandler();
await handlers.promptSPFxUpgrade();
await TreeViewManagerInstance.updateTreeViewsByContent(upgradeable);
await AzureAccountManager.updateSubscriptionInfo();
}
}

function registerInCommandController(
Expand All @@ -1053,6 +1056,10 @@ function runCommand(commandName: string, args: unknown[]) {

async function checkProjectUpgradable(): Promise<boolean> {
const versionCheckResult = await handlers.projectVersionCheck();
if (versionCheckResult.isErr()) {
unsetIsTeamsFxProject();
return false;
}
const upgradeable = versionCheckResult.isOk()
? versionCheckResult.value.isSupport == VersionState.upgradeable
: false;
Expand All @@ -1077,6 +1084,8 @@ async function detectedTeamsFxProject(context: vscode.ExtensionContext) {
}

const upgradeable = await checkProjectUpgradable();
await vscode.commands.executeCommand("setContext", "fx-extension.canUpgradeV3", upgradeable);
await TreeViewManagerInstance.updateTreeViewsByContent(upgradeable);
if (isTeamsFxProject) {
await vscode.commands.executeCommand("setContext", "fx-extension.canUpgradeV3", upgradeable);
await TreeViewManagerInstance.updateTreeViewsByContent(upgradeable);
}
}
5 changes: 5 additions & 0 deletions packages/vscode-extension/src/globalVariables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ export function setUriEventHandler(uriHandler: UriHandler) {
export function setCommandIsRunning(isRunning: boolean) {
commandIsRunning = isRunning;
}

// Only used by checkProjectUpgradable() when error happens
export function unsetIsTeamsFxProject() {
isTeamsFxProject = false;
}
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/utils/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export function getAppName(): string | undefined {
const yamlFilPath = path.join(globalVariables.workspaceUri!.fsPath, "teamsapp.yml");
try {
const settings = yaml.parse(fs.readFileSync(yamlFilPath, "utf-8"));
for (const action of settings?.registerApp) {
for (const action of settings?.provision) {
if (action?.uses === "teamsApp/create") {
const name = action?.with?.name;
if (name) {
Expand Down
11 changes: 10 additions & 1 deletion packages/vscode-extension/test/extension/commonUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ describe("CommonUtils", () => {

it("get app name successfully - v3", () => {
const ymlData = `# Triggered when 'teamsfx provision' is executed
registerApp:
provision:
- uses: aadApp/create # Creates a new AAD app to authenticate users if AAD_APP_CLIENT_ID environment variable is empty
with:
name: appNameTest-aad
Expand All @@ -325,6 +325,15 @@ describe("CommonUtils", () => {
expect(res).equal("appNameTest");
});

it("empty yml file - v3", () => {
sandbox.stub(globalVariables, "workspaceUri").value(Uri.file("test"));
sandbox.stub(fs, "readFileSync").returns("");
sandbox.stub(commonTools, "isV3Enabled").returns(true);

const res = commonUtils.getAppName();
expect(res).equal(undefined);
});

it("throw exception - v3", () => {
sandbox.stub(globalVariables, "workspaceUri").value(Uri.file("test"));
sandbox.stub(fs, "readFileSync").throws();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,5 +122,12 @@ describe("Global Variables", () => {
chai.expect(globalVariables.commandIsRunning).equals(true);
sinon.restore();
});

it("unsetIsTeamsFxProject()", async () => {
globalVariables.unsetIsTeamsFxProject();

chai.expect(globalVariables.isTeamsFxProject).equals(false);
sinon.restore();
});
});
});