Skip to content

Commit

Permalink
Site Preview Enhancements: Clear cache and telemetry logging (#1088)
Browse files Browse the repository at this point in the history
  • Loading branch information
priyanshu92 authored Jan 21, 2025
1 parent a82f277 commit c535e69
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 10 deletions.
4 changes: 4 additions & 0 deletions l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@
"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...",
"Failed to get organization details. Please try again later": "Failed to get organization details. Please try again later",
"Clearing cache...": "Clearing cache...",
"Authenticating...": "Authenticating...",
"Unable to clear cache": "Unable to clear cache",
"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
12 changes: 12 additions & 0 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
<source xml:lang="en">Are you sure you want to delete the Auth Profile {0}-{1}?</source>
<note>{0} is the user name, {1} is the URL of environment of the auth profile</note>
</trans-unit>
<trans-unit id="++CODE++1f6087c22e8b59c12a5a95c61f5811ecd795e553b7a0d7f2e337e36dc26fe509">
<source xml:lang="en">Authenticating...</source>
</trans-unit>
<trans-unit id="++CODE++4190475b52357e7ad3da76828784a5b9f291519e331b0c0e71f5d14e946bbc4b">
<source xml:lang="en">Authentication failed. Please try again.</source>
</trans-unit>
Expand Down Expand Up @@ -81,6 +84,9 @@
<trans-unit id="++CODE++2c8d1f9ca282591926b952dc5949d44df6204f1f0a3f5183bcd5ef7ae5864bad">
<source xml:lang="en">Choose web template</source>
</trans-unit>
<trans-unit id="++CODE++149fd22e94b05db4102d8eb8dc887a15388e66177b1e7d7b6634e5530b0998b0">
<source xml:lang="en">Clearing cache...</source>
</trans-unit>
<trans-unit id="++CODE++eef726ad55117038c05eaa478148144884ab56cadc5a46785e8221040ff7a6ec">
<source xml:lang="en">Cloud Instance: {0}</source>
<note>The {0} represents profile's Azure Cloud Instances</note>
Expand Down Expand Up @@ -162,6 +168,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++78900eaa5444b623de50e2df5c46a35ee65a934a17bf9a1d619e275f1e6a529c">
<source xml:lang="en">Failed to get organization details. Please try again later</source>
</trans-unit>
<trans-unit id="++CODE++51e1f5c5757cfd25a390293a7d8e9eb583943b66211fae1cbe25d07bfcb767f1">
<source xml:lang="en">Failed to get website endpoint. Please try again later</source>
</trans-unit>
Expand Down Expand Up @@ -461,6 +470,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++dabe9e12f081a01200dc7e96c5ae45a75ca20e6805dcf047778012f41ee33f31">
<source xml:lang="en">Try and be as specific as possible. Your feedback will be used to improve Copilot. &lt;a href=&quot;https://privacy.microsoft.com/en-US/data-privacy-notice&quot;&gt; View privacy details &lt;/a&gt;</source>
</trans-unit>
<trans-unit id="++CODE++34077c1b18e274ca17c858b0521d9ff1edd6a164eccb2a24888fc6ed0eb3df35">
<source xml:lang="en">Unable to clear cache</source>
</trans-unit>
<trans-unit id="++CODE++bd7b156375b48ce5797a3421150e6f5c3b71d3a30f823e957241589aea6236ca">
<source xml:lang="en">Unable to complete the request</source>
</trans-unit>
Expand Down
8 changes: 6 additions & 2 deletions src/client/preview-site/Constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const Messages = {
LOGIN: vscode.l10n.t("Login"),
CANCEL: vscode.l10n.t("Cancel"),
INSTALL: vscode.l10n.t("Install"),
EDGE_DEV_TOOLS_NOT_INSTALLED_MESSAGE: vscode.l10n.t({ message: "The extension 'Microsoft Edge Tools' is required to run this command. Do you want to install it now?", comment:["Do not translate 'Microsoft Edge Tools' "] }),
EDGE_DEV_TOOLS_NOT_INSTALLED_MESSAGE: vscode.l10n.t({ message: "The extension 'Microsoft Edge Tools' is required to run this command. Do you want to install it now?", comment: ["Do not translate 'Microsoft Edge Tools' "] }),
OPENING_SITE_PREVIEW: vscode.l10n.t("Opening site preview..."),
PREVIEW_SHOWN_FOR_PUBLISHED_CHANGES: vscode.l10n.t("The preview shown is for published changes."),
SITE_PREVIEW_FEATURE_NOT_ENABLED: vscode.l10n.t("Site runtime preview feature is not enabled."),
Expand All @@ -20,5 +20,9 @@ export const Messages = {
GETTING_ORG_DETAILS: vscode.l10n.t("Getting organization details..."),
GETTING_REGION_INFORMATION: vscode.l10n.t("Getting region information..."),
FAILED_TO_GET_ENDPOINT: vscode.l10n.t("Failed to get website endpoint. Please try again later"),
GETTING_WEBSITE_ENDPOINT: vscode.l10n.t("Getting website endpoint...")
GETTING_WEBSITE_ENDPOINT: vscode.l10n.t("Getting website endpoint..."),
ORG_DETAILS_ERROR: vscode.l10n.t("Failed to get organization details. Please try again later"),
CLEARING_CACHE: vscode.l10n.t("Clearing cache..."),
AUTHENTICATING: vscode.l10n.t("Authenticating..."),
UNABLE_TO_CLEAR_CACHE: vscode.l10n.t("Unable to clear cache"),
};
70 changes: 62 additions & 8 deletions src/client/preview-site/PreviewSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ import { WorkspaceFolder } from 'vscode-languageclient/node';
import { getWebsiteRecordId } from '../../common/utilities/WorkspaceInfoFinderUtil';
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 { VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY, VSCODE_EXTENSION_SITE_PREVIEW_ERROR } from '../../common/services/TelemetryConstants';
import { EDGE_TOOLS_EXTENSION_ID } from '../../common/constants';
import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper";
import { getWorkspaceFolders, showProgressWithNotification } from '../../common/utilities/Utils';
import { PacTerminal } from '../lib/PacTerminal';
import { initializeOrgDetails } from '../../common/utilities/OrgHandlerUtils';
import { ArtemisService } from '../../common/services/ArtemisService';
import { Messages } from './Constants';
import { dataverseAuthentication } from '../../common/services/AuthenticationProvider';
import { IOrgDetails } from '../../common/chat-participants/powerpages/PowerPagesChatParticipantTypes';

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

Expand All @@ -32,7 +34,7 @@ export class PreviewSite {
return false;
}

return true;
return enableSiteRuntimePreview;
}

static async loadSiteUrl(
Expand Down Expand Up @@ -112,32 +114,88 @@ export class PreviewSite {
});

if (!isSiteRuntimePreviewEnabled) {
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED });
await vscode.window.showInformationMessage(Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED);
return;
}

if (!vscode.workspace.workspaceFolders) {
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.NO_FOLDER_OPENED });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.NO_FOLDER_OPENED });
await vscode.window.showErrorMessage(Messages.NO_FOLDER_OPENED);
return;
}

if (this._websiteUrl === undefined) {
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.INITIALIZING_PREVIEW_TRY_AGAIN });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.INITIALIZING_PREVIEW_TRY_AGAIN });
await vscode.window.showWarningMessage(Messages.INITIALIZING_PREVIEW_TRY_AGAIN);
return;
}

let orgDetails: IOrgDetails | undefined = undefined;
await showProgressWithNotification(
Messages.INITIALIZING_PREVIEW,
async (progress) => {
progress.report({ message: Messages.GETTING_ORG_DETAILS });

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

if (!orgDetails) {
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.ORG_DETAILS_ERROR });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.ORG_DETAILS_ERROR });
await vscode.window.showWarningMessage(Messages.ORG_DETAILS_ERROR);
return;
}

if (this._websiteUrl === "") {
let shouldRepeatLoginFlow = true;

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

await PreviewSite.clearCache(telemetry, orgDetails);

await PreviewSite.launchBrowserAndDevToolsWithinVsCode(this._websiteUrl);
}

private static async handleEmptyWebsiteUrl(pacTerminal: PacTerminal, telemetry: ITelemetry): Promise<boolean> {
private static async clearCache(telemetry: ITelemetry, orgDetails: IOrgDetails): Promise<void> {
if (!this._websiteUrl) {
return;
}

const requestUrl = `${this._websiteUrl.endsWith('/') ? this._websiteUrl : this._websiteUrl.concat('/')}_services/cache/config`;

await showProgressWithNotification(
Messages.INITIALIZING_PREVIEW,
async (progress) => {
progress.report({ message: Messages.CLEARING_CACHE });

const authResponse = await dataverseAuthentication(telemetry, orgDetails.orgUrl);

const clearCacheResponse = await fetch(requestUrl, {
headers: {
authorization: "Bearer " + authResponse.accessToken,
'Accept': '*/*',
'Content-Type': 'text/plain',
},
method: 'DELETE'
});

if (!clearCacheResponse.ok) {
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.UNABLE_TO_CLEAR_CACHE, response: await clearCacheResponse.json(), statusCode: clearCacheResponse.status.toString() });
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.UNABLE_TO_CLEAR_CACHE, response: await clearCacheResponse.json(), statusCode: clearCacheResponse.status.toString() });
}
}
);

}

private static async handleEmptyWebsiteUrl(orgDetails: IOrgDetails, telemetry: ITelemetry): Promise<boolean> {
const shouldInitiateLogin = await vscode.window.showErrorMessage(
Messages.WEBSITE_NOT_FOUND_IN_ENVIRONMENT,
Messages.LOGIN,
Expand All @@ -152,10 +210,6 @@ export class PreviewSite {
await showProgressWithNotification(
Messages.INITIALIZING_PREVIEW,
async (progress) => {
progress.report({ message: Messages.GETTING_ORG_DETAILS });

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

progress.report({ message: Messages.GETTING_REGION_INFORMATION });

const artemisResponse = await ArtemisService.getArtemisResponse(orgDetails.orgID, telemetry, "");
Expand Down
1 change: 1 addition & 0 deletions src/common/services/TelemetryConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,4 @@ export const VSCODE_EXTENSION_SERVICE_STAMP_NOT_FOUND = "VSCodeExtensionServiceS
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_DETAILS_FAILED = "VSCodeExtensionPPAPIGetWebsiteDetailsFailed";
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_RECORD_ID_COMPLETED = "VSCodeExtensionPPAPIGetWebsiteByRecordIdCompleted";
export const VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY = "VSCodeExtensionGetWebsiteRecordIdEmpty";
export const VSCODE_EXTENSION_SITE_PREVIEW_ERROR = "VSCodeExtensionSitePreviewError";

0 comments on commit c535e69

Please sign in to comment.