Skip to content

Commit

Permalink
Web Extension: Remove dependency on website preview URL (#1091)
Browse files Browse the repository at this point in the history
* Web Extension: Remove dependency on website preview URL

* Translations
  • Loading branch information
priyanshu92 authored Jan 22, 2025
1 parent be918a4 commit cd4fb6d
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 33 deletions.
1 change: 0 additions & 1 deletion l10n/bundle.l10n.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"You are editing a live, public site ": "You are editing a live, public site ",
"Preview site": "Preview site",
"Open in Power Pages studio": "Open in Power Pages studio",
"Preview site URL is not available": "Preview site URL is not available",
"Preview site URL is not valid": "Preview site URL is not valid",
"Opening preview site...": "Opening preview site...",
"Power Pages studio URL is not available": "Power Pages studio URL is not available",
Expand Down
3 changes: 0 additions & 3 deletions loc/translations-export/vscode-powerplatform.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,6 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
<trans-unit id="++CODE++f6412ced721a26ac3e3cb55d3ff713d8403c3dfc2efa0cff07b48478bdd57555">
<source xml:lang="en">Preview site</source>
</trans-unit>
<trans-unit id="++CODE++f190e8061b8cbadd991ff217210525eff0000a8c6ddc2d44baec8388b7bd1a3e">
<source xml:lang="en">Preview site URL is not available</source>
</trans-unit>
<trans-unit id="++CODE++1cc20af81855b8570858ea1ac0491000d230bcf2ac53c1c1b30243a9b58a2036">
<source xml:lang="en">Preview site URL is not valid</source>
</trans-unit>
Expand Down
1 change: 0 additions & 1 deletion src/web/client/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export enum queryParameters {
ENV_ID = "envid",
GEO = "geo", // User geo location
ENABLE_MULTIFILE = "enablemultifile",
WEBSITE_PREVIEW_URL = "websitepreviewurl",
ENTITY = "entity",
ENTITY_ID = "entityid",
REFERRER_SOURCE = "referrersource",
Expand Down
21 changes: 11 additions & 10 deletions src/web/client/utilities/commonUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export function GetFileNameWithExtension(
}

export function isLanguageCodeNeededInFileName(entity: string) {
return entity === schemaEntityName.WEBPAGES ||entity === schemaEntityName.CONTENTSNIPPETS;
return entity === schemaEntityName.WEBPAGES || entity === schemaEntityName.CONTENTSNIPPETS;
}

export function isExtensionNeededInFileName(entity: string) {
Expand Down Expand Up @@ -310,32 +310,33 @@ export function getRangeForMultilineMatch(text: string, pattern: string, index:
return range;
}

export async function validateWebsitePreviewURL(): Promise<boolean> {
export async function getValidWebsitePreviewUrl(): Promise<{ websiteUrl: string, isValid: boolean }> {
const envId = getEnvironmentIdFromUrl();
const serviceEndpointStamp = WebExtensionContext.serviceEndpointCategory;
const websitePreviewId = WebExtensionContext.urlParametersMap?.get(queryParameters.PORTAL_ID);

if (serviceEndpointStamp === ServiceEndpointCategory.NONE || !envId || !websitePreviewId) {
WebExtensionContext.telemetry.sendErrorTelemetry(
webExtensionTelemetryEventNames.WEB_EXTENSION_WEBSITE_PREVIEW_URL_VALIDATION_INSUFFICIENT_PARAMETERS,
validateWebsitePreviewURL.name,
getValidWebsitePreviewUrl.name,
`serviceEndpointStamp:${serviceEndpointStamp}, envId:${envId}, websitePreviewId:${websitePreviewId}`
);
return false;
return { websiteUrl: '', isValid: false };
}

const siteDetails = await PPAPIService.getWebsiteDetailsById(serviceEndpointStamp, envId, websitePreviewId, WebExtensionContext.telemetry.getTelemetryReporter());

if (siteDetails == null) {
WebExtensionContext.telemetry.sendErrorTelemetry(
webExtensionTelemetryEventNames.WEB_EXTENSION_WEBSITE_PREVIEW_URL_VALIDATION_SITE_DETAILS_FETCH_FAILED,
validateWebsitePreviewURL.name,
getValidWebsitePreviewUrl.name,
);
return false;
return { websiteUrl: '', isValid: false };
}

return siteDetails.websiteUrl.length !== 0 &&
WebExtensionContext.urlParametersMap.get(queryParameters.WEBSITE_PREVIEW_URL) !== undefined &&
siteDetails.websiteUrl.toLocaleLowerCase().trim() === WebExtensionContext.urlParametersMap.get(queryParameters.WEBSITE_PREVIEW_URL)?.toLocaleLowerCase().trim();
}
if (siteDetails.websiteUrl.length !== 0) {
return { websiteUrl: siteDetails.websiteUrl, isValid: true };
}

return { websiteUrl: '', isValid: false };
}
25 changes: 7 additions & 18 deletions src/web/client/webViews/powerPagesNavigationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@
import * as vscode from 'vscode';
import * as path from 'path';
import WebExtensionContext from "../WebExtensionContext";
import { httpMethod, queryParameters } from '../common/constants';
import { getBackToStudioURL, isStringUndefinedOrEmpty, validateWebsitePreviewURL } from '../utilities/commonUtil';
import { httpMethod } from '../common/constants';
import { getBackToStudioURL, getValidWebsitePreviewUrl } from '../utilities/commonUtil';
import { webExtensionTelemetryEventNames } from '../../../common/OneDSLoggerTelemetry/web/client/webExtensionTelemetryEvents';

export class PowerPagesNavigationProvider implements vscode.TreeDataProvider<PowerPagesNode> {

private _onDidChangeTreeData: vscode.EventEmitter<PowerPagesNode | undefined | void> = new vscode.EventEmitter<PowerPagesNode | undefined | void>();
readonly onDidChangeTreeData: vscode.Event<PowerPagesNode | undefined | void> = this._onDidChangeTreeData.event;
private isWebsitePreviewURLValid: Promise<boolean> = validateWebsitePreviewURL();
private isWebsitePreviewURLValid: Promise<{ websiteUrl: string, isValid: boolean }> = getValidWebsitePreviewUrl();

refresh(): void {
this._onDidChangeTreeData.fire();
Expand Down Expand Up @@ -63,33 +63,22 @@ export class PowerPagesNavigationProvider implements vscode.TreeDataProvider<Pow

async previewPowerPageSite(): Promise<void> {
let requestSentAtTime = new Date().getTime();
const websitePreviewUrl = WebExtensionContext.urlParametersMap.get(queryParameters.WEBSITE_PREVIEW_URL) as string;

if (isStringUndefinedOrEmpty(websitePreviewUrl)) {
vscode.window.showErrorMessage(vscode.l10n.t("Preview site URL is not available"));
const { isValid, websiteUrl } = await this.isWebsitePreviewURLValid;

WebExtensionContext.telemetry.sendErrorTelemetry(
webExtensionTelemetryEventNames.WEB_EXTENSION_WEBSITE_PREVIEW_URL_UNAVAILABLE,
this.previewPowerPageSite.name,
`websitePreviewUrl:${websitePreviewUrl}`
);
return;
}

const isValid = await this.isWebsitePreviewURLValid;
if (!isValid) {
vscode.window.showErrorMessage(vscode.l10n.t("Preview site URL is not valid"));

WebExtensionContext.telemetry.sendErrorTelemetry(
webExtensionTelemetryEventNames.WEB_EXTENSION_WEBSITE_PREVIEW_URL_INVALID,
this.previewPowerPageSite.name,
`websitePreviewUrl:${websitePreviewUrl}`
`websitePreviewUrl:${websiteUrl}`
);
return;
}

// Runtime clear cache call
const requestUrl = `${websitePreviewUrl.endsWith('/') ? websitePreviewUrl : websitePreviewUrl.concat('/')}_services/cache/config`;
const requestUrl = `${websiteUrl.endsWith('/') ? websiteUrl : websiteUrl.concat('/')}_services/cache/config`;

WebExtensionContext.telemetry.sendAPITelemetry(
requestUrl,
Expand Down Expand Up @@ -141,7 +130,7 @@ export class PowerPagesNavigationProvider implements vscode.TreeDataProvider<Pow
}
);

vscode.env.openExternal(vscode.Uri.parse(websitePreviewUrl));
vscode.env.openExternal(vscode.Uri.parse(websiteUrl));
WebExtensionContext.telemetry.sendInfoTelemetry(webExtensionTelemetryEventNames.WEB_EXTENSION_PREVIEW_SITE_TRIGGERED);
}

Expand Down

0 comments on commit cd4fb6d

Please sign in to comment.