Skip to content

A plugin marketplace for GitHub Copilot and other AI agents that provides Power Platform development plugins, including reusable skills, agents, and commands for building and deploying solutions.

[Pages] Hide mobile preview without screenshots (#825)

Priyanshu Agrawal8821feed9140
diff --git a/plugins/power-pages/scripts/render-template-import-status.js b/plugins/power-pages/scripts/render-template-import-status.js
index 20fa757e0..8d0ae647f 100644
--- a/plugins/power-pages/scripts/render-template-import-status.js
+++ b/plugins/power-pages/scripts/render-template-import-status.js
@@ -80,19 +80,36 @@ function buildModel({ templateName, templateDescription, statusPath, outputPath,
const statusUrl = path.dirname(path.resolve(statusPath)) === path.dirname(path.resolve(outputPath))
? path.basename(statusPath)
: pathToFileURL(path.resolve(statusPath)).href;
- const previews = previewImages.map((image, index) => {
+ const previewGroups = new Map();
+ for (let index = 0; index < previewImages.length; index++) {
+ const image = previewImages[index];
const url = previewImageUrl(image, index, path.dirname(path.resolve(outputPath)));
- if (!url) return null;
+ if (!url) continue;
const sourcePath = /^(?:https?|file):\/\//i.test(image)
? decodeURIComponent(new URL(image).pathname)
: image;
- return {
- name: `preview-${index + 1}`,
- displayName: sourcePath.split(/[\\/]/).pop(),
- desktop: url,
- mobile: url,
- };
- }).filter(Boolean);
+ // `desktop-home.png` and `mobile-home.png` are device-specific captures of one
+ // page; unprefixed catalog images remain desktop previews for compatibility.
+ const filename = sourcePath.split(/[\\/]/).pop();
+ const deviceMatch = filename.match(/^(desktop|mobile)-(.+)$/i);
+ const displayName = deviceMatch ? deviceMatch[2] : filename;
+ const key = deviceMatch
+ ? `device:${path.parse(displayName).name.toLowerCase()}`
+ : `image:${index}`;
+ let preview = previewGroups.get(key);
+ if (!preview) {
+ preview = {
+ name: `preview-${previewGroups.size + 1}`,
+ displayName,
+ desktop: null,
+ mobile: null,
+ };
+ previewGroups.set(key, preview);
+ }
+ const device = deviceMatch ? deviceMatch[1].toLowerCase() : 'desktop';
+ preview[device] = url;
+ }
+ const previews = [...previewGroups.values()];
const pluralSolutions = solutionCount > 1;
const pluginRoot = path.resolve(__dirname, '..');
@@ -187,8 +204,9 @@ function renderTemplateImportStatus({
// remote preview origins, while retaining default-src 'none' and nonce scripts.
// https://www.w3.org/TR/CSP3/#directive-connect-src
const imageOrigins = [...new Set(model.template.previews
- .filter(({ desktop }) => /^https?:\/\//i.test(desktop))
- .map(({ desktop }) => new URL(desktop).origin))];
+ .flatMap(({ desktop, mobile }) => [desktop, mobile])
+ .filter((url) => /^https?:\/\//i.test(url))
+ .map((url) => new URL(url).origin))];
renderTemplate({
templatePath,
outputPath,
diff --git a/plugins/power-pages/scripts/tests/render-template-import-status.test.js b/plugins/power-pages/scripts/tests/render-template-import-status.test.js
index 9e0c17ccc..401bf64dc 100644
--- a/plugins/power-pages/scripts/tests/render-template-import-status.test.js
+++ b/plugins/power-pages/scripts/tests/render-template-import-status.test.js
@@ -196,6 +196,7 @@ test('buildModel uses an Open website result instead of automatic redirect metad
function runStatusPage(html, saved = {}) {
const elements = new Map();
+ const viewButtons = [];
function element(id) {
return {
dataset: {},
@@ -208,6 +209,13 @@ function runStatusPage(html, saved = {}) {
remove() { elements.delete(id); },
};
}
+ for (const [, view, text] of html.matchAll(/<button\b[^>]*\bdata-view="([^"]+)"[^>]*>([\s\S]*?)<\/button>/g)) {
+ const button = element(`view-${view}`);
+ button.dataset.view = view;
+ button.textContent = text;
+ elements.set(`view-${view}`, button);
+ viewButtons.push(button);
+ }
for (const [, id] of html.matchAll(/\bid="([^"]+)"/g)) elements.set(id, element(id));
let polls = 0;
const context = vm.createContext({
@@ -217,7 +225,7 @@ function runStatusPage(html, saved = {}) {
return elements.get(id);
},
createElement: () => element(),
- querySelectorAll: () => [],
+ querySelectorAll: (selector) => selector === '[data-view]' ? viewButtons : [],
},
location: { pathname: '/import.html' },
sessionStorage: {
@@ -318,10 +326,134 @@ test('SPA previews retain original filenames after localization and filtering',
assert.deepEqual(model.template.previews.map(({ displayName }) => displayName), [
'Home page.png', 'Service requests.png',
]);
+ assert.equal(model.template.previews[0].mobile, null);
assert.equal(model.template.previews[0].desktop, 'preview-images/preview-02.png');
assert.equal(model.template.description, 'Track requests and manage supplier accounts.');
});
+test('SPA previews show mobile only when mobile-prefixed screenshots are available', (t) => {
+ const dir = tempDir();
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ const outputPath = path.join(dir, 'import.html');
+ const pairedOutputPath = path.join(dir, 'paired.html');
+ const model = buildModel({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath,
+ previewImages: [
+ 'https://example.com/previews/desktop-home.png',
+ 'https://example.com/previews/mobile-home.png',
+ ],
+ solutionCount: 1,
+ });
+
+ assert.equal(model.template.previews.some(({ mobile }) => Boolean(mobile)), true);
+ assert.deepEqual(model.template.previews, [{
+ name: 'preview-1',
+ displayName: 'home.png',
+ desktop: 'https://example.com/previews/desktop-home.png',
+ mobile: 'https://example.com/previews/mobile-home.png',
+ }]);
+
+ const desktopOnly = buildModel({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath: path.join(dir, 'desktop-only.html'),
+ previewImages: ['https://example.com/previews/desktop-home.png'],
+ solutionCount: 1,
+ });
+ assert.equal(desktopOnly.template.previews.some(({ mobile }) => Boolean(mobile)), false);
+ assert.equal(desktopOnly.template.previews[0].mobile, null);
+
+ renderTemplateImportStatus({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath: pairedOutputPath,
+ previewImages: [
+ 'https://example.com/previews/desktop-home.png',
+ 'https://example.com/previews/mobile-home.png',
+ ],
+ solutionCount: 1,
+ });
+ const responsivePage = runStatusPage(fs.readFileSync(pairedOutputPath, 'utf8'));
+ const mobileButton = responsivePage.elements.get('view-mobile');
+ assert.equal(mobileButton.hidden, false);
+ mobileButton.listeners.click();
+ assert.equal(responsivePage.elements.get('previewImage').src, 'https://example.com/previews/mobile-home.png');
+
+ renderTemplateImportStatus({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath,
+ previewImages: ['https://example.com/previews/desktop-home.png'],
+ solutionCount: 1,
+ });
+ const page = runStatusPage(fs.readFileSync(outputPath, 'utf8'), { view: 'mobile' });
+ assert.equal(page.elements.get('view-mobile').hidden, true);
+ assert.equal(page.elements.get('previewImage').src, 'https://example.com/previews/desktop-home.png');
+
+ const emptyOutputPath = path.join(dir, 'empty.html');
+ renderTemplateImportStatus({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath: emptyOutputPath,
+ previewImages: [],
+ solutionCount: 1,
+ });
+ const emptyPage = runStatusPage(fs.readFileSync(emptyOutputPath, 'utf8'));
+ assert.equal(emptyPage.elements.get('previewViewControls').hidden, true);
+ assert.match(fs.readFileSync(emptyOutputPath, 'utf8'), /\.segmented\[hidden\]\s*\{\s*display:\s*none;\s*\}/);
+});
+
+test('unprefixed previews with the same basename remain separate', (t) => {
+ const dir = tempDir();
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ const model = buildModel({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath: path.join(dir, 'import.html'),
+ previewImages: [
+ 'https://example.com/overview/screenshot.png',
+ 'https://example.com/details/screenshot.png',
+ ],
+ solutionCount: 1,
+ });
+
+ assert.deepEqual(model.template.previews.map(({ displayName, desktop, mobile }) => ({
+ displayName, desktop, mobile,
+ })), [
+ {
+ displayName: 'screenshot.png',
+ desktop: 'https://example.com/overview/screenshot.png',
+ mobile: null,
+ },
+ {
+ displayName: 'screenshot.png',
+ desktop: 'https://example.com/details/screenshot.png',
+ mobile: null,
+ },
+ ]);
+});
+
+test('device previews pair by page name when image extensions differ', (t) => {
+ const dir = tempDir();
+ t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
+ const model = buildModel({
+ templateName: 'Supplier Portal',
+ statusPath: path.join(dir, 'status.json'),
+ outputPath: path.join(dir, 'import.html'),
+ previewImages: [
+ 'https://example.com/previews/desktop-home.png',
+ 'https://example.com/previews/mobile-home.jpg',
+ ],
+ solutionCount: 1,
+ });
+
+ assert.equal(model.template.previews.length, 1);
+ assert.equal(model.template.previews[0].desktop, 'https://example.com/previews/desktop-home.png');
+ assert.equal(model.template.previews[0].mobile, 'https://example.com/previews/mobile-home.jpg');
+});
+
test('SPA image policy allows only the supplied remote preview origins', (t) => {
const dir = tempDir();
t.after(() => fs.rmSync(dir, { recursive: true, force: true }));
@@ -330,11 +462,14 @@ test('SPA image policy allows only the supplied remote preview origins', (t) =>
templateName: 'Supplier Portal',
statusPath: path.join(dir, 'status.json'),
outputPath,
- previewImages: ['https://images.example.com/Home.png', 'https://images.example.com/Requests.png'],
+ previewImages: [
+ 'https://images.example.com/desktop-home.png',
+ 'https://mobile.example.com/mobile-home.png',
+ ],
});
const html = fs.readFileSync(outputPath, 'utf8');
const policy = html.match(/http-equiv="Content-Security-Policy" content="([^"]+)"/)[1]
.replace(/&#39;/g, "'");
- assert.match(policy, /img-src 'self' data: https:\/\/images\.example\.com;/);
+ assert.match(policy, /img-src 'self' data: https:\/\/images\.example\.com https:\/\/mobile\.example\.com;/);
assert.match(policy, /connect-src 'self';/);
});
diff --git a/plugins/power-pages/skills/create-site/SKILL.md b/plugins/power-pages/skills/create-site/SKILL.md
index 1cad00fc3..1c61306e6 100644
--- a/plugins/power-pages/skills/create-site/SKILL.md
+++ b/plugins/power-pages/skills/create-site/SKILL.md
@@ -448,6 +448,7 @@ Write the file with the `Write` tool (atomic overwrite). You do not need to read
node "${PLUGIN_ROOT}/scripts/open-url.js" --url "<url from <temp-import-status-dir>/url.txt>"
```
Reuse the already-downloaded local preview image URLs from the browser step; do not fetch preview images again for this page.
+ Name device-specific captures `desktop-<page>.<ext>` and `mobile-<page>.<ext>` so the status page can pair them. Unprefixed images count as desktop previews, and the Mobile control appears only when a mobile-prefixed image is present.
The server command returns only after the listener is ready. It removes the temporary status directory after a successful redirect, after the browser stops polling, or when the maximum lifetime expires.
7. Unless `SKIP_TEMPLATE_SOLUTION_IMPORT = true`, mark **Import template supporting solutions** as `in_progress`. Process `TEMPLATE_SOLUTIONS_TO_IMPORT` sequentially in its existing case-insensitive lexical unique-name order. For each entry, set `CURRENT_TEMPLATE_SOLUTION` and prepare its unmanaged solution for import:
```bash
diff --git a/plugins/power-pages/skills/create-site/assets/non-spa-creation-status-template.html b/plugins/power-pages/skills/create-site/assets/non-spa-creation-status-template.html
index ce73cea76..2a7fdeaae 100644
--- a/plugins/power-pages/skills/create-site/assets/non-spa-creation-status-template.html
+++ b/plugins/power-pages/skills/create-site/assets/non-spa-creation-status-template.html
@@ -234,6 +234,8 @@
background: var(--white);
}
+ .segmented[hidden] { display: none; }
+
.segmented button, .ghost {
border: 0;
border-radius: 8px;
@@ -584,7 +586,7 @@
</div>
<div class="slide-controls" id="slideControls" role="tablist" aria-label="Template page preview"></div>
<div class="preview-controls">
- <div class="segmented" role="group" aria-label="Preview size">
+ <div class="segmented" id="previewViewControls" role="group" aria-label="Preview size">
<button class="active" data-view="desktop" data-focus-key="view-desktop" aria-pressed="true">Desktop</button>
<button data-view="mobile" data-focus-key="view-mobile" aria-pressed="false">Mobile</button>
</div>
@@ -647,7 +649,8 @@
const model = __JSON_MODEL__;
const storageKey = `power-pages-create-site:${location.pathname}`;
const saved = JSON.parse(sessionStorage.getItem(storageKey) || "{}");
- let currentView = saved.view === "mobile" ? "mobile" : "desktop";
+ const hasMobilePreviews = model.template.previews.some((preview) => Boolean(preview.mobile));
+ let currentView = saved.view === "mobile" && hasMobilePreviews ? "mobile" : "desktop";
const allowRefreshPause = model.presentation?.allowRefreshPause !== false;
let autoRefreshPaused = allowRefreshPause && saved.autoRefreshPaused === true;
let refreshTimer;
@@ -673,9 +676,14 @@
if (!preview) {
document.getElementById("previewCard").hidden = true;
document.getElementById("slideControls").hidden = true;
+ document.getElementById("previewViewControls").hidden = true;
return;
}
+ document.getElementById("previewViewControls").hidden = false;
+ if (!preview[currentView]) {
+ currentView = preview.desktop ? "desktop" : "mobile";
+ }
const image = document.getElementById("previewImage");
image.src = preview[currentView];
image.alt = `${currentView} preview of ${model.template.displayName}: ${preview.displayName}`;
@@ -685,6 +693,8 @@
const selected = button.dataset.view === currentView;
button.classList.toggle("active", selected);
button.setAttribute("aria-pressed", String(selected));
+ button.hidden = button.dataset.view === "mobile" && !hasMobilePreviews;
+ button.disabled = !preview[button.dataset.view];
});
document.querySelectorAll("[data-slide]").forEach((button) => {
const selected = button.dataset.slide === currentSlide;