Skip to content

Commit c535e69

Browse files
authored
Site Preview Enhancements: Clear cache and telemetry logging (#1088)
1 parent a82f277 commit c535e69

File tree

5 files changed

+85
-10
lines changed

5 files changed

+85
-10
lines changed

l10n/bundle.l10n.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@
111111
"Getting region information...": "Getting region information...",
112112
"Failed to get website endpoint. Please try again later": "Failed to get website endpoint. Please try again later",
113113
"Getting website endpoint...": "Getting website endpoint...",
114+
"Failed to get organization details. Please try again later": "Failed to get organization details. Please try again later",
115+
"Clearing cache...": "Clearing cache...",
116+
"Authenticating...": "Authenticating...",
117+
"Unable to clear cache": "Unable to clear cache",
114118
"File might be referenced by name {0} here./{0} represents the name of the file": {
115119
"message": "File might be referenced by name {0} here.",
116120
"comment": [

loc/translations-export/vscode-powerplatform.xlf

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@
4242
<source xml:lang="en">Are you sure you want to delete the Auth Profile {0}-{1}?</source>
4343
<note>{0} is the user name, {1} is the URL of environment of the auth profile</note>
4444
</trans-unit>
45+
<trans-unit id="++CODE++1f6087c22e8b59c12a5a95c61f5811ecd795e553b7a0d7f2e337e36dc26fe509">
46+
<source xml:lang="en">Authenticating...</source>
47+
</trans-unit>
4548
<trans-unit id="++CODE++4190475b52357e7ad3da76828784a5b9f291519e331b0c0e71f5d14e946bbc4b">
4649
<source xml:lang="en">Authentication failed. Please try again.</source>
4750
</trans-unit>
@@ -81,6 +84,9 @@
8184
<trans-unit id="++CODE++2c8d1f9ca282591926b952dc5949d44df6204f1f0a3f5183bcd5ef7ae5864bad">
8285
<source xml:lang="en">Choose web template</source>
8386
</trans-unit>
87+
<trans-unit id="++CODE++149fd22e94b05db4102d8eb8dc887a15388e66177b1e7d7b6634e5530b0998b0">
88+
<source xml:lang="en">Clearing cache...</source>
89+
</trans-unit>
8490
<trans-unit id="++CODE++eef726ad55117038c05eaa478148144884ab56cadc5a46785e8221040ff7a6ec">
8591
<source xml:lang="en">Cloud Instance: {0}</source>
8692
<note>The {0} represents profile's Azure Cloud Instances</note>
@@ -162,6 +168,9 @@ The {3} represents Solution's Type (Managed or Unmanaged), but that test is loca
162168
<trans-unit id="++CODE++862d6197d64601aa13ce30db5ec5b8f819ad00fe21e3b031a3e47fe22ef68fb3">
163169
<source xml:lang="en">Failed to get file ready for edit: {0}</source>
164170
</trans-unit>
171+
<trans-unit id="++CODE++78900eaa5444b623de50e2df5c46a35ee65a934a17bf9a1d619e275f1e6a529c">
172+
<source xml:lang="en">Failed to get organization details. Please try again later</source>
173+
</trans-unit>
165174
<trans-unit id="++CODE++51e1f5c5757cfd25a390293a7d8e9eb583943b66211fae1cbe25d07bfcb767f1">
166175
<source xml:lang="en">Failed to get website endpoint. Please try again later</source>
167176
</trans-unit>
@@ -461,6 +470,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
461470
<trans-unit id="++CODE++dabe9e12f081a01200dc7e96c5ae45a75ca20e6805dcf047778012f41ee33f31">
462471
<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>
463472
</trans-unit>
473+
<trans-unit id="++CODE++34077c1b18e274ca17c858b0521d9ff1edd6a164eccb2a24888fc6ed0eb3df35">
474+
<source xml:lang="en">Unable to clear cache</source>
475+
</trans-unit>
464476
<trans-unit id="++CODE++bd7b156375b48ce5797a3421150e6f5c3b71d3a30f823e957241589aea6236ca">
465477
<source xml:lang="en">Unable to complete the request</source>
466478
</trans-unit>

src/client/preview-site/Constants.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const Messages = {
99
LOGIN: vscode.l10n.t("Login"),
1010
CANCEL: vscode.l10n.t("Cancel"),
1111
INSTALL: vscode.l10n.t("Install"),
12-
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' "] }),
12+
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' "] }),
1313
OPENING_SITE_PREVIEW: vscode.l10n.t("Opening site preview..."),
1414
PREVIEW_SHOWN_FOR_PUBLISHED_CHANGES: vscode.l10n.t("The preview shown is for published changes."),
1515
SITE_PREVIEW_FEATURE_NOT_ENABLED: vscode.l10n.t("Site runtime preview feature is not enabled."),
@@ -20,5 +20,9 @@ export const Messages = {
2020
GETTING_ORG_DETAILS: vscode.l10n.t("Getting organization details..."),
2121
GETTING_REGION_INFORMATION: vscode.l10n.t("Getting region information..."),
2222
FAILED_TO_GET_ENDPOINT: vscode.l10n.t("Failed to get website endpoint. Please try again later"),
23-
GETTING_WEBSITE_ENDPOINT: vscode.l10n.t("Getting website endpoint...")
23+
GETTING_WEBSITE_ENDPOINT: vscode.l10n.t("Getting website endpoint..."),
24+
ORG_DETAILS_ERROR: vscode.l10n.t("Failed to get organization details. Please try again later"),
25+
CLEARING_CACHE: vscode.l10n.t("Clearing cache..."),
26+
AUTHENTICATING: vscode.l10n.t("Authenticating..."),
27+
UNABLE_TO_CLEAR_CACHE: vscode.l10n.t("Unable to clear cache"),
2428
};

src/client/preview-site/PreviewSite.ts

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ import { WorkspaceFolder } from 'vscode-languageclient/node';
1111
import { getWebsiteRecordId } from '../../common/utilities/WorkspaceInfoFinderUtil';
1212
import { PROVIDER_ID, ServiceEndpointCategory } from '../../common/services/Constants';
1313
import { PPAPIService } from '../../common/services/PPAPIService';
14-
import { VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY } from '../../common/services/TelemetryConstants';
14+
import { VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY, VSCODE_EXTENSION_SITE_PREVIEW_ERROR } from '../../common/services/TelemetryConstants';
1515
import { EDGE_TOOLS_EXTENSION_ID } from '../../common/constants';
1616
import { oneDSLoggerWrapper } from "../../common/OneDSLoggerTelemetry/oneDSLoggerWrapper";
1717
import { getWorkspaceFolders, showProgressWithNotification } from '../../common/utilities/Utils';
1818
import { PacTerminal } from '../lib/PacTerminal';
1919
import { initializeOrgDetails } from '../../common/utilities/OrgHandlerUtils';
2020
import { ArtemisService } from '../../common/services/ArtemisService';
2121
import { Messages } from './Constants';
22+
import { dataverseAuthentication } from '../../common/services/AuthenticationProvider';
23+
import { IOrgDetails } from '../../common/chat-participants/powerpages/PowerPagesChatParticipantTypes';
2224

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

@@ -32,7 +34,7 @@ export class PreviewSite {
3234
return false;
3335
}
3436

35-
return true;
37+
return enableSiteRuntimePreview;
3638
}
3739

3840
static async loadSiteUrl(
@@ -112,32 +114,88 @@ export class PreviewSite {
112114
});
113115

114116
if (!isSiteRuntimePreviewEnabled) {
117+
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED });
118+
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED });
115119
await vscode.window.showInformationMessage(Messages.SITE_PREVIEW_FEATURE_NOT_ENABLED);
116120
return;
117121
}
118122

119123
if (!vscode.workspace.workspaceFolders) {
124+
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.NO_FOLDER_OPENED });
125+
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.NO_FOLDER_OPENED });
120126
await vscode.window.showErrorMessage(Messages.NO_FOLDER_OPENED);
121127
return;
122128
}
123129

124130
if (this._websiteUrl === undefined) {
131+
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.INITIALIZING_PREVIEW_TRY_AGAIN });
132+
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.INITIALIZING_PREVIEW_TRY_AGAIN });
125133
await vscode.window.showWarningMessage(Messages.INITIALIZING_PREVIEW_TRY_AGAIN);
126134
return;
127135
}
128136

137+
let orgDetails: IOrgDetails | undefined = undefined;
138+
await showProgressWithNotification(
139+
Messages.INITIALIZING_PREVIEW,
140+
async (progress) => {
141+
progress.report({ message: Messages.GETTING_ORG_DETAILS });
142+
143+
orgDetails = await initializeOrgDetails(false, pacTerminal.getWrapper());
144+
});
145+
146+
if (!orgDetails) {
147+
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.ORG_DETAILS_ERROR });
148+
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.ORG_DETAILS_ERROR });
149+
await vscode.window.showWarningMessage(Messages.ORG_DETAILS_ERROR);
150+
return;
151+
}
152+
129153
if (this._websiteUrl === "") {
130154
let shouldRepeatLoginFlow = true;
131155

132156
while (shouldRepeatLoginFlow) {
133-
shouldRepeatLoginFlow = await PreviewSite.handleEmptyWebsiteUrl(pacTerminal, telemetry);
157+
shouldRepeatLoginFlow = await PreviewSite.handleEmptyWebsiteUrl(orgDetails, telemetry);
134158
}
135159
}
136160

161+
await PreviewSite.clearCache(telemetry, orgDetails);
162+
137163
await PreviewSite.launchBrowserAndDevToolsWithinVsCode(this._websiteUrl);
138164
}
139165

140-
private static async handleEmptyWebsiteUrl(pacTerminal: PacTerminal, telemetry: ITelemetry): Promise<boolean> {
166+
private static async clearCache(telemetry: ITelemetry, orgDetails: IOrgDetails): Promise<void> {
167+
if (!this._websiteUrl) {
168+
return;
169+
}
170+
171+
const requestUrl = `${this._websiteUrl.endsWith('/') ? this._websiteUrl : this._websiteUrl.concat('/')}_services/cache/config`;
172+
173+
await showProgressWithNotification(
174+
Messages.INITIALIZING_PREVIEW,
175+
async (progress) => {
176+
progress.report({ message: Messages.CLEARING_CACHE });
177+
178+
const authResponse = await dataverseAuthentication(telemetry, orgDetails.orgUrl);
179+
180+
const clearCacheResponse = await fetch(requestUrl, {
181+
headers: {
182+
authorization: "Bearer " + authResponse.accessToken,
183+
'Accept': '*/*',
184+
'Content-Type': 'text/plain',
185+
},
186+
method: 'DELETE'
187+
});
188+
189+
if (!clearCacheResponse.ok) {
190+
telemetry.sendTelemetryErrorEvent(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.UNABLE_TO_CLEAR_CACHE, response: await clearCacheResponse.json(), statusCode: clearCacheResponse.status.toString() });
191+
oneDSLoggerWrapper.getLogger().traceInfo(VSCODE_EXTENSION_SITE_PREVIEW_ERROR, { error: Messages.UNABLE_TO_CLEAR_CACHE, response: await clearCacheResponse.json(), statusCode: clearCacheResponse.status.toString() });
192+
}
193+
}
194+
);
195+
196+
}
197+
198+
private static async handleEmptyWebsiteUrl(orgDetails: IOrgDetails, telemetry: ITelemetry): Promise<boolean> {
141199
const shouldInitiateLogin = await vscode.window.showErrorMessage(
142200
Messages.WEBSITE_NOT_FOUND_IN_ENVIRONMENT,
143201
Messages.LOGIN,
@@ -152,10 +210,6 @@ export class PreviewSite {
152210
await showProgressWithNotification(
153211
Messages.INITIALIZING_PREVIEW,
154212
async (progress) => {
155-
progress.report({ message: Messages.GETTING_ORG_DETAILS });
156-
157-
const orgDetails = await initializeOrgDetails(false, pacTerminal.getWrapper());
158-
159213
progress.report({ message: Messages.GETTING_REGION_INFORMATION });
160214

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

src/common/services/TelemetryConstants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,4 @@ export const VSCODE_EXTENSION_SERVICE_STAMP_NOT_FOUND = "VSCodeExtensionServiceS
3030
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_DETAILS_FAILED = "VSCodeExtensionPPAPIGetWebsiteDetailsFailed";
3131
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_RECORD_ID_COMPLETED = "VSCodeExtensionPPAPIGetWebsiteByRecordIdCompleted";
3232
export const VSCODE_EXTENSION_GET_WEBSITE_RECORD_ID_EMPTY = "VSCodeExtensionGetWebsiteRecordIdEmpty";
33+
export const VSCODE_EXTENSION_SITE_PREVIEW_ERROR = "VSCodeExtensionSitePreviewError";

0 commit comments

Comments
 (0)