Skip to content

Commit

Permalink
[PowerPages][Actions Hub] Toggle to Change Environment (#1119)
Browse files Browse the repository at this point in the history
* Add switch environment functionality to Actions Hub

* Update icon for switch environment command in Actions Hub

* Update translation for switch environment title to "Change Environment"

* Add tests for switch environment command registration and error handling

* Remove redundant error handling tests for switch environment and refresh commands

* Refactor command names to include namespace for actions in Actions Hub

* Update refresh command registration to include namespace in Actions Hub tests

---------

Co-authored-by: amitjoshi <[email protected]>
  • Loading branch information
amitjoshi438 and amitjoshi authored Feb 12, 2025
1 parent 8902752 commit 5a42a6e
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 11 deletions.
1 change: 1 addition & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@
"Inactive Sites": "Inactive Sites",
"No sites found": "No sites found",
"No environments found": "No environments found",
"Select an environment to switch to": "Select an environment to switch to",
"Active Environment is expired or deleted. Please select a new environment.": "Active Environment is expired or deleted. Please select a new environment.",
"PAC Telemetry enabled": "PAC Telemetry enabled",
"Failed to enable PAC telemetry.": "Failed to enable PAC telemetry.",
Expand Down
6 changes: 6 additions & 0 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++a40f78f3a7f5c5ab1b101e95cdf044552542712fdcf45a83dfea3f455b6f638a">
<source xml:lang="en">Select Type</source>
</trans-unit>
<trans-unit id="++CODE++ced4bf2ba126114717dde651370974e70f3a6ac603e69671be5d4d3e3a303c3c">
<source xml:lang="en">Select an environment to switch to</source>
</trans-unit>
<trans-unit id="++CODE++4d6f03fa73020c945e651c34d40c5529f3477ac02df254c1764a68d576575e14">
<source xml:lang="en">Selection is empty.</source>
</trans-unit>
Expand Down Expand Up @@ -569,6 +572,9 @@ To learn more, visit [Prevent accidental overwrites](command:powerplatform-walkt
<note>This is a Markdown formatted string, and the formatting must persist across translations.
The fifth line should be '[TRANSLATION HERE](command:powerplatform-walkthrough.saveConflict-learn-more).', keeping brackets and the text in the parentheses unmodified</note>
</trans-unit>
<trans-unit id="powerpages.actionsHub.switchEnvironment.title">
<source xml:lang="en">Change Environment</source>
</trans-unit>
<trans-unit id="pacCLI.authPanel.clearAuthProfile.title">
<source xml:lang="en">Clear Auth Profiles</source>
</trans-unit>
Expand Down
22 changes: 16 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -377,9 +377,14 @@
"title": "%powerplatform.pages.previewSite.title%"
},
{
"command": "powerpages.actionsHub.refresh",
"command": "microsoft.powerplatform.pages.actionsHub.refresh",
"title": "%powerpages.actionsHub.refresh.title%",
"icon": "$(refresh)"
},
{
"command": "microsoft.powerplatform.pages.actionsHub.switchEnvironment",
"title": "%powerpages.actionsHub.switchEnvironment.title%",
"icon": "$(arrow-swap)"
}
],
"configuration": {
Expand Down Expand Up @@ -855,11 +860,6 @@
"command": "powerpages.copilot.clearConversation",
"when": "view == powerpages.copilot",
"group": "navigation"
},
{
"command": "powerpages.actionsHub.refresh",
"when": "view == powerpages.actionsHub",
"group": "navigation"
}
],
"view/item/context": [
Expand Down Expand Up @@ -930,6 +930,16 @@
"command": "powerpages.collaboration.openMail",
"group": "inline",
"when": "viewItem == userNode"
},
{
"command": "microsoft.powerplatform.pages.actionsHub.refresh",
"when": "view == powerpages.actionsHub && viewItem == environmentGroup",
"group": "inline"
},
{
"command": "microsoft.powerplatform.pages.actionsHub.switchEnvironment",
"when": "view == powerpages.actionsHub && viewItem == environmentGroup",
"group": "inline"
}
]
},
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,6 @@
"microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title": "POWER PAGES ACTIONS",
"powerplatform.pages.previewSite.title": "Preview Site",
"microsoft.powerplatform.pages.actionsHub.title": "POWER PAGES ACTIONS",
"powerpages.actionsHub.refresh.title": "Refresh"
"powerpages.actionsHub.refresh.title": "Refresh",
"powerpages.actionsHub.switchEnvironment.title": "Change Environment"
}
29 changes: 28 additions & 1 deletion src/client/power-pages/actions-hub/ActionsHubTreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { pacAuthManager } from "../../pac/PacAuthManager";
import { SUCCESS } from "../../../common/constants";
import { extractAuthInfo } from "../commonUtility";
import { PacTerminal } from "../../lib/PacTerminal";
import { OrgListOutput } from "../../pac/PacTypes";

export class ActionsHubTreeDataProvider implements vscode.TreeDataProvider<ActionsHubTreeItem> {
private readonly _disposables: vscode.Disposable[] = [];
Expand Down Expand Up @@ -79,7 +80,7 @@ export class ActionsHubTreeDataProvider implements vscode.TreeDataProvider<Actio
private registerPanel(pacTerminal: PacTerminal): vscode.Disposable[] {
const pacWrapper = pacTerminal.getWrapper();
return [
vscode.commands.registerCommand("powerpages.actionsHub.refresh", async () => {
vscode.commands.registerCommand("microsoft.powerplatform.pages.actionsHub.refresh", async () => {
try {
const pacActiveAuth = await pacWrapper.activeAuth();
if (pacActiveAuth && pacActiveAuth.Status === SUCCESS) {
Expand All @@ -89,6 +90,32 @@ export class ActionsHubTreeDataProvider implements vscode.TreeDataProvider<Actio
} catch (error) {
oneDSLoggerWrapper.getLogger().traceError(Constants.EventNames.ACTIONS_HUB_REFRESH_FAILED, error as string, error as Error, { methodName: this.refresh.name }, {});
}
}),

vscode.commands.registerCommand("microsoft.powerplatform.pages.actionsHub.switchEnvironment", async () => {
const authInfo = pacAuthManager.getAuthInfo();
if(authInfo) {
const envListOutput = await pacWrapper.orgList();
if(envListOutput && envListOutput.Status === SUCCESS && envListOutput.Results) {
//envListOutput.Results is an array of OrgListOutput
const envList = envListOutput.Results as OrgListOutput[];
//show a quick pick to select the environment with friendly name and environment url
const selectedEnv = await vscode.window.showQuickPick(envList.map((env) => {
return {
label: env.FriendlyName,
description: env.EnvironmentUrl
}
}),
{
placeHolder: vscode.l10n.t(Constants.Strings.SELECT_ENVIRONMENT)
}
);

if(selectedEnv) {
await pacWrapper.orgSelect(selectedEnv.description);
}
}
}
})
];
}
Expand Down
3 changes: 2 additions & 1 deletion src/client/power-pages/actions-hub/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ export const Constants = {
ACTIVE_SITES: vscode.l10n.t("Active Sites"),
INACTIVE_SITES: vscode.l10n.t("Inactive Sites"),
NO_SITES_FOUND: vscode.l10n.t("No sites found"),
NO_ENVIRONMENTS_FOUND: vscode.l10n.t("No environments found")
NO_ENVIRONMENTS_FOUND: vscode.l10n.t("No environments found"),
SELECT_ENVIRONMENT: vscode.l10n.t("Select an environment to switch to")
},
EventNames: {
ACTIONS_HUB_INITIALIZED: "actionsHubInitialized",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ describe("ActionsHubTreeDataProvider", () => {
});

describe('initialize', () => {
it("should register refresh command", () => {
it("microsoft.powerplatform.pages.actionsHub.refresh", () => {
// Initialize
const actionsHubTreeDataProvider = ActionsHubTreeDataProvider.initialize(context, pacTerminal);
actionsHubTreeDataProvider["registerPanel"](pacTerminal);

// Assert that the command was registered
expect(registerCommandStub.calledWith("powerpages.actionsHub.refresh")).to.be.true;
expect(registerCommandStub.calledWith("microsoft.powerplatform.pages.actionsHub.refresh")).to.be.true;
});
});

Expand Down Expand Up @@ -134,4 +134,22 @@ describe("ActionsHubTreeDataProvider", () => {
});
});

describe('registerPanel', () => {
it("should register the refresh command", async () => {
const provider = ActionsHubTreeDataProvider.initialize(context, pacTerminal);
const disposables = provider["registerPanel"](pacTerminal);

expect(registerCommandStub.calledWith("microsoft.powerplatform.pages.actionsHub.refresh")).to.be.true;
expect(disposables).to.have.lengthOf(2);
});

it("should register the switch environment command", async () => {
const provider = ActionsHubTreeDataProvider.initialize(context, pacTerminal);
const disposables = provider["registerPanel"](pacTerminal);

expect(registerCommandStub.calledWith("microsoft.powerplatform.pages.actionsHub.switchEnvironment")).to.be.true;
expect(disposables).to.have.lengthOf(2);
});
});

});

0 comments on commit 5a42a6e

Please sign in to comment.