web: shared modal focus controller (M1/M2) — work in progress

This commit is contained in:
2026-10-19 20:46:15 +01:00
parent a7991077d2
commit b1e9400d6e
11 changed files with 1562 additions and 121 deletions
+27 -23
View File
@@ -91,7 +91,7 @@ const ARTIFACT_SERVER_HINT =
"Set the server URL in Settings to open or copy artifact links.";
export function createRunDetailView(rt) {
const { state, repo } = rt;
const { state, repo, modal } = rt;
const renderContent = (...args) => rt.renderContent(...args);
const selectRun = (...args) => rt.selectRun(...args);
const pushRoute = (...args) => rt.pushRoute(...args);
@@ -347,7 +347,6 @@ function renderChangesBody(changes) {
* the diff viewer on this file, whose position there confirms which row it is.
*/
function renderChangeRow(entry, index, files) {
const open = () => openChangeViewer(files, index);
const row = h("div", {
class: "change-row",
role: "button",
@@ -355,6 +354,7 @@ function renderChangeRow(entry, index, files) {
"data-change-index": String(index),
"aria-label": `Open ${entry.path}`,
});
const open = () => openChangeViewer(files, index, row);
row.addEventListener("click", open);
row.addEventListener("keydown", (event) => {
if (event.key === "Enter" || event.key === " ") {
@@ -492,6 +492,23 @@ function renderStagePane(d) {
}
for (const spec of specs) body.append(renderStageSection(spec, step));
overlay.append(h("div", { class: "stage-pane-sheet" }, bar, body));
modal.stage("stage-pane", overlay, {
onClose: () => closeStagePane(),
fallbackSelectors: ["#detailTitle", "#pane-main"],
// A pane opened from the Timeline returns to its row; one opened from the
// Graph returns to the stage node (there is no timeline row then).
restore: () => {
const row = [...document.querySelectorAll(".timeline-row")].find(
(node) =>
node.dataset.stageKey === stageKey && node.dataset.visitIndex === String(visitIndex),
);
return (
row ??
[...document.querySelectorAll(".graph-node")].find((node) => node.dataset.key === stageKey) ??
null
);
},
});
return overlay;
}
@@ -570,7 +587,7 @@ function renderVerdictLink(text, artifact, step) {
const link = h("a", { class: "verdict-link", href: resolved, target: "_blank", rel: "noreferrer", text });
link.addEventListener("click", (event) => {
event.preventDefault();
openArtifactFromVerdict(artifact, step, resolved);
openArtifactFromVerdict(artifact, step, resolved, link);
});
return link;
}
@@ -583,12 +600,12 @@ function renderVerdictRef(artifact, step) {
type: "button",
text: artifact.name || "(unnamed artifact)",
});
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved));
chip.addEventListener("click", () => openArtifactFromVerdict(artifact, step, resolved, chip));
return chip;
}
/** Open a referenced artifact: media in the viewer, everything else externally. */
function openArtifactFromVerdict(artifact, step, resolved) {
function openArtifactFromVerdict(artifact, step, resolved, trigger = null) {
if (!resolved) return;
const group = { stageKey: step.stage, visit: displayVisit(step, 0), artifacts: presentedArtifacts(step) };
const viewable = pagedArtifacts([group]);
@@ -596,11 +613,11 @@ function openArtifactFromVerdict(artifact, step, resolved) {
const at = viewerIndexOf.get(artifact.url);
const kind = artifactKind(artifact.content_type, artifact.name);
const media = kind === ArtifactKind.Image || kind === ArtifactKind.Video;
if (media && at != null) openArtifactViewer(viewable, at);
if (media && at != null) openArtifactViewer(viewable, at, trigger);
else window.open(resolved, "_blank", "noopener,noreferrer");
}
/** Open the stage pane for one visit of a stage and move focus into it. */
/** Open the stage pane for one visit of a stage; the controller moves focus in. */
function openStagePane(stageKey, visitIndex, { updateRoute = true } = {}) {
state.runStagePane = { stageKey, visitIndex };
state.runStageSections = new Set();
@@ -613,30 +630,17 @@ function openStagePane(stageKey, visitIndex, { updateRoute = true } = {}) {
});
}
renderContent();
document.querySelector(".stage-pane-back")?.focus();
}
/** Close the stage pane, returning focus to the timeline row that opened it. */
/** Close the stage pane; the controller returns focus to the row or graph node. */
function closeStagePane({ updateRoute = true } = {}) {
const closing = state.runStagePane;
if (!closing) return;
if (!state.runStagePane) return;
state.runStagePane = null;
state.runStageSections = new Set();
if (updateRoute && state.selectedRunId) {
pushRoute({ kind: "run", id: state.selectedRunId });
}
renderContent();
const row = [...document.querySelectorAll(".timeline-row")].find(
(node) => node.dataset.stageKey === closing.stageKey && node.dataset.visitIndex === String(closing.visitIndex),
);
// A pane opened from the Timeline returns to its row; one opened from the Graph
// returns to the stage node that opened it (there is no timeline row then).
const focusTarget =
row ??
[...document.querySelectorAll(".graph-node")].find(
(candidate) => candidate.dataset.key === closing.stageKey,
);
focusTarget?.focus();
}
// --- Run-level operator actions (R11–R14) ----------------------------------
@@ -856,7 +860,7 @@ function renderArtifactTile(artifact, viewable, viewerIndexOf) {
});
const openViewer = () => {
const at = viewerIndexOf.get(artifact.url);
if (at != null) openArtifactViewer(viewable, at);
if (at != null) openArtifactViewer(viewable, at, tile);
};
const openTab = () => {
if (resolved) window.open(resolved, "_blank", "noopener,noreferrer");