fix(web): preview artifact images on primary click
This commit is contained in:
@@ -8,6 +8,21 @@ test, or a code change without a capture, is `partial` at best.
|
||||
|
||||
Status legend: `todo` · `partial` (some of it works) · `done` (working + captured).
|
||||
|
||||
### Image artifact primary preview (2026-10-21)
|
||||
|
||||
Image thumbnails and image list rows now open the existing in-app viewer. The
|
||||
former eye action is replaced by an external-arrow **Open in browser** action,
|
||||
which does not also activate the viewer. This applies to both the run gallery
|
||||
and individual visit artifacts; other file types retain their current actions.
|
||||
The viewer's own Open in browser, Copy and navigation actions remain unchanged.
|
||||
|
||||
`test/artifact-browser-probe.mjs` verifies gallery/list/visit clicks, keyboard
|
||||
activation and return focus, preview without a new tab, actual browser-tab opening
|
||||
from the external image action, and installed-Android intent routing without
|
||||
double activation. Captures at 390/420/1100px are under the approved OpenCode
|
||||
temporary `image-primary-preview-captures/`. Android OS hand-off is not tested.
|
||||
This supersedes prior external-primary image behavior; shell cache is v15.
|
||||
|
||||
### Chat metrics behind Info (2026-10-21)
|
||||
|
||||
The four usage/performance values now live in an explicit **Chat information**
|
||||
|
||||
@@ -1235,10 +1235,12 @@ function renderArtifactListRow(artifact, viewable, viewerIndexOf) {
|
||||
open.append(h("span", { class: "artifact-kind", text: artifactKindLabel(kind) }));
|
||||
open.append(h("span", { class: "artifact-list-name", text: name }));
|
||||
open.append(h("span", { class: "artifact-size", text: humanBytes(artifact.size_bytes) }));
|
||||
open.addEventListener("click", () => openArtifactInBrowser(resolved));
|
||||
const at = viewerIndexOf.get(artifact.url);
|
||||
const previewImage = kind === ArtifactKind.Image && at != null;
|
||||
open.addEventListener("click", () => previewImage
|
||||
? openArtifactViewer(viewable, at, open) : openArtifactInBrowser(resolved));
|
||||
wrap.append(open, renderTileActions(resolved, media, opensViewer && at != null
|
||||
? (trigger) => openArtifactViewer(viewable, at, trigger) : null, name));
|
||||
? (trigger) => openArtifactViewer(viewable, at, trigger) : null, name, previewImage));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
@@ -1316,7 +1318,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
const img = h("img", { class: "artifact-thumb", alt: name, loading: "lazy" });
|
||||
if (resolved) img.src = resolved;
|
||||
tile.append(img);
|
||||
tile.addEventListener("click", openTab);
|
||||
tile.addEventListener("click", () => openViewer(tile));
|
||||
} else if (kind === ArtifactKind.Video) {
|
||||
tile.append(
|
||||
h(
|
||||
@@ -1339,18 +1341,22 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
|
||||
);
|
||||
tile.addEventListener("click", openTab);
|
||||
}
|
||||
wrap.append(tile, renderTileActions(resolved, media, opensViewer ? openViewer : null, name));
|
||||
wrap.append(tile, renderTileActions(resolved, media, opensViewer ? openViewer : null, name, kind === ArtifactKind.Image));
|
||||
return wrap;
|
||||
}
|
||||
|
||||
/** The compact per-tile actions: icon-only link/share, shown on hover or focus. */
|
||||
function renderTileActions(resolved, media, preview = null, name = "artifact") {
|
||||
function renderTileActions(resolved, media, preview = null, name = "artifact", previewImage = false) {
|
||||
const actions = h("div", { class: "artifact-actions" });
|
||||
const stop = (fn) => (event) => {
|
||||
event.stopPropagation();
|
||||
fn(event.currentTarget);
|
||||
};
|
||||
if (preview) actions.append(artifactAction("preview", `Preview in app: ${name}`, !resolved, stop(preview)));
|
||||
if (previewImage) {
|
||||
actions.append(artifactAction("external", `Open in browser: ${name}`, !resolved, stop(() => openArtifactInBrowser(resolved))));
|
||||
} else if (preview) {
|
||||
actions.append(artifactAction("preview", `Preview in app: ${name}`, !resolved, stop(preview)));
|
||||
}
|
||||
if (!media) {
|
||||
actions.append(
|
||||
artifactAction("link", "Copy link", !resolved || !canCopyLink(), stop(() => copyArtifactLink(resolved))),
|
||||
@@ -1379,7 +1385,9 @@ function artifactAction(kind, label, disabled, onclick) {
|
||||
svg.setAttribute("aria-hidden", "true");
|
||||
svg.setAttribute("focusable", "false");
|
||||
const path = document.createElementNS(ARTIFACT_SVG_NS, "path");
|
||||
path.setAttribute("d", kind === "preview"
|
||||
path.setAttribute("d", kind === "external"
|
||||
? "M14 3h7v7M21 3 10 14M10 3H5a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-5"
|
||||
: kind === "preview"
|
||||
? "M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7S2 12 2 12ZM15 12a3 3 0 1 1-6 0a3 3 0 0 1 6 0Z"
|
||||
: kind === "link"
|
||||
? "M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// A shell cache for an installed Pipelines app. The API (the WebSocket proxy and
|
||||
// artifact files) is never cached; static files prefer the network and fall back
|
||||
// to the last good copy so an installed app still opens when the server is away.
|
||||
const CACHE = "pipelines-shell-v14";
|
||||
const CACHE = "pipelines-shell-v15";
|
||||
const SHELL = ["/", "/index.html", "/manifest.webmanifest", "/favicon.svg"];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
|
||||
@@ -37,6 +37,7 @@ document.addEventListener('click',e=>{const link=e.target.closest('a');if(link?.
|
||||
Object.defineProperty(navigator,'clipboard',{configurable:true,value:{writeText:async text=>copied.push(text)}});
|
||||
window.ready=true;
|
||||
window.showList=()=>{state.artifactView='list';const list=document.createElement('section');list.id='listFixture';list.append(rt.views.runDetail.renderArtifactGallery([step]));host.append(list);};
|
||||
window.showVisit=()=>{const visit=document.createElement('section');visit.id='visitFixture';visit.append(rt.views.runDetail.renderVisitArtifacts(step));host.append(visit);};
|
||||
window.showSearch=()=>{const target=document.createElement('div');document.body.append(target);Object.assign(state,{searchQuery:'',searchKind:'',searchSort:'relevance',searchResults:[],searchSequencer:new SearchSequencer(),searchActiveIndex:0});const search=createSearchView({...rt,searchHost:target,renderHeader:()=>{},repo:{search:async()=>({results:[{kind:'artifact',target:documentFile.url,artifact:{...documentFile,run_id:18,sequence:1}}]})}});search.openSearch();};
|
||||
</script>`;
|
||||
|
||||
@@ -72,6 +73,17 @@ try {
|
||||
assert.equal(await page.evaluate("location.href"), appURL);
|
||||
assert.equal(await page.evaluate("history.length"), historyLength);
|
||||
await page.screenshot(resolve(out, "01-app-preserved-after-browser-open.png"));
|
||||
const targets=()=>fetch(`http://127.0.0.1:${browser.port}/json/list`).then(r=>r.json());
|
||||
const targetCount=(await targets()).length;
|
||||
await page.click('[data-artifact-name="public/pixel.png"]');
|
||||
await page.waitForSelector('.artifact-viewer');
|
||||
assert.equal((await targets()).length,targetCount,'image preview must not create a browser tab');
|
||||
await page.screenshot(resolve(out,'01-image-preview-normal-browser.png'));
|
||||
await page.pressKey('Escape');
|
||||
await page.click('[aria-label="Open in browser: public/pixel.png"]');
|
||||
await eventually(async()=>(await targets()).some(t=>t.url===origin+'/artifacts/18/1/public/pixel.png'));
|
||||
assert.equal(await page.evaluate('location.href'),appURL);
|
||||
assert.equal(await page.evaluate("!!document.querySelector('.artifact-viewer')"),false);
|
||||
|
||||
const android = await browser.openPage("about:blank");
|
||||
await android.emulateTouch(true);
|
||||
@@ -93,7 +105,14 @@ try {
|
||||
assert.equal(await android.evaluate("handoffs.length"), 4, "Markdown Open must request the browser too");
|
||||
assert.equal(await android.evaluate("!!document.querySelector('.artifact-viewer')"), false);
|
||||
await android.click('[data-artifact-name="public/pixel.png"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 5, "images must not unexpectedly open inside the installed app");
|
||||
await android.waitForSelector('.artifact-viewer');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 4, "image clicks preview without external navigation");
|
||||
await android.screenshot(resolve(out, '03-image-preview-mobile.png'));
|
||||
await android.pressKey('Escape');
|
||||
assert.equal(await android.evaluate("document.activeElement.dataset.artifactName"), 'public/pixel.png');
|
||||
await android.click('[aria-label="Open in browser: public/pixel.png"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 5, "the external icon hands the image to the browser");
|
||||
assert.equal(await android.evaluate("!!document.querySelector('.artifact-viewer')"), false, "the external action must not also open the viewer");
|
||||
await android.click('[aria-label="Preview in app: public/evidence.md"]');
|
||||
await android.waitForSelector('.viewer-markdown');
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
@@ -115,13 +134,33 @@ try {
|
||||
await android.evaluate('showList()');
|
||||
await android.click('#listFixture .artifact-list-open[aria-label="Open public/evidence.md"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 7);
|
||||
await android.click('#listFixture .artifact-list-open[aria-label="Open public/pixel.png"]');
|
||||
await android.waitForSelector('.artifact-viewer');
|
||||
assert.equal(await android.evaluate("handoffs.length"),7,'image list rows also preview');
|
||||
await android.screenshot(resolve(out,'04-image-list-preview-mobile.png'));
|
||||
await android.pressKey('Escape');
|
||||
await android.click('#listFixture [aria-label="Open in browser: public/pixel.png"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"),8);
|
||||
await android.evaluate('showVisit()');
|
||||
await android.evaluate("document.querySelector('#visitFixture [data-artifact-name=\"public/pixel.png\"]').focus()");
|
||||
await android.pressKey('Enter');await android.waitForSelector('.artifact-viewer');
|
||||
assert.equal(await android.evaluate("handoffs.length"),8,'visit image keyboard activation previews without hand-off');
|
||||
await android.pressKey('Escape');
|
||||
await android.click('#visitFixture [aria-label="Open in browser: public/pixel.png"]');
|
||||
assert.equal(await android.evaluate("handoffs.length"),9);
|
||||
assert.equal(await android.evaluate("!!document.querySelector('[aria-label=\"Preview in app: public/pixel.png\"]')"),false,'images no longer have an eye preview action');
|
||||
for(const width of [390,420,1100]) {
|
||||
await android.resize(width,844);
|
||||
await android.screenshot(resolve(out,`05-image-external-icon-${width}.png`));
|
||||
assert.equal(await android.evaluate('document.documentElement.scrollWidth<=innerWidth'),true);
|
||||
}
|
||||
await android.evaluate('showSearch()');
|
||||
await android.waitForSelector('#searchInput');await android.fill('#searchInput','evidence');
|
||||
await android.waitForSelector('.search-row[data-kind=artifact]');await android.click('.search-row[data-kind=artifact]');
|
||||
assert.equal(await android.evaluate("handoffs.length"), 8, "search results must use the same browser hand-off");
|
||||
assert.equal(await android.evaluate("handoffs.length"), 10, "search results must use the same browser hand-off");
|
||||
assert.equal(await android.evaluate("location.href"), original);
|
||||
assert.deepEqual(await android.evaluate("routes"), []);
|
||||
console.log("PASS: real browser tab opens while app URL/history stay intact; installed-Android VIEW intents cover tiles, chat, session and viewer actions; previews and Copy keep their original behavior. Android OS launch is not tested.");
|
||||
console.log("PASS: images preview on primary gallery/list/visit activation; external icons hand off without opening the viewer; keyboard/focus and mobile fit pass. Other artifact, chat, session, search and viewer browser actions retain safe hand-off. Android OS launch is not tested.");
|
||||
} finally {
|
||||
await browser?.close();
|
||||
await new Promise(r => server.close(r));
|
||||
|
||||
@@ -9,9 +9,9 @@ test("shell updates retain unrelated caches and the current app cache", async ()
|
||||
let activation;
|
||||
vm.runInNewContext(await readFile(new URL("../sw.js", import.meta.url), "utf8"), {
|
||||
self: { addEventListener: (type, handler) => handlers.set(type, handler), clients: { claim: async () => {} } },
|
||||
caches: { keys: async () => ["pipelines-shell-v13", "pipelines-shell-v14", "unrelated-user-cache"], delete: async (key) => deleted.push(key) },
|
||||
caches: { keys: async () => ["pipelines-shell-v14", "pipelines-shell-v15", "unrelated-user-cache"], delete: async (key) => deleted.push(key) },
|
||||
});
|
||||
handlers.get("activate")({ waitUntil: (promise) => { activation = promise; } });
|
||||
await activation;
|
||||
assert.deepEqual(deleted, ["pipelines-shell-v13"]);
|
||||
assert.deepEqual(deleted, ["pipelines-shell-v14"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user