Skip to content

Commit 8c4b270

Browse files
authored
[Power Pages] Refactor PortalWebView to use new utility function (#1172)
* Refactor PortalWebView to use new utility function - 🔄 Replace `searchPortalConfigFolder` with `findWebsiteYmlFolder` for improved folder detection. - 🔧 Update logic to handle active text editor and reveal the panel correctly. - 📂 Simplify local resource root folder setup. -Priyanshu * Add error message for missing website root folder - ✏️ Added a new error message for when the website root folder cannot be located in the localization files. - 📜 Updated the XLF translation file to include the new message. -Priyanshu
1 parent 729a3cb commit 8c4b270

3 files changed

Lines changed: 29 additions & 14 deletions

File tree

l10n/bundle.l10n.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@
9696
"Do not translate 'PCF' as it is a product name."
9797
]
9898
},
99+
"Unable to locate website root folder.": "Unable to locate website root folder.",
99100
"File might be referenced by name {0} here./{0} represents the name of the file": {
100101
"message": "File might be referenced by name {0} here.",
101102
"comment": [

loc/translations-export/vscode-powerplatform.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,9 @@ The {3} represents Dataverse Environment's Organization ID (GUID)</note>
600600
<trans-unit id="++CODE++bab36b47fe2dd4f2f7e8eb486f2e3546e27dc047e69f5b24307bc71e5be2a7cf">
601601
<source xml:lang="en">Unable to find that app</source>
602602
</trans-unit>
603+
<trans-unit id="++CODE++3747890a3bfddec3123ce9a40cdd15f278d1335b382f80beb52bf18101ab02c2">
604+
<source xml:lang="en">Unable to locate website root folder.</source>
605+
</trans-unit>
603606
<trans-unit id="++CODE++b6038584b7b1f565be9c9d3f0ac11be70bd2e69e072ead52884ca7338a14ee67">
604607
<source xml:lang="en">Unique name: {0}</source>
605608
<note>{0} is the Unique name</note>

src/client/PortalWebView.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as vscode from "vscode";
77
import * as path from "path";
8-
import { searchPortalConfigFolder } from "../common/utilities/PathFinderUtil";
8+
import { findWebsiteYmlFolder } from "../common/utilities/WorkspaceInfoFinderUtil";
99

1010
/**
1111
* Displays Portal html webpage preview
@@ -35,25 +35,35 @@ export class PortalWebView {
3535
return;
3636
}
3737

38-
const column = vscode.window.activeTextEditor
39-
? vscode.window.activeTextEditor.viewColumn
40-
: undefined;
41-
4238
// If we already have a panel, show it.
4339
if (PortalWebView.currentPanel) {
40+
const column = vscode.window.activeTextEditor
41+
? vscode.window.activeTextEditor.viewColumn
42+
: undefined;
43+
4444
PortalWebView.currentPanel._update();
4545
PortalWebView.currentPanel._panel.reveal(column);
4646
return;
4747
}
4848

49+
if (!vscode.window.activeTextEditor) {
50+
return;
51+
}
52+
const repoRoot = PortalWebView.getPortalRootFolder();
53+
54+
if (!repoRoot) {
55+
vscode.window.showErrorMessage(vscode.l10n.t("Unable to locate website root folder."));
56+
return;
57+
}
58+
59+
const localResourceRootFolder = vscode.Uri.joinPath(repoRoot, "web-files");
60+
4961
const panel = vscode.window.createWebviewPanel(
5062
PortalWebView.viewType,
5163
"Portal Preview",
5264
vscode.ViewColumn.Two,
5365
{
54-
localResourceRoots: [
55-
vscode.Uri.joinPath(PortalWebView.getPortalRootFolder() as vscode.Uri, "web-files"),
56-
],
66+
localResourceRoots: [localResourceRootFolder]
5767
}
5868
);
5969

@@ -173,13 +183,14 @@ export class PortalWebView {
173183
private static getPortalRootFolder(): vscode.Uri | null {
174184
const fileBeingEdited = vscode.window.activeTextEditor as vscode.TextEditor;
175185
if (fileBeingEdited) {
176-
for (let i = 0; !!(vscode.workspace.workspaceFolders) && (i < vscode.workspace.workspaceFolders?.length); i++) {
177-
const portalConfigFolderUrl = searchPortalConfigFolder(vscode.workspace.workspaceFolders[i]?.uri?.toString(), fileBeingEdited?.document?.uri?.toString());
178-
if (portalConfigFolderUrl) {
179-
const portalRootFolder = path.dirname(portalConfigFolderUrl.href);
180-
return vscode.Uri.parse(portalRootFolder);
181-
}
186+
const repoRoot = findWebsiteYmlFolder(fileBeingEdited.document.uri.fsPath);
187+
188+
if (!repoRoot) {
189+
return null;
182190
}
191+
192+
const rootFolder = vscode.Uri.file(repoRoot);
193+
return rootFolder;
183194
}
184195
return null;
185196
}

0 commit comments

Comments
 (0)