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

Site Runtime Preview Enhancements #1081

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
12 changes: 9 additions & 3 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
},
"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:",
Expand Down Expand Up @@ -96,10 +95,17 @@
"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",
"Opening site preview...": "Opening site preview...",
"The preview shown is for published changes.": "The preview shown is for published changes.",
"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...",
"Initializing site preview. Please try again after few seconds.": "Initializing site preview. Please try again after few seconds.",
"Website not found in the environment. Please check the credentials and login with correct account.": "Website not found in the environment. Please check the credentials and login with correct account.",
"Initializing site preview": "Initializing site preview",
"Getting org details...": "Getting org details...",
"Getting region information...": "Getting region information...",
"Failed to get website endpoint. Please try again later": "Failed to get website endpoint. Please try again later",
"Getting website endpoint...": "Getting website endpoint...",
"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": [
Expand Down
28 changes: 23 additions & 5 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ 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++51e1f5c5757cfd25a390293a7d8e9eb583943b66211fae1cbe25d07bfcb767f1">
<source xml:lang="en">Failed to get website endpoint. Please try again later</source>
</trans-unit>
<trans-unit id="++CODE++a9e36b880dd45b64ae5601865540605296febf9bd855fc46d9c35c2c2ed9a7f2">
<source xml:lang="en">Feature is not enabled for this geo.</source>
</trans-unit>
Expand Down Expand Up @@ -190,6 +193,15 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
<trans-unit id="++CODE++ee1d3100df4b00eabd74481b92106e42cce956213372a914082f82702f56470d">
<source xml:lang="en">Get GitHub Copilot to try @powerpages</source>
</trans-unit>
<trans-unit id="++CODE++68e1b7e92c5520ace7e24c69c89bd599053323522fc402d50d154fab5e7261dc">
<source xml:lang="en">Getting org details...</source>
</trans-unit>
<trans-unit id="++CODE++6f1bba10af9069a03da80d629b97c40fc4bedaf90a23496a2bdef0c512a92959">
<source xml:lang="en">Getting region information...</source>
</trans-unit>
<trans-unit id="++CODE++0087988cdb71080f2525354e125366c6db7d85a36f199e2f80d14a44b3fd0340">
<source xml:lang="en">Getting website endpoint...</source>
</trans-unit>
<trans-unit id="++CODE++b9f4adbdfa2deef1eaa415a914f63329ee06c604b5a1bf34645175b9e28a9712">
<source xml:lang="en">Here are a few suggestions to get you started</source>
</trans-unit>
Expand All @@ -214,6 +226,12 @@ Return to this chat and @powerpages can help you write and edit your website cod
<trans-unit id="++CODE++08295f3385931e35c850b945e2ae04882452c4bf0dd575f70e95aaa6ed00daa9">
<source xml:lang="en">In your own words, describe what you need. You can get help with writing code for Power Pages sites in HTML, CSS, and JS languages.</source>
</trans-unit>
<trans-unit id="++CODE++a22418694e3938cc42976630bcd24822ed4f671b168708e0641171440ca8f6dd">
<source xml:lang="en">Initializing site preview</source>
</trans-unit>
<trans-unit id="++CODE++15b09c32b0337229ff64c72f2ea9a3f8422fa20975ae494da863fd738554b1de">
<source xml:lang="en">Initializing site preview. Please try again after few seconds.</source>
</trans-unit>
<trans-unit id="++CODE++e992151b1efc99f93484c7d7f3076b66ab072a8af2383e96104cc597c971339c">
<source xml:lang="en">Insert code into editor</source>
</trans-unit>
Expand Down Expand Up @@ -412,6 +430,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++5eccedc8c04d2137a9eb74edf18ea469b4b63e7315de4b8fe49c48bb8d0780e9">
<source xml:lang="en">The pac CLI is ready for use in your VS Code terminal!</source>
</trans-unit>
<trans-unit id="++CODE++db00163e0e6fed2e319e28785c537befb88ded272d245e503d9580322ab2fec8">
<source xml:lang="en">The preview shown is for published changes.</source>
</trans-unit>
<trans-unit id="++CODE++18f3be2933741b96e56b1e1f70818fcba46ec9c5b3dcd0e28d801eab15791d84">
<source xml:lang="en">There was a permissions problem with the server</source>
</trans-unit>
Expand Down Expand Up @@ -464,11 +485,8 @@ 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 id="++CODE++aa64cfbb63d3382bc0530c6e599467b1cc5c1ef8ff3b573d37ad628f9058b2aa">
<source xml:lang="en">Website not found in the environment. Please check the credentials and login with correct account.</source>
</trans-unit>
<trans-unit id="++CODE++e4bb03b399c07eeda658d87305435a58818cb5e0c3b76ae054d99564cf14ef6b">
<source xml:lang="en">What do you need help with?</source>
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@
},
{
"command": "microsoft.powerplatform.pages.preview-site",
"category": "Powerpages",
"title": "%powerplatform.pages.previewSite.title%"
}
],
Expand Down Expand Up @@ -817,7 +818,7 @@
},
{
"command": "microsoft.powerplatform.pages.preview-site",
"when": "microsoft.powerplatform.pages.siteRuntimePreviewEnabled"
"when": "microsoft.powerplatform.pages.siteRuntimePreviewEnabled && workspaceFolderCount == 1 && !isWeb"
priyanshu92 marked this conversation as resolved.
Show resolved Hide resolved
},
{
"command": "powerPlatform.previewCurrentActiveUsers",
Expand Down
17 changes: 6 additions & 11 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ import { EXTENSION_ID, SUCCESS } from "../common/constants";
import { AadIdKey, EnvIdKey, TenantIdKey } from "../common/OneDSLoggerTelemetry/telemetryConstants";
import { PowerPagesAppName, PowerPagesClientName } from "../common/ecs-features/constants";
import { ECSFeaturesClient } from "../common/ecs-features/ecsFeatureClient";
import { getECSOrgLocationValue } from "../common/utilities/Utils";
import { getECSOrgLocationValue, getWorkspaceFolders } from "../common/utilities/Utils";
import { CliAcquisitionContext } from "./lib/CliAcquisitionContext";
import { PreviewSite, SITE_PREVIEW_COMMAND_ID } from "./runtime-site-preview/PreviewSite";

Expand Down Expand Up @@ -190,13 +190,8 @@ export async function activate(

let copilotNotificationShown = false;

const workspaceFolders =
vscode.workspace.workspaceFolders?.map(
(fl) => ({ ...fl, uri: fl.uri.fsPath } as WorkspaceFolder)
) || [];

const workspaceFolders = getWorkspaceFolders();

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

vscode.commands.executeCommand("setContext", "microsoft.powerplatform.pages.siteRuntimePreviewEnabled", isSiteRuntimePreviewEnabled);
Expand Down Expand Up @@ -257,7 +252,7 @@ export async function activate(
}

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

})
Expand All @@ -282,17 +277,17 @@ export async function activate(

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

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

Expand Down
113 changes: 98 additions & 15 deletions src/client/runtime-site-preview/PreviewSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,47 @@ import { EnableSiteRuntimePreview } from '../../common/ecs-features/ecsFeatureGa
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 { PROVIDER_ID, 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';
import { getWorkspaceFolders, showProgressWithNotification } from '../../common/utilities/Utils';
import { PacTerminal } from '../lib/PacTerminal';
import { initializeOrgDetails } from '../../common/utilities/OrgHandlerUtils';
import { ArtemisService } from '../../common/services/ArtemisService';

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

export class PreviewSite {
private static _websiteUrl: string | undefined = undefined;

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

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

return enableSiteRuntimePreview;
return true;
}

static async loadSiteUrl(
workspaceFolders: WorkspaceFolder[],
stamp: ServiceEndpointCategory,
envId: string,
telemetry: ITelemetry)
: Promise<void> {
const websiteUrl = await PreviewSite.getWebSiteUrl(workspaceFolders, stamp, envId, telemetry);

this._websiteUrl = websiteUrl;
}

static async getWebSiteURL(workspaceFolders: WorkspaceFolder[], stamp: ServiceEndpointCategory, envId: string, telemetry: ITelemetry): Promise<string> {
static getSiteUrl(): string | undefined {
return this._websiteUrl;
}

private 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, {
Expand Down Expand Up @@ -64,14 +84,25 @@ export class PreviewSite {
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);
await showProgressWithNotification(
vscode.l10n.t('Opening site preview...'),
async () => {
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.launch');
await settings.update('defaultUrl', currentDefaultUrl);
}
);

await vscode.window.showInformationMessage(vscode.l10n.t('The preview shown is for published changes.'));
}

static async handlePreviewRequest(isSiteRuntimePreviewEnabled: boolean, websiteURL: string | undefined, telemetry: ITelemetry) {
static async handlePreviewRequest(
isSiteRuntimePreviewEnabled: boolean,
telemetry: ITelemetry,
pacTerminal: PacTerminal) {

telemetry.sendTelemetryEvent("StartCommand", {
commandId: SITE_PREVIEW_COMMAND_ID,
});
Expand All @@ -89,14 +120,66 @@ export class PreviewSite {
return;
}

if (!websiteURL || websiteURL === "") {
await vscode.window.showErrorMessage(vscode.l10n.t("Website URL not found."));
if (this._websiteUrl === undefined) {
await vscode.window.showWarningMessage(vscode.l10n.t("Initializing site preview. Please try again after few seconds."));
return;
}

await showProgressNotification(
vscode.l10n.t('Opening site preview...'),
async () => await PreviewSite.launchBrowserAndDevToolsWithinVsCode(websiteURL)
if (this._websiteUrl === "") {
let shouldRepeatLoginFlow = true;

while (shouldRepeatLoginFlow) {
shouldRepeatLoginFlow = await PreviewSite.handleEmptyWebsiteUrl(pacTerminal, telemetry);
}
}

await PreviewSite.launchBrowserAndDevToolsWithinVsCode(this._websiteUrl);
}

private static async handleEmptyWebsiteUrl(pacTerminal: PacTerminal, telemetry: ITelemetry): Promise<boolean> {
const shouldInitiateLogin = await vscode.window.showErrorMessage(
vscode.l10n.t(
`Website not found in the environment. Please check the credentials and login with correct account.`
),
vscode.l10n.t('Login'),
vscode.l10n.t('Cancel')
);

let shouldRepeatLoginFlow = false;

if (shouldInitiateLogin === vscode.l10n.t('Login')) {
await vscode.authentication.getSession(PROVIDER_ID, [], { forceNewSession: true, clearSessionPreference: true });

await showProgressWithNotification(
vscode.l10n.t('Initializing site preview'),
async (progress) => {
progress.report({ message: vscode.l10n.t('Getting org details...') });

const orgDetails = await initializeOrgDetails(false, pacTerminal.getWrapper());

progress.report({ message: vscode.l10n.t('Getting region information...') });
priyanshu92 marked this conversation as resolved.
Show resolved Hide resolved

const artemisResponse = await ArtemisService.getArtemisResponse(orgDetails.orgID, telemetry, "");

if (artemisResponse === null || artemisResponse.response === null) {
vscode.window.showErrorMessage(vscode.l10n.t("Failed to get website endpoint. Please try again later"));
return;
}

progress.report({ message: vscode.l10n.t('Getting website endpoint...') });

const websiteUrl = await PreviewSite.getWebSiteUrl(getWorkspaceFolders(), artemisResponse?.stamp, orgDetails.environmentID, telemetry);

if (websiteUrl === "") {
shouldRepeatLoginFlow = true;
}
else {
this._websiteUrl = websiteUrl;
}
}
);
}

return shouldRepeatLoginFlow;
}
}
19 changes: 0 additions & 19 deletions src/common/controls/ShowProgressNotification.ts

This file was deleted.

Loading
Loading