Skip to content

Commit

Permalink
localization added and moved preview site code to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrow1303 committed Nov 4, 2024
1 parent 0c54e48 commit 99bd698
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 29 deletions.
23 changes: 3 additions & 20 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,8 +239,8 @@ export async function activate(
copilotNotificationShown = true;

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

})
Expand All @@ -264,7 +264,7 @@ export async function activate(
}

const registerPreviewShowCommand = async () => {
const isEnabled = isSiteRuntimePreviewEnabled();
const isEnabled = PreviewSite.isSiteRuntimePreviewEnabled();

_telemetry.sendTelemetryEvent("EnableSiteRuntimePreview", {
isEnabled: isEnabled.toString(),
Expand Down Expand Up @@ -333,23 +333,6 @@ export async function deactivate(): Promise<void> {
disposeNotificationPanel();
}

async function getWebSiteURL(workspaceFolders: WorkspaceFolder[], stamp: ServiceEndpointCategory, envId: string, telemetry: ITelemetry): Promise<string> {

const websiteRecordId = getWebsiteRecordID(workspaceFolders, telemetry);
const websiteDetails = await PPAPIService.getWebsiteDetailsByWebsiteRecordId(stamp, envId, websiteRecordId, _telemetry);
return websiteDetails?.websiteUrl || "";
}

function isSiteRuntimePreviewEnabled() {
const enableSiteRuntimePreview = ECSFeaturesClient.getConfig(EnableSiteRuntimePreview).enableSiteRuntimePreview

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

return enableSiteRuntimePreview;
}

function didOpenTextDocument(document: vscode.TextDocument): void {
// The debug options for the server
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging
Expand Down
6 changes: 4 additions & 2 deletions src/client/runtimeSitePreview/LaunchJsonHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export async function updateLaunchJsonConfig(url: string): Promise<void> {

const workspaceFolders = vscode.workspace.workspaceFolders;
if (!workspaceFolders) {
vscode.window.showErrorMessage('No workspace folder is open.');
vscode.window.showErrorMessage(
vscode.l10n.t('No workspace folder is open.'));
return;
}

Expand Down Expand Up @@ -82,7 +83,8 @@ export async function updateLaunchJsonConfig(url: string): Promise<void> {
await vscode.workspace.fs.writeFile(launchJsonPath, Buffer.from(launchJsonContent, 'utf8'));
} catch (e) {
if(e instanceof Error) {
vscode.window.showErrorMessage(`Failed to update launch.json: ${e.message}`);
vscode.window.showErrorMessage(
vscode.l10n.t(`Failed to update launch.json: ${e.message}`));
}
}
}
27 changes: 26 additions & 1 deletion src/client/runtimeSitePreview/PreviewSite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,33 @@ import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import { updateLaunchJsonConfig } from './LaunchJsonHelper';
import { ECSFeaturesClient } from '../../common/ecs-features/ecsFeatureClient';
import { EnableSiteRuntimePreview } from '../../common/ecs-features/ecsFeatureGates';
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 { PPAPIService } from '../../common/services/PPAPIService';

export class PreviewSite {

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

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

return enableSiteRuntimePreview;
}

static async getWebSiteURL(workspaceFolders: WorkspaceFolder[], stamp: ServiceEndpointCategory, envId: string, telemetry: ITelemetry): Promise<string> {

const websiteRecordId = getWebsiteRecordID(workspaceFolders, telemetry);
const websiteDetails = await PPAPIService.getWebsiteDetailsByWebsiteRecordId(stamp, envId, websiteRecordId, telemetry);
return websiteDetails?.websiteUrl || "";
}

static async launchBrowserAndDevToolsWithinVsCode(webSitePreviewURL: string): Promise<void> {

const edgeToolsExtensionId = 'ms-edgedevtools.vscode-edge-devtools';
Expand Down Expand Up @@ -59,9 +83,10 @@ export class PreviewSite {
}
} else {
const install = await vscode.window.showWarningMessage(
vscode.l10n.t(
`The extension "${edgeToolsExtensionId}" is required to run this command. Do you want to install it now?`,
'Install', 'Cancel'
);
));

if (install === 'Install') {
// Open the Extensions view with the specific extension
Expand Down
1 change: 1 addition & 0 deletions src/common/OneDSLoggerTelemetry/telemetry/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const CleanupRelatedFilesEvent = 'CleanupRelatedFilesEvent';
export const UpdateEntityNameInYmlEvent = 'UpdateEntityNameInYmlEvent';
export const UserFileCreateEvent = 'UserFileCreateEvent';
export const FileCreateEvent = 'FileCreateEvent';
export const GetWebsiteRecordID = 'getWebsiteRecordID';

interface ITelemetryData {
eventName: string,
Expand Down
13 changes: 9 additions & 4 deletions src/common/services/PPAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import { ITelemetry } from "../OneDSLoggerTelemetry/telemetry/ITelemetry";
import { getCommonHeaders, powerPlatformAPIAuthentication } from "./AuthenticationProvider";
import { VSCODE_EXTENSION_GET_CROSS_GEO_DATA_MOVEMENT_ENABLED_FLAG_FAILED, VSCODE_EXTENSION_GET_PPAPI_WEBSITES_ENDPOINT_UNSUPPORTED_REGION, VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_ID_COMPLETED } from "./TelemetryConstants";
import { ServiceEndpointCategory, PPAPI_WEBSITES_ENDPOINT, PPAPI_WEBSITES_API_VERSION } from "./Constants";
import { VSCODE_EXTENSION_SERVICE_STAMP_NOT_FOUND, VSCODE_EXTENSION_GET_CROSS_GEO_DATA_MOVEMENT_ENABLED_FLAG_FAILED, VSCODE_EXTENSION_GET_PPAPI_WEBSITES_ENDPOINT_UNSUPPORTED_REGION,
VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_ID_COMPLETED, VSCODE_EXTENSION_PPAPI_GET_WEBSITE_DETAILS_FAILED, VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_RECORD_ID_COMPLETED } from "./TelemetryConstants";import { ServiceEndpointCategory, PPAPI_WEBSITES_ENDPOINT, PPAPI_WEBSITES_API_VERSION } from "./Constants";
import { sendTelemetryEvent } from "../copilot/telemetry/copilotTelemetry";
import { IWebsiteDetails } from "./Interfaces";

Expand Down Expand Up @@ -35,11 +35,16 @@ export class PPAPIService {

public static async getWebsiteDetailsByWebsiteRecordId(serviceEndpointStamp: ServiceEndpointCategory, environmentId: string, websiteRecordId: string, telemetry: ITelemetry): Promise<IWebsiteDetails | null> {

if (!serviceEndpointStamp) {
sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_SERVICE_STAMP_NOT_FOUND, data: serviceEndpointStamp });
return null;
}

const websiteDetailsArray = await PPAPIService.getWebsiteDetails(serviceEndpointStamp, environmentId, telemetry);
const websiteDetails = websiteDetailsArray?.find((website) => website.websiteRecordId === websiteRecordId);

if (websiteDetails) {
sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_ID_COMPLETED, orgUrl: websiteDetails.dataverseInstanceUrl });
sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_RECORD_ID_COMPLETED, orgUrl: websiteDetails.dataverseInstanceUrl });
return websiteDetails;
}
return null;
Expand All @@ -59,7 +64,7 @@ export class PPAPIService {
}
}
catch (error) {
sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_GET_CROSS_GEO_DATA_MOVEMENT_ENABLED_FLAG_FAILED, errorMsg: (error as Error).message });
sendTelemetryEvent(telemetry, { eventName: VSCODE_EXTENSION_PPAPI_GET_WEBSITE_DETAILS_FAILED, errorMsg: (error as Error).message });
}
return null;
}
Expand Down
3 changes: 3 additions & 0 deletions src/common/services/TelemetryConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,6 @@ export const VSCODE_EXTENSION_GET_PPAPI_WEBSITES_ENDPOINT_UNSUPPORTED_REGION = "
export const VSCODE_EXTENSION_DECODE_JWT_TOKEN_FAILED = "VSCodeExtensionDecodeJWTTokenFailed";
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_ID_COMPLETED = "VSCodeExtensionPPAPIGetWebsiteByIdCompleted";
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_ID_FAILED = "VSCodeExtensionPPAPIGetWebsiteByIdFailed";
export const VSCODE_EXTENSION_SERVICE_STAMP_NOT_FOUND = "VSCodeExtensionServiceStampNotFound";
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_DETAILS_FAILED = "VSCodeExtensionPPAPIGetWebsiteDetailsFailed";
export const VSCODE_EXTENSION_PPAPI_GET_WEBSITE_BY_RECORD_ID_COMPLETED = "VSCodeExtensionPPAPIGetWebsiteByRecordIdCompleted";
4 changes: 2 additions & 2 deletions src/common/utilities/WorkspaceInfoFinderUtil.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as path from 'path';
import * as fs from 'fs';
import { parse } from 'yaml';
import { ITelemetry } from '../OneDSLoggerTelemetry/telemetry/ITelemetry';
import { sendTelemetryEvent } from '../OneDSLoggerTelemetry/telemetry/telemetry';
import { GetWebsiteRecordID, sendTelemetryEvent } from '../OneDSLoggerTelemetry/telemetry/telemetry';

export function getPortalsOrgURLs(workspaceRootFolders: WorkspaceFolder[] | null, telemetry: ITelemetry) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -56,7 +56,7 @@ export function getWebsiteRecordID(workspaceFolders: { uri: string }[], telemetr
}
}
} catch (exception) {
sendTelemetryEvent(telemetry, { methodName: getWebsiteRecordID.name, eventName: 'getWebsiteRecordID', exception: exception as Error });
sendTelemetryEvent(telemetry, { methodName: getWebsiteRecordID.name, eventName: GetWebsiteRecordID, exception: exception as Error });
}
return "";
}

0 comments on commit 99bd698

Please sign in to comment.