Skip to content

Commit

Permalink
Added site runtime preview code behind ECS Config (#1052)
Browse files Browse the repository at this point in the history
* Added site runtime preview code behind ECS Config

* localization added and moved preview site code to separate file

* fixed build failures and handled empty website recordID

* Corrected website details ppapi service for runtime preview

* merged main branch to runtimePreviewECS

* correcting function call for runtime preview

* corrected localised error

* removed bug of no show command found

* Launch Edge new tab instead of launching project

---------

Co-authored-by: Ashwani Kumar <[email protected]>
Co-authored-by: Priyanshu Agrawal <[email protected]>
  • Loading branch information
3 people authored Dec 17, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 9dbedcf commit 50fa107
Showing 13 changed files with 301 additions and 35 deletions.
61 changes: 34 additions & 27 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
@@ -33,6 +33,7 @@
},
"Enter the environment URL": "Enter the environment URL",
"Active auth profile is not found or has expired. To create a new auth profile, enter the environment URL.": "Active auth profile is not found or has expired. To create a new auth profile, enter the environment URL.",
"Website not found in the environment. Please check the credentials and root folder path.": "Website not found in the environment. Please check the credentials and root folder path.",
"Selection is empty.": "Selection is empty.",
"PREVIEW": "PREVIEW",
"Explain the following code snippet:": "Explain the following code snippet:",
@@ -83,40 +84,22 @@
"Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.": "Hi! Power Pages lets you build secure, professional websites that you can quickly configure and publish across web browsers and devices.\n\nTo create your website, visit the [Power Pages](https://powerpages.microsoft.com/).\nReturn to this chat and @powerpages can help you write and edit your website code.",
"Checking for active auth profile...": "Checking for active auth profile...",
"@PowerPages is not yet available in your region.": "@PowerPages is not yet available in your region.",
"Failed to get site content from NL2Site service": "Failed to get site content from NL2Site service",
"Generating webpages...": "Generating webpages...",
"Generating a new Power Pages site...": "Generating a new Power Pages site...",
"Failed to create a new Power Pages site. Please try again.": "Failed to create a new Power Pages site. Please try again.",
"Select Folder for new PCF Control/Do not translate 'PCF' as it is a product name.": {
"message": "Select Folder for new PCF Control",
"comment": [
"Do not translate 'PCF' as it is a product name."
]
},
"Preparing pac CLI (v{0}).../{0} represents the version number": {
"message": "Preparing pac CLI (v{0})...",
"comment": [
"{0} represents the version number"
]
},
"The pac CLI is ready for use in your VS Code terminal!": "The pac CLI is ready for use in your VS Code terminal!",
"Cannot install pac CLI: {0}/{0} represents the error message returned from the exception": {
"message": "Cannot install pac CLI: {0}",
"comment": [
"{0} represents the error message returned from the exception"
]
},
"Installing Power Pages generator(v{0}).../{0} represents the version number": {
"message": "Installing Power Pages generator(v{0})...",
"comment": [
"{0} represents the version number"
]
},
"dotnet sdk 6.0 or greater must be installed/Do not translate 'dotnet' or 'sdk'": {
"message": "dotnet sdk 6.0 or greater must be installed",
"comment": [
"Do not translate 'dotnet' or 'sdk'"
]
},
"The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?": "The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?",
"Install": "Install",
"Cancel": "Cancel",
"Site runtime preview feature is not enabled.": "Site runtime preview feature is not enabled.",
"No workspace folder opened. Please open a site folder to preview.": "No workspace folder opened. Please open a site folder to preview.",
"Website URL not found.": "Website URL not found.",
"Opening site preview...": "Opening site preview...",
"File might be referenced by name {0} here./{0} represents the name of the file": {
"message": "File might be referenced by name {0} here.",
"comment": [
@@ -188,6 +171,12 @@
"Do not translate 'npm'"
]
},
"Installing Power Pages generator(v{0}).../{0} represents the version number": {
"message": "Installing Power Pages generator(v{0})...",
"comment": [
"{0} represents the version number"
]
},
"Cannot install Power Pages generator: {0}/{0} represents the error message returned from the exception": {
"message": "Cannot install Power Pages generator: {0}",
"comment": [
@@ -217,9 +206,27 @@
"The {3} represents Dataverse Environment's Organization ID (GUID)"
]
},
"Preparing pac CLI (v{0}).../{0} represents the version number": {
"message": "Preparing pac CLI (v{0})...",
"comment": [
"{0} represents the version number"
]
},
"The pac CLI is ready for use in your VS Code terminal!": "The pac CLI is ready for use in your VS Code terminal!",
"Cannot install pac CLI: {0}/{0} represents the error message returned from the exception": {
"message": "Cannot install pac CLI: {0}",
"comment": [
"{0} represents the error message returned from the exception"
]
},
"dotnet sdk 6.0 or greater must be installed/Do not translate 'dotnet' or 'sdk'": {
"message": "dotnet sdk 6.0 or greater must be installed",
"comment": [
"Do not translate 'dotnet' or 'sdk'"
]
},
"Confirm": "Confirm",
"Are you sure you want to clear all the Auth Profiles?": "Are you sure you want to clear all the Auth Profiles?",
"Cancel": "Cancel",
"Are you sure you want to delete the Auth Profile {0}-{1}?/{0} is the user name, {1} is the URL of environment of the auth profile": {
"message": "Are you sure you want to delete the Auth Profile {0}-{1}?",
"comment": [
30 changes: 27 additions & 3 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
@@ -143,6 +143,9 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
<trans-unit id="++CODE++f9e17ed11037dab93f8820c30db63b2ff2a045b5761f71818b7291afae60f199">
<source xml:lang="en">Explain the following code {% include 'Page Copy'%}</source>
</trans-unit>
<trans-unit id="++CODE++b985f1515c42b4b5b0c11a3d7b3286fc9d66997d476668ab1f93a4a11499fef5">
<source xml:lang="en">Failed to create a new Power Pages site. Please try again.</source>
</trans-unit>
<trans-unit id="++CODE++2310c6b7e5953cab877859ba1fcfa98e58e1508677df9412010e9b578ea237f4">
<source xml:lang="en">Failed to create: {0}.</source>
<note>{0} will be replaced by the error message.</note>
@@ -159,9 +162,6 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
<trans-unit id="++CODE++862d6197d64601aa13ce30db5ec5b8f819ad00fe21e3b031a3e47fe22ef68fb3">
<source xml:lang="en">Failed to get file ready for edit: {0}</source>
</trans-unit>
<trans-unit id="++CODE++41405814c44fb391a3f8e31d1a3bc20299cd2e87979ebfbd1eb9488be12c617a">
<source xml:lang="en">Failed to get site content from NL2Site service</source>
</trans-unit>
<trans-unit id="++CODE++a9e36b880dd45b64ae5601865540605296febf9bd855fc46d9c35c2c2ed9a7f2">
<source xml:lang="en">Feature is not enabled for this geo.</source>
</trans-unit>
@@ -217,6 +217,9 @@ Return to this chat and @powerpages can help you write and edit your website cod
<trans-unit id="++CODE++e992151b1efc99f93484c7d7f3076b66ab072a8af2383e96104cc597c971339c">
<source xml:lang="en">Insert code into editor</source>
</trans-unit>
<trans-unit id="++CODE++569ca49f4aaf7846e952c1d4aeca72febd0b79fa1c4f9db08fd3127551218572">
<source xml:lang="en">Install</source>
</trans-unit>
<trans-unit id="++CODE++25109e9c19daeeed3977b84ace83722ac8a4daafcfe4e3709082fcc5b228e7a8">
<source xml:lang="en">Installing Power Pages generator(v{0})...</source>
<note>{0} represents the version number</note>
@@ -294,6 +297,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++6da29e062697a9f26659ef14ebda075afe939756af5d8e1d3451eb7d6d6e1a8a">
<source xml:lang="en">No workspace folder found</source>
</trans-unit>
<trans-unit id="++CODE++6c0242ffba2aababcb4e45831de1492e8bccae2cb0f3387dfe9c16620f6928ef">
<source xml:lang="en">No workspace folder opened. Please open a site folder to preview.</source>
</trans-unit>
<trans-unit id="++CODE++bda6bda1e902d120a7f4515ceac8546c3112e3cb9351df1d8b9713b8f86e0370">
<source xml:lang="en">One or more attribute names have been changed or removed. Contact your admin.</source>
</trans-unit>
@@ -303,6 +309,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++dac0ee62a5197a3722a9e7e9e851e80504cced8a13ce8b17842d78e8313578c2">
<source xml:lang="en">Opening preview site...</source>
</trans-unit>
<trans-unit id="++CODE++e61c4ac3c692e3cfdc02717db82d18b1e9d51242710031f20af35b33d149fa7a">
<source xml:lang="en">Opening site preview...</source>
</trans-unit>
<trans-unit id="++CODE++5cac0147c19013eb88b1fc8dc0d066b48e9f5cfcdbc9737a29d544d9bd61db55">
<source xml:lang="en">Operation failed. See output panel for details.</source>
</trans-unit>
@@ -376,6 +385,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++899fb203e6c2faac8093e21a2fa8db0d4b13d16ea5492461d8b72dbcee3ecf2a">
<source xml:lang="en">Show Output Panel</source>
</trans-unit>
<trans-unit id="++CODE++f7094162bd4c4b59aa706387714347223e1569c79c5b37eb19ac754a33a0fdd0">
<source xml:lang="en">Site runtime preview feature is not enabled.</source>
</trans-unit>
<trans-unit id="++CODE++27dd8c8e67d15783f51c6b71ed60d5350731daa85b418f1e84c2e5828ae2d54e">
<source xml:lang="en">Some references might be broken. Please check diagnostics for details.</source>
</trans-unit>
@@ -391,6 +403,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++618f7afd7be2f12bf2ebbaba5bc7e951d2ebfb11d4480647f991fbb664caa26e">
<source xml:lang="en">The Power Pages generator is ready for use in your VS Code extension!</source>
</trans-unit>
<trans-unit id="++CODE++538ecf1398703f8a2048b99a2b2a533012b06ee88d67a0fd6fbbcd716cfbd663">
<source xml:lang="en">The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?</source>
</trans-unit>
<trans-unit id="++CODE++e4a2396fd7a366292a40abc87b18a2329458c258f4d0e0e593e6189dff19a117">
<source xml:lang="en">The name you want to give to this authentication profile</source>
</trans-unit>
@@ -449,6 +464,12 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++00dc171124ab430bbbaae51ec39dda1c5e7d045f382f56b1767d9e733292731c">
<source xml:lang="en">Webpage names should contain only letters, numbers, hyphens, or underscores.</source>
</trans-unit>
<trans-unit id="++CODE++968729c173b0e6967fc054251835e9196b1e09ad7c55ab7b0acafb3402a9d5d6">
<source xml:lang="en">Website URL not found.</source>
</trans-unit>
<trans-unit id="++CODE++4ed689987736ce09e17c67eb32f441ca7d0f7ed013a282aafd1ebcf302e6386b">
<source xml:lang="en">Website not found in the environment. Please check the credentials and root folder path.</source>
</trans-unit>
<trans-unit id="++CODE++e4bb03b399c07eeda658d87305435a58818cb5e0c3b76ae054d99564cf14ef6b">
<source xml:lang="en">What do you need help with?</source>
</trans-unit>
@@ -617,6 +638,9 @@ The second line should be '[TRANSLATION HERE](command:powerplatform-walkthrough.
<trans-unit id="microsoft-powerapps-portals.preview-show.title">
<source xml:lang="en">PowerApps Portal -&gt; Show preview</source>
</trans-unit>
<trans-unit id="powerplatform.pages.previewSite.title">
<source xml:lang="en">Preview Site</source>
</trans-unit>
<trans-unit id="pacCLI.envAndSolutionsPanel.refresh.title">
<source xml:lang="en">Refresh</source>
</trans-unit>
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -370,6 +370,10 @@
"command": "powerPlatform.previewCurrentActiveUsers",
"title": "Current Active Users",
"icon": "$(person)"
},
{
"command": "microsoft.powerplatform.pages.preview-site",
"title": "%powerplatform.pages.previewSite.title%"
}
],
"configuration": {
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
@@ -97,5 +97,6 @@
"The fifth line should be '[TRANSLATION HERE](command:powerplatform-walkthrough.saveConflict-learn-more).', keeping brackets and the text in the parentheses unmodified"
]
},
"microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title": "POWER PAGES ACTIONS"
"microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title": "POWER PAGES ACTIONS",
"powerplatform.pages.previewSite.title": "Preview Site"
}
24 changes: 24 additions & 0 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
@@ -46,6 +46,7 @@ import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/
import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient";
import { getECSOrgLocationValue } from "../common/utilities/Utils";
import { CliAcquisitionContext } from "./lib/CliAcquisitionContext";
import { PreviewSite, SITE_PREVIEW_COMMAND_ID } from "./runtime-site-preview/PreviewSite";

let client: LanguageClient;
let _context: vscode.ExtensionContext;
@@ -195,6 +196,9 @@ export async function activate(
) || [];


let websiteURL: string | undefined = "";
const isSiteRuntimePreviewEnabled = PreviewSite.isSiteRuntimePreviewEnabled();

_context.subscriptions.push(
orgChangeEvent(async (orgDetails: ActiveOrgOutput) => {
const orgID = orgDetails.OrgId;
@@ -250,6 +254,10 @@ export async function activate(

}

if (artemisResponse !== null && isSiteRuntimePreviewEnabled) {
websiteURL = await PreviewSite.getWebSiteURL(workspaceFolders, artemisResponse?.stamp, orgDetails.EnvironmentId, _telemetry);
}

})
);

@@ -270,6 +278,22 @@ export async function activate(
vscode.commands.executeCommand('setContext', 'powerpages.websiteYmlExists', false);
}

_telemetry.sendTelemetryEvent("EnableSiteRuntimePreview", {
isEnabled: isSiteRuntimePreviewEnabled.toString(),
websiteURL: websiteURL
});
oneDSLoggerWrapper.getLogger().traceInfo("EnableSiteRuntimePreview", {
isEnabled: isSiteRuntimePreviewEnabled.toString(),
websiteURL: websiteURL
});

_context.subscriptions.push(
vscode.commands.registerCommand(
SITE_PREVIEW_COMMAND_ID,
async () => await PreviewSite.handlePreviewRequest(isSiteRuntimePreviewEnabled, websiteURL, _telemetry)
)
);

const workspaceFolderWatcher = vscode.workspace.onDidChangeWorkspaceFolders(handleWorkspaceFolderChange);
_context.subscriptions.push(workspaceFolderWatcher);

102 changes: 102 additions & 0 deletions src/client/runtime-site-preview/PreviewSite.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*/

import * as vscode from 'vscode';
import { ECSFeaturesClient } from '../../common/ecs-features/ecsFeatureClient';
import { EnableSiteRuntimePreview } from '../../common/ecs-features/ecsFeatureGates';
import { ITelemetry } from '../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';
import { WorkspaceFolder } from 'vscode-languageclient/node';
import { getWebsiteRecordId } from '../../common/utilities/WorkspaceInfoFinderUtil';
import { ServiceEndpointCategory } from '../../common/services/Constants';
import { PPAPIService } from '../../common/services/PPAPIService';
import { VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY } from '../../common/services/TelemetryConstants';
import { EDGE_TOOLS_EXTENSION_ID } from '../../common/constants';
import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper";
import { showProgressNotification } from '../../common/controls/ShowProgressNotification';

export const SITE_PREVIEW_COMMAND_ID = "microsoft.powerplatform.pages.preview-site";

export class PreviewSite {
static isSiteRuntimePreviewEnabled(): boolean {
const enableSiteRuntimePreview = ECSFeaturesClient.getConfig(EnableSiteRuntimePreview).enableSiteRuntimePreview

if (enableSiteRuntimePreview === undefined) {
return false;
}

return enableSiteRuntimePreview;
}

static async getWebSiteURL(workspaceFolders: WorkspaceFolder[], stamp: ServiceEndpointCategory, envId: string, telemetry: ITelemetry): Promise<string> {
const websiteRecordId = getWebsiteRecordId(workspaceFolders, telemetry);
if (!websiteRecordId) {
telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY, {
websiteRecordId: websiteRecordId
});
return "";
}
const websiteDetails = await PPAPIService.getWebsiteDetailsByWebsiteRecordId(stamp, envId, websiteRecordId, telemetry);
return websiteDetails?.websiteUrl || "";
}

static async launchBrowserAndDevToolsWithinVsCode(webSitePreviewURL: string | undefined): Promise<void> {
if (!webSitePreviewURL || webSitePreviewURL === "") {
return;
}

const edgeToolsExtension = vscode.extensions.getExtension(EDGE_TOOLS_EXTENSION_ID);

if (!edgeToolsExtension) {
const install = await vscode.window.showWarningMessage(
vscode.l10n.t(
`The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?`
),
vscode.l10n.t('Install'),
vscode.l10n.t('Cancel')
);

if (install === vscode.l10n.t('Install')) {
await vscode.commands.executeCommand('workbench.extensions.search', EDGE_TOOLS_EXTENSION_ID);
}

return;
}

const settings = vscode.workspace.getConfiguration('vscode-edge-devtools');
const currentDefaultUrl = await settings.get('defaultUrl');
await settings.update('defaultUrl', webSitePreviewURL);
await vscode.commands.executeCommand('vscode-edge-devtools-view.launch');
await settings.update('defaultUrl', currentDefaultUrl);
}

static async handlePreviewRequest(isSiteRuntimePreviewEnabled: boolean, websiteURL: string | undefined, telemetry: ITelemetry) {
telemetry.sendTelemetryEvent("StartCommand", {
commandId: SITE_PREVIEW_COMMAND_ID,
});
oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", {
commandId: SITE_PREVIEW_COMMAND_ID
});

if (!isSiteRuntimePreviewEnabled) {
await vscode.window.showInformationMessage(vscode.l10n.t("Site runtime preview feature is not enabled."));
return;
}

if (!vscode.workspace.workspaceFolders) {
await vscode.window.showErrorMessage(vscode.l10n.t("No workspace folder opened. Please open a site folder to preview."));
return;
}

if (!websiteURL || websiteURL === "") {
await vscode.window.showErrorMessage(vscode.l10n.t("Website URL not found."));
return;
}

await showProgressNotification(
vscode.l10n.t('Opening site preview...'),
async () => await PreviewSite.launchBrowserAndDevToolsWithinVsCode(websiteURL)
);
}
}
2 changes: 1 addition & 1 deletion src/common/OneDSLoggerTelemetry/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
@@ -18,6 +18,7 @@ export const CleanupRelatedFilesEvent = 'CleanupRelatedFilesEvent';
export const UpdateEntityNameInYmlEvent = 'UpdateEntityNameInYmlEvent';
export const UserFileCreateEvent = 'UserFileCreateEvent';
export const FileCreateEvent = 'FileCreateEvent';
export const GetWebsiteRecordID = 'getWebsiteRecordId';

interface ITelemetryData {
eventName: string,
@@ -68,4 +69,3 @@ export function sendTelemetryEvent(telemetry: ITelemetry, telemetryData: ITeleme
oneDSLoggerWrapper.getLogger().traceInfo(telemetryData.eventName, telemetryDataProperties, telemetryDataMeasurements);
}
}

Loading

0 comments on commit 50fa107

Please sign in to comment.