Skip to content

Commit 50fa107

Browse files
ashwani123psparrow1303priyanshu92
authored
Added site runtime preview code behind ECS Config (#1052)
* 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]>
1 parent 9dbedcf commit 50fa107

File tree

13 files changed

+301
-35
lines changed

13 files changed

+301
-35
lines changed

l10n/bundle.l10n.json

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
},
3434
"Enter the environment URL": "Enter the environment URL",
3535
"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.",
36+
"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.",
3637
"Selection is empty.": "Selection is empty.",
3738
"PREVIEW": "PREVIEW",
3839
"Explain the following code snippet:": "Explain the following code snippet:",
@@ -83,40 +84,22 @@
8384
"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.",
8485
"Checking for active auth profile...": "Checking for active auth profile...",
8586
"@PowerPages is not yet available in your region.": "@PowerPages is not yet available in your region.",
86-
"Failed to get site content from NL2Site service": "Failed to get site content from NL2Site service",
8787
"Generating webpages...": "Generating webpages...",
8888
"Generating a new Power Pages site...": "Generating a new Power Pages site...",
89+
"Failed to create a new Power Pages site. Please try again.": "Failed to create a new Power Pages site. Please try again.",
8990
"Select Folder for new PCF Control/Do not translate 'PCF' as it is a product name.": {
9091
"message": "Select Folder for new PCF Control",
9192
"comment": [
9293
"Do not translate 'PCF' as it is a product name."
9394
]
9495
},
95-
"Preparing pac CLI (v{0}).../{0} represents the version number": {
96-
"message": "Preparing pac CLI (v{0})...",
97-
"comment": [
98-
"{0} represents the version number"
99-
]
100-
},
101-
"The pac CLI is ready for use in your VS Code terminal!": "The pac CLI is ready for use in your VS Code terminal!",
102-
"Cannot install pac CLI: {0}/{0} represents the error message returned from the exception": {
103-
"message": "Cannot install pac CLI: {0}",
104-
"comment": [
105-
"{0} represents the error message returned from the exception"
106-
]
107-
},
108-
"Installing Power Pages generator(v{0}).../{0} represents the version number": {
109-
"message": "Installing Power Pages generator(v{0})...",
110-
"comment": [
111-
"{0} represents the version number"
112-
]
113-
},
114-
"dotnet sdk 6.0 or greater must be installed/Do not translate 'dotnet' or 'sdk'": {
115-
"message": "dotnet sdk 6.0 or greater must be installed",
116-
"comment": [
117-
"Do not translate 'dotnet' or 'sdk'"
118-
]
119-
},
96+
"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?",
97+
"Install": "Install",
98+
"Cancel": "Cancel",
99+
"Site runtime preview feature is not enabled.": "Site runtime preview feature is not enabled.",
100+
"No workspace folder opened. Please open a site folder to preview.": "No workspace folder opened. Please open a site folder to preview.",
101+
"Website URL not found.": "Website URL not found.",
102+
"Opening site preview...": "Opening site preview...",
120103
"File might be referenced by name {0} here./{0} represents the name of the file": {
121104
"message": "File might be referenced by name {0} here.",
122105
"comment": [
@@ -188,6 +171,12 @@
188171
"Do not translate 'npm'"
189172
]
190173
},
174+
"Installing Power Pages generator(v{0}).../{0} represents the version number": {
175+
"message": "Installing Power Pages generator(v{0})...",
176+
"comment": [
177+
"{0} represents the version number"
178+
]
179+
},
191180
"Cannot install Power Pages generator: {0}/{0} represents the error message returned from the exception": {
192181
"message": "Cannot install Power Pages generator: {0}",
193182
"comment": [
@@ -217,9 +206,27 @@
217206
"The {3} represents Dataverse Environment's Organization ID (GUID)"
218207
]
219208
},
209+
"Preparing pac CLI (v{0}).../{0} represents the version number": {
210+
"message": "Preparing pac CLI (v{0})...",
211+
"comment": [
212+
"{0} represents the version number"
213+
]
214+
},
215+
"The pac CLI is ready for use in your VS Code terminal!": "The pac CLI is ready for use in your VS Code terminal!",
216+
"Cannot install pac CLI: {0}/{0} represents the error message returned from the exception": {
217+
"message": "Cannot install pac CLI: {0}",
218+
"comment": [
219+
"{0} represents the error message returned from the exception"
220+
]
221+
},
222+
"dotnet sdk 6.0 or greater must be installed/Do not translate 'dotnet' or 'sdk'": {
223+
"message": "dotnet sdk 6.0 or greater must be installed",
224+
"comment": [
225+
"Do not translate 'dotnet' or 'sdk'"
226+
]
227+
},
220228
"Confirm": "Confirm",
221229
"Are you sure you want to clear all the Auth Profiles?": "Are you sure you want to clear all the Auth Profiles?",
222-
"Cancel": "Cancel",
223230
"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": {
224231
"message": "Are you sure you want to delete the Auth Profile {0}-{1}?",
225232
"comment": [

loc/translations-export/vscode-powerplatform.xlf

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,9 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
143143
<trans-unit id="++CODE++f9e17ed11037dab93f8820c30db63b2ff2a045b5761f71818b7291afae60f199">
144144
<source xml:lang="en">Explain the following code {% include 'Page Copy'%}</source>
145145
</trans-unit>
146+
<trans-unit id="++CODE++b985f1515c42b4b5b0c11a3d7b3286fc9d66997d476668ab1f93a4a11499fef5">
147+
<source xml:lang="en">Failed to create a new Power Pages site. Please try again.</source>
148+
</trans-unit>
146149
<trans-unit id="++CODE++2310c6b7e5953cab877859ba1fcfa98e58e1508677df9412010e9b578ea237f4">
147150
<source xml:lang="en">Failed to create: {0}.</source>
148151
<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
159162
<trans-unit id="++CODE++862d6197d64601aa13ce30db5ec5b8f819ad00fe21e3b031a3e47fe22ef68fb3">
160163
<source xml:lang="en">Failed to get file ready for edit: {0}</source>
161164
</trans-unit>
162-
<trans-unit id="++CODE++41405814c44fb391a3f8e31d1a3bc20299cd2e87979ebfbd1eb9488be12c617a">
163-
<source xml:lang="en">Failed to get site content from NL2Site service</source>
164-
</trans-unit>
165165
<trans-unit id="++CODE++a9e36b880dd45b64ae5601865540605296febf9bd855fc46d9c35c2c2ed9a7f2">
166166
<source xml:lang="en">Feature is not enabled for this geo.</source>
167167
</trans-unit>
@@ -217,6 +217,9 @@ Return to this chat and @powerpages can help you write and edit your website cod
217217
<trans-unit id="++CODE++e992151b1efc99f93484c7d7f3076b66ab072a8af2383e96104cc597c971339c">
218218
<source xml:lang="en">Insert code into editor</source>
219219
</trans-unit>
220+
<trans-unit id="++CODE++569ca49f4aaf7846e952c1d4aeca72febd0b79fa1c4f9db08fd3127551218572">
221+
<source xml:lang="en">Install</source>
222+
</trans-unit>
220223
<trans-unit id="++CODE++25109e9c19daeeed3977b84ace83722ac8a4daafcfe4e3709082fcc5b228e7a8">
221224
<source xml:lang="en">Installing Power Pages generator(v{0})...</source>
222225
<note>{0} represents the version number</note>
@@ -294,6 +297,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
294297
<trans-unit id="++CODE++6da29e062697a9f26659ef14ebda075afe939756af5d8e1d3451eb7d6d6e1a8a">
295298
<source xml:lang="en">No workspace folder found</source>
296299
</trans-unit>
300+
<trans-unit id="++CODE++6c0242ffba2aababcb4e45831de1492e8bccae2cb0f3387dfe9c16620f6928ef">
301+
<source xml:lang="en">No workspace folder opened. Please open a site folder to preview.</source>
302+
</trans-unit>
297303
<trans-unit id="++CODE++bda6bda1e902d120a7f4515ceac8546c3112e3cb9351df1d8b9713b8f86e0370">
298304
<source xml:lang="en">One or more attribute names have been changed or removed. Contact your admin.</source>
299305
</trans-unit>
@@ -303,6 +309,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
303309
<trans-unit id="++CODE++dac0ee62a5197a3722a9e7e9e851e80504cced8a13ce8b17842d78e8313578c2">
304310
<source xml:lang="en">Opening preview site...</source>
305311
</trans-unit>
312+
<trans-unit id="++CODE++e61c4ac3c692e3cfdc02717db82d18b1e9d51242710031f20af35b33d149fa7a">
313+
<source xml:lang="en">Opening site preview...</source>
314+
</trans-unit>
306315
<trans-unit id="++CODE++5cac0147c19013eb88b1fc8dc0d066b48e9f5cfcdbc9737a29d544d9bd61db55">
307316
<source xml:lang="en">Operation failed. See output panel for details.</source>
308317
</trans-unit>
@@ -376,6 +385,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
376385
<trans-unit id="++CODE++899fb203e6c2faac8093e21a2fa8db0d4b13d16ea5492461d8b72dbcee3ecf2a">
377386
<source xml:lang="en">Show Output Panel</source>
378387
</trans-unit>
388+
<trans-unit id="++CODE++f7094162bd4c4b59aa706387714347223e1569c79c5b37eb19ac754a33a0fdd0">
389+
<source xml:lang="en">Site runtime preview feature is not enabled.</source>
390+
</trans-unit>
379391
<trans-unit id="++CODE++27dd8c8e67d15783f51c6b71ed60d5350731daa85b418f1e84c2e5828ae2d54e">
380392
<source xml:lang="en">Some references might be broken. Please check diagnostics for details.</source>
381393
</trans-unit>
@@ -391,6 +403,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
391403
<trans-unit id="++CODE++618f7afd7be2f12bf2ebbaba5bc7e951d2ebfb11d4480647f991fbb664caa26e">
392404
<source xml:lang="en">The Power Pages generator is ready for use in your VS Code extension!</source>
393405
</trans-unit>
406+
<trans-unit id="++CODE++538ecf1398703f8a2048b99a2b2a533012b06ee88d67a0fd6fbbcd716cfbd663">
407+
<source xml:lang="en">The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?</source>
408+
</trans-unit>
394409
<trans-unit id="++CODE++e4a2396fd7a366292a40abc87b18a2329458c258f4d0e0e593e6189dff19a117">
395410
<source xml:lang="en">The name you want to give to this authentication profile</source>
396411
</trans-unit>
@@ -449,6 +464,12 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
449464
<trans-unit id="++CODE++00dc171124ab430bbbaae51ec39dda1c5e7d045f382f56b1767d9e733292731c">
450465
<source xml:lang="en">Webpage names should contain only letters, numbers, hyphens, or underscores.</source>
451466
</trans-unit>
467+
<trans-unit id="++CODE++968729c173b0e6967fc054251835e9196b1e09ad7c55ab7b0acafb3402a9d5d6">
468+
<source xml:lang="en">Website URL not found.</source>
469+
</trans-unit>
470+
<trans-unit id="++CODE++4ed689987736ce09e17c67eb32f441ca7d0f7ed013a282aafd1ebcf302e6386b">
471+
<source xml:lang="en">Website not found in the environment. Please check the credentials and root folder path.</source>
472+
</trans-unit>
452473
<trans-unit id="++CODE++e4bb03b399c07eeda658d87305435a58818cb5e0c3b76ae054d99564cf14ef6b">
453474
<source xml:lang="en">What do you need help with?</source>
454475
</trans-unit>
@@ -617,6 +638,9 @@ The second line should be '[TRANSLATION HERE](command:powerplatform-walkthrough.
617638
<trans-unit id="microsoft-powerapps-portals.preview-show.title">
618639
<source xml:lang="en">PowerApps Portal -&gt; Show preview</source>
619640
</trans-unit>
641+
<trans-unit id="powerplatform.pages.previewSite.title">
642+
<source xml:lang="en">Preview Site</source>
643+
</trans-unit>
620644
<trans-unit id="pacCLI.envAndSolutionsPanel.refresh.title">
621645
<source xml:lang="en">Refresh</source>
622646
</trans-unit>

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,10 @@
370370
"command": "powerPlatform.previewCurrentActiveUsers",
371371
"title": "Current Active Users",
372372
"icon": "$(person)"
373+
},
374+
{
375+
"command": "microsoft.powerplatform.pages.preview-site",
376+
"title": "%powerplatform.pages.previewSite.title%"
373377
}
374378
],
375379
"configuration": {

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,6 @@
9797
"The fifth line should be '[TRANSLATION HERE](command:powerplatform-walkthrough.saveConflict-learn-more).', keeping brackets and the text in the parentheses unmodified"
9898
]
9999
},
100-
"microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title": "POWER PAGES ACTIONS"
100+
"microsoft-powerplatform-portals.navigation-loop.powerPagesFileExplorer.title": "POWER PAGES ACTIONS",
101+
"powerplatform.pages.previewSite.title": "Preview Site"
101102
}

src/client/extension.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/
4646
import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient";
4747
import { getECSOrgLocationValue } from "../common/utilities/Utils";
4848
import { CliAcquisitionContext } from "./lib/CliAcquisitionContext";
49+
import { PreviewSite, SITE_PREVIEW_COMMAND_ID } from "./runtime-site-preview/PreviewSite";
4950

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

197198

199+
let websiteURL: string | undefined = "";
200+
const isSiteRuntimePreviewEnabled = PreviewSite.isSiteRuntimePreviewEnabled();
201+
198202
_context.subscriptions.push(
199203
orgChangeEvent(async (orgDetails: ActiveOrgOutput) => {
200204
const orgID = orgDetails.OrgId;
@@ -250,6 +254,10 @@ export async function activate(
250254

251255
}
252256

257+
if (artemisResponse !== null && isSiteRuntimePreviewEnabled) {
258+
websiteURL = await PreviewSite.getWebSiteURL(workspaceFolders, artemisResponse?.stamp, orgDetails.EnvironmentId, _telemetry);
259+
}
260+
253261
})
254262
);
255263

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

281+
_telemetry.sendTelemetryEvent("EnableSiteRuntimePreview", {
282+
isEnabled: isSiteRuntimePreviewEnabled.toString(),
283+
websiteURL: websiteURL
284+
});
285+
oneDSLoggerWrapper.getLogger().traceInfo("EnableSiteRuntimePreview", {
286+
isEnabled: isSiteRuntimePreviewEnabled.toString(),
287+
websiteURL: websiteURL
288+
});
289+
290+
_context.subscriptions.push(
291+
vscode.commands.registerCommand(
292+
SITE_PREVIEW_COMMAND_ID,
293+
async () => await PreviewSite.handlePreviewRequest(isSiteRuntimePreviewEnabled, websiteURL, _telemetry)
294+
)
295+
);
296+
273297
const workspaceFolderWatcher = vscode.workspace.onDidChangeWorkspaceFolders(handleWorkspaceFolderChange);
274298
_context.subscriptions.push(workspaceFolderWatcher);
275299

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*/
5+
6+
import * as vscode from 'vscode';
7+
import { ECSFeaturesClient } from '../../common/ecs-features/ecsFeatureClient';
8+
import { EnableSiteRuntimePreview } from '../../common/ecs-features/ecsFeatureGates';
9+
import { ITelemetry } from '../../common/OneDSLoggerTelemetry/telemetry/ITelemetry';
10+
import { WorkspaceFolder } from 'vscode-languageclient/node';
11+
import { getWebsiteRecordId } from '../../common/utilities/WorkspaceInfoFinderUtil';
12+
import { ServiceEndpointCategory } from '../../common/services/Constants';
13+
import { PPAPIService } from '../../common/services/PPAPIService';
14+
import { VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY } from '../../common/services/TelemetryConstants';
15+
import { EDGE_TOOLS_EXTENSION_ID } from '../../common/constants';
16+
import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper";
17+
import { showProgressNotification } from '../../common/controls/ShowProgressNotification';
18+
19+
export const SITE_PREVIEW_COMMAND_ID = "microsoft.powerplatform.pages.preview-site";
20+
21+
export class PreviewSite {
22+
static isSiteRuntimePreviewEnabled(): boolean {
23+
const enableSiteRuntimePreview = ECSFeaturesClient.getConfig(EnableSiteRuntimePreview).enableSiteRuntimePreview
24+
25+
if (enableSiteRuntimePreview === undefined) {
26+
return false;
27+
}
28+
29+
return enableSiteRuntimePreview;
30+
}
31+
32+
static async getWebSiteURL(workspaceFolders: WorkspaceFolder[], stamp: ServiceEndpointCategory, envId: string, telemetry: ITelemetry): Promise<string> {
33+
const websiteRecordId = getWebsiteRecordId(workspaceFolders, telemetry);
34+
if (!websiteRecordId) {
35+
telemetry.sendTelemetryEvent(VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY, {
36+
websiteRecordId: websiteRecordId
37+
});
38+
return "";
39+
}
40+
const websiteDetails = await PPAPIService.getWebsiteDetailsByWebsiteRecordId(stamp, envId, websiteRecordId, telemetry);
41+
return websiteDetails?.websiteUrl || "";
42+
}
43+
44+
static async launchBrowserAndDevToolsWithinVsCode(webSitePreviewURL: string | undefined): Promise<void> {
45+
if (!webSitePreviewURL || webSitePreviewURL === "") {
46+
return;
47+
}
48+
49+
const edgeToolsExtension = vscode.extensions.getExtension(EDGE_TOOLS_EXTENSION_ID);
50+
51+
if (!edgeToolsExtension) {
52+
const install = await vscode.window.showWarningMessage(
53+
vscode.l10n.t(
54+
`The extension Microsoft Edge Tools is required to run this command. Do you want to install it now?`
55+
),
56+
vscode.l10n.t('Install'),
57+
vscode.l10n.t('Cancel')
58+
);
59+
60+
if (install === vscode.l10n.t('Install')) {
61+
await vscode.commands.executeCommand('workbench.extensions.search', EDGE_TOOLS_EXTENSION_ID);
62+
}
63+
64+
return;
65+
}
66+
67+
const settings = vscode.workspace.getConfiguration('vscode-edge-devtools');
68+
const currentDefaultUrl = await settings.get('defaultUrl');
69+
await settings.update('defaultUrl', webSitePreviewURL);
70+
await vscode.commands.executeCommand('vscode-edge-devtools-view.launch');
71+
await settings.update('defaultUrl', currentDefaultUrl);
72+
}
73+
74+
static async handlePreviewRequest(isSiteRuntimePreviewEnabled: boolean, websiteURL: string | undefined, telemetry: ITelemetry) {
75+
telemetry.sendTelemetryEvent("StartCommand", {
76+
commandId: SITE_PREVIEW_COMMAND_ID,
77+
});
78+
oneDSLoggerWrapper.getLogger().traceInfo("StartCommand", {
79+
commandId: SITE_PREVIEW_COMMAND_ID
80+
});
81+
82+
if (!isSiteRuntimePreviewEnabled) {
83+
await vscode.window.showInformationMessage(vscode.l10n.t("Site runtime preview feature is not enabled."));
84+
return;
85+
}
86+
87+
if (!vscode.workspace.workspaceFolders) {
88+
await vscode.window.showErrorMessage(vscode.l10n.t("No workspace folder opened. Please open a site folder to preview."));
89+
return;
90+
}
91+
92+
if (!websiteURL || websiteURL === "") {
93+
await vscode.window.showErrorMessage(vscode.l10n.t("Website URL not found."));
94+
return;
95+
}
96+
97+
await showProgressNotification(
98+
vscode.l10n.t('Opening site preview...'),
99+
async () => await PreviewSite.launchBrowserAndDevToolsWithinVsCode(websiteURL)
100+
);
101+
}
102+
}

src/common/OneDSLoggerTelemetry/telemetry/telemetry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export const CleanupRelatedFilesEvent = 'CleanupRelatedFilesEvent';
1818
export const UpdateEntityNameInYmlEvent = 'UpdateEntityNameInYmlEvent';
1919
export const UserFileCreateEvent = 'UserFileCreateEvent';
2020
export const FileCreateEvent = 'FileCreateEvent';
21+
export const GetWebsiteRecordID = 'getWebsiteRecordId';
2122

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

0 commit comments

Comments
 (0)