Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/fixed-15880.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- dashboard: merge banners drain the toast countdown bar (#15880)
5 changes: 4 additions & 1 deletion src/pkg/dashboard/stage_tracker_cues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,8 @@ func stageTrackerCelebrateJS(t *testing.T, html string) string {
jsFunc(t, html, "celebrateDetached"),
jsFunc(t, html, "stageTrackerMergeBannerNumber"),
jsFunc(t, html, "stageTrackerMergeBannerText"),
jsFunc(t, html, "toastCountdownBar"),
jsFunc(t, html, "toastCountdownCancel"),
jsFunc(t, html, "stageTrackerMergeBanner"),
jsFunc(t, html, "stageTrackerMergeBannerDismiss"),
jsFunc(t, html, "hamBannerDismiss"),
Expand Down Expand Up @@ -417,14 +419,15 @@ function el(tag, attrs) {
querySelector(sel) { return e.querySelectorAll(sel)[0] || null; },
querySelectorAll(sel) { const out = []; const unesc = v => v.replace(/\\(.)/g, '$1'); const m = sel.match(/^\[([\w-]+)="(.*)"\]$/); const word = sel.match(/^\[([\w-]+)~="(.*)"\]\[data-ham-key\]$/); const cls = sel.match(/^\.([\w-]+)/); const capOfRow = sel === '.ham-row[data-ham-key] .ham-seg.cap'; const walk = n => { for (const c of n.children) { if (capOfRow) { if (c.classList.contains('cap') && c.closest('.ham-row') && c.closest('.ham-row').classList.contains('ham-row')) out.push(c); } else if (m && c.attrs[m[1]] === unesc(m[2])) out.push(c); else if (word && c.attrs['data-ham-key'] != null && String(c.attrs[word[1]] || '').split(' ').includes(unesc(word[2]))) out.push(c); else if (!m && !word && cls && c.classList.contains(cls[1]) && (!sel.includes('[data-at]') || c.attrs['data-at'] != null)) out.push(c); walk(c); } }; walk(e); return out; },
closest(sel) { let n = e; while (n) { if (n.attrs && n.attrs['data-ham-key'] != null) return n; n = n.parentNode; } return null; },
matches() { return false; }, contains(x) { return x === e || e.children.some(c => c.contains(x)); },
};
return e;
}
global.CSS = { escape: s => String(s).replace(/([^\w-])/g, '\\$1') };
const body = el('body'); const panel = el('div'); const chip = el('button', { id: 'activity-monitor-merged' }); const n = el('span'); n.classList.add('ham-merged-n'); n.textContent = '0'; chip.appendChild(n); const sub = el('span'); sub.classList.add('ham-merged-sub'); chip.appendChild(sub); chip.rect = { left: 500, top: 10, width: 60, height: 20 };
const pop = el('div', { id: 'activity-monitor-merged-pop' }); pop.hidden = true; const banners = el('div'); const live = el('span');
const byId = { 'activity-monitor-panel': panel, 'activity-monitor-merged': chip, 'activity-monitor-merged-pop': pop, 'merge-banners': banners, 'activity-monitor-merged-live': live };
global.document = { body, hidden: false, getElementById(id) { return byId[id] || null; }, createElement(tag) { if (tag === 'template') { const tpl = el('template'); Object.defineProperty(tpl, 'innerHTML', { set(v) { const c = el('p'); c.classList.add('cue-event'); c.attrs['data-cue-key'] = (v.match(/data-cue-key="([^"]*)"/) || [])[1]; c.textContent = v.replace(/<[^>]+>/g, ''); const age = el('span'); age.classList.add('cue-event-age'); age.attrs['data-at'] = (v.match(/data-at="(\d+)"/) || [])[1]; c.appendChild(age); tpl.content = { firstElementChild: c }; } }); return tpl; } return el(tag); } };
global.document = { body, hidden: false, activeElement: null, getElementById(id) { return byId[id] || null; }, createElement(tag) { if (tag === 'template') { const tpl = el('template'); Object.defineProperty(tpl, 'innerHTML', { set(v) { const c = el('p'); c.classList.add('cue-event'); c.attrs['data-cue-key'] = (v.match(/data-cue-key="([^"]*)"/) || [])[1]; c.textContent = v.replace(/<[^>]+>/g, ''); const age = el('span'); age.classList.add('cue-event-age'); age.attrs['data-at'] = (v.match(/data-at="(\d+)"/) || [])[1]; c.appendChild(age); tpl.content = { firstElementChild: c }; } }); return tpl; } return el(tag); } };
const store = {}; global.localStorage = { getItem: k => (k in store ? store[k] : null), setItem(k, v) { store[k] = String(v); } };
const session = {}; global.sessionStorage = { getItem: k => (k in session ? session[k] : null), setItem(k, v) { session[k] = String(v); } };
let reduced = false; function stageTrackerReducedMotion() { return reduced; }
Expand Down
129 changes: 129 additions & 0 deletions src/pkg/dashboard/stage_tracker_merge_banner_countdown.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// Activity Monitor "#N merged" banners: the auto-dismiss goes through
// toastCountdownBar, so the banner drains the same .toast-bar every other
// timed toast shows (CSS keys on .toast-bar + --toast-ttl), hover holds it,
// and the manual × dismiss clears the pending timer. The functions are
// lifted straight out of index.html so this runs against the shipped source.
const test = require('node:test');
const assert = require('node:assert');
const fs = require('node:fs');
const path = require('node:path');

const html = fs.readFileSync(path.join(__dirname, 'static', 'index.html'), 'utf8');

function pick(re, what) {
const m = html.match(re);
assert.ok(m, what + ' not found in index.html');
return m[0];
}

// A minimal DOM: enough for toastCountdownBar and the banner builder.
function makeDom() {
const timers = [];
class El {
constructor(tag) {
this.tagName = tag; this.children = []; this.parentNode = null; this.attrs = {}; this.listeners = {};
this.style = { props: {}, setProperty(k, v) { this.props[k] = v; } };
this.className = ''; this.innerHTML = ''; this.id = '';
}
get classList() { const self = this; return { add(c) { self.className += ' ' + c; }, remove() {}, contains(c) { return self.className.split(' ').includes(c); } }; }
appendChild(c) { if (c.parentNode) c.parentNode.removeChild(c); c.parentNode = this; this.children.push(c); return c; }
removeChild(c) { this.children = this.children.filter(x => x !== c); c.parentNode = null; }
remove() { if (this.parentNode) this.parentNode.removeChild(this); }
setAttribute(k, v) { this.attrs[k] = String(v); }
getAttribute(k) { return this.attrs[k] === undefined ? null : this.attrs[k]; }
addEventListener(n, fn) { (this.listeners[n] = this.listeners[n] || []).push(fn); }
fire(n, e) { for (const fn of this.listeners[n] || []) fn(e || {}); }
matches() { return false; }
contains(x) { return x === this || this.children.some(c => c.contains(x)); }
querySelector() { return null; }
closest(sel) { for (let n = this; n; n = n.parentNode) if (sel === '.merge-banner' && n.className && n.className.split(' ').includes('merge-banner')) return n; return null; }
}
const body = new El('body');
const byId = {};
const document = {
body, activeElement: null,
createElement: t => new El(t),
getElementById: id => byId[id] || null,
};
const origAppend = body.appendChild.bind(body);
body.appendChild = c => { if (c.id) byId[c.id] = c; return origAppend(c); };
const setTimeout = (fn, ms) => { const t = { fn, ms, cleared: false }; timers.push(t); return t; };
const clearTimeout = t => { if (t) t.cleared = true; };
return { document, timers, setTimeout, clearTimeout, El };
}

const BANNER_MS = 30000;
const src = [
'const window = {};',
'function esc(s) { return typeof s === "string" ? s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;") : ""; }',
'const _stageTrackerMerged = { server: { recent: [] } };',
'const _stageTrackerPRTitle = {};',
'function stageTrackerMergedIdent(repo, n) { return repo + "#" + n; }',
'function stageTrackerMergedByText() { return ""; }',
'function stageTrackerReducedMotion() { return true; }',
'function stageTrackerAfter(el, ev, ms, fn) { fn(); }',
`function stageTrackerMergeBannerMs() { return ${BANNER_MS}; }`,
pick(/const STAGE_TRACKER_MERGE_BANNER_MAX = [^\n]*\n/, 'STAGE_TRACKER_MERGE_BANNER_MAX'),
pick(/function toastCountdownBar\(el, ms, onExpire\) \{[\s\S]*?\n \}\n/, 'toastCountdownBar'),
pick(/function toastCountdownCancel\(el\) \{[\s\S]*?\n \}\n/, 'toastCountdownCancel'),
pick(/function stageTrackerMergeBannerNumber\(b\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerNumber'),
pick(/function stageTrackerMergeBannerText\(b, nowMs\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerText'),
pick(/function stageTrackerMergeBanner\(b\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBanner'),
pick(/function stageTrackerMergeBannerDismiss\(el\) \{[\s\S]*?\n \}\n/, 'stageTrackerMergeBannerDismiss'),
pick(/function hamBannerDismiss\(btn\) \{[\s\S]*?\n \}\n/, 'hamBannerDismiss'),
].join('\n');

function load() {
const dom = makeDom();
const api = new Function('document', 'setTimeout', 'clearTimeout', src + '; return { banner: stageTrackerMergeBanner, dismiss: stageTrackerMergeBannerDismiss, hamBannerDismiss };')(dom.document, dom.setTimeout, dom.clearTimeout);
return Object.assign(dom, api);
}

const merge = { key: 'hivecommons/hive/pr#15834', repo: 'hivecommons/hive', number: 15834, title: 'fix the thing', at: Date.now() };

test('merge banner carries the countdown bar and --toast-ttl the CSS drains over', () => {
const d = load();
const el = d.banner(merge);
const bar = el.children.find(c => c.className === 'toast-bar');
assert.ok(bar, 'a .toast-bar child is appended to the banner');
assert.strictEqual(bar.getAttribute('aria-hidden'), 'true');
assert.strictEqual(el.style.props['--toast-ttl'], BANNER_MS + 'ms', 'bar duration equals the banner duration');
assert.ok(el._countdown, 'countdown state is armed');
assert.strictEqual(d.timers.length, 1);
assert.strictEqual(d.timers[0].ms, BANNER_MS, 'dismiss timer uses stageTrackerMergeBannerMs()');
assert.strictEqual(el._timer, undefined, 'no bare setTimeout handle remains');
});

test('timer expiry removes the banner', () => {
const d = load();
const el = d.banner(merge);
assert.ok(el.parentNode);
d.timers[0].fn();
assert.strictEqual(el.parentNode, null, 'banner left the stack when the countdown fired');
});

test('hover holds the countdown and the bar together; leaving re-arms the remainder', () => {
const d = load();
const el = d.banner(merge);
const bar = el.children.find(c => c.className === 'toast-bar');
assert.strictEqual(d.timers.length, 1);
el.fire('mouseenter');
assert.ok(d.timers[0].cleared, 'timer cleared on hover');
assert.strictEqual(bar.style.animationPlayState, 'paused');
el.fire('mouseleave');
assert.strictEqual(d.timers.length, 2, 'a fresh timer is armed on leave');
assert.ok(d.timers[1].ms <= BANNER_MS && d.timers[1].ms > 0, 'remainder re-armed');
assert.strictEqual(bar.style.animationPlayState, 'running');
});

test('manual × dismiss clears the pending timer and the bar', () => {
const d = load();
const el = d.banner(merge);
const close = new d.El('button');
el.appendChild(close);
d.hamBannerDismiss(close);
assert.strictEqual(el.parentNode, null, 'banner removed');
assert.ok(d.timers[0].cleared, 'auto-dismiss timer cleared so it cannot fire stale');
assert.strictEqual(el._countdown, null);
assert.ok(!el.children.some(c => c.className === 'toast-bar'), 'bar removed with the countdown');
});
3 changes: 2 additions & 1 deletion src/pkg/dashboard/static-src/css/tracker.css
Original file line number Diff line number Diff line change
Expand Up @@ -571,7 +571,8 @@
(just the ⟳ and the actor glyph). */
.ham-seg.active .ham-seg-t.ham-queue-stalled { color: inherit; }
.merge-banners { position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: var(--z-merge-banner); display: flex; flex-direction: column; gap: var(--sp-3); max-width: min(26rem, calc(100vw - 2 * var(--sp-6))); pointer-events: none; }
.merge-banner { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-4); align-items: start; padding: var(--sp-4) var(--sp-5); border: var(--line-width) solid var(--line); border-left: 3px solid var(--green); border-radius: var(--r); background: var(--panel-strong); color: var(--text); box-shadow: var(--shadow-raised); font-size: var(--fs-sm); pointer-events: auto; animation: merge-banner-in 220ms ease-out both; }
.merge-banner { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-4); align-items: start; padding: var(--sp-4) var(--sp-5); border: var(--line-width) solid var(--line); border-left: 3px solid var(--green); border-radius: var(--r); background: var(--panel-strong); color: var(--text); box-shadow: var(--shadow-raised); font-size: var(--fs-sm); pointer-events: auto; position: relative; overflow: hidden; animation: merge-banner-in 220ms ease-out both; }
.merge-banner .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); }
.merge-banner.merge-banner-out { animation: merge-banner-out 180ms ease-in both; }
.merge-banner-ico { color: var(--green); font-weight: var(--fw-bold); }
.merge-banner-head { font-weight: var(--fw-semibold); }
Expand Down
9 changes: 6 additions & 3 deletions src/pkg/dashboard/static-src/js/tracker-merged.js
Original file line number Diff line number Diff line change
Expand Up @@ -925,7 +925,10 @@
// Stateful: a persistent banner, bottom right, for one merge — stays
// until dismissed or stageTrackerMergeBannerMs() (twice the info toast
// duration, STAGE_TRACKER_MERGE_BANNER_MS at the default), stacked when
// several, with a "show row" link while the row is on the board.
// several, with a "show row" link while the row is on the board. The
// auto-dismiss goes through toastCountdownBar like every other timed
// toast, so the banner drains a .toast-bar along its bottom edge and
// hover / focus inside it holds both timer and bar together.
function stageTrackerMergeBanner(b) {
if (!document.body) return null;
let box = document.getElementById('merge-banners');
Expand All @@ -943,12 +946,12 @@
el.innerHTML = `<span class="merge-banner-ico" aria-hidden="true">✓</span><div class="merge-banner-body"><div class="merge-banner-head">${num ? `<span class="merge-banner-num">#${esc(num)}</span> ` : ''}merged${info.preview ? ' <span class="text-muted">(test)</span>' : ''}</div><div class="merge-banner-text" title="${esc(t.text)}">${esc(t.text)}</div><div class="merge-banner-links">${b.rowKey ? `<button type="button" data-action="hamBannerShowRow" data-arg0="${esc(b.rowKey)}" data-stop="1">Show row</button>` : ''}${info.url ? `<a href="${esc(info.url)}" target="_blank" rel="noopener">Open on GitHub</a>` : ''}<button type="button" data-action="hamMergedOpen" data-stop="1">All merges</button></div></div><button type="button" class="merge-banner-close" data-action="hamBannerDismiss" data-arg-types="t" data-stop="1" aria-label="Dismiss">×</button>`;
box.appendChild(el);
while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) box.children[0].remove();
el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), stageTrackerMergeBannerMs());
toastCountdownBar(el, stageTrackerMergeBannerMs(), () => stageTrackerMergeBannerDismiss(el));
return el;
}
function stageTrackerMergeBannerDismiss(el) {
if (!el || !el.parentNode) return;
if (el._timer) { clearTimeout(el._timer); el._timer = 0; }
toastCountdownCancel(el);
if (stageTrackerReducedMotion()) { el.remove(); return; }
el.classList.add('merge-banner-out');
stageTrackerAfter(el, 'animationend', 180, () => el.remove());
Expand Down
12 changes: 8 additions & 4 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,8 @@
(just the ⟳ and the actor glyph). */
.ham-seg.active .ham-seg-t.ham-queue-stalled { color: inherit; }
.merge-banners { position: fixed; right: var(--sp-6); bottom: var(--sp-6); z-index: var(--z-merge-banner); display: flex; flex-direction: column; gap: var(--sp-3); max-width: min(26rem, calc(100vw - 2 * var(--sp-6))); pointer-events: none; }
.merge-banner { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-4); align-items: start; padding: var(--sp-4) var(--sp-5); border: var(--line-width) solid var(--line); border-left: 3px solid var(--green); border-radius: var(--r); background: var(--panel-strong); color: var(--text); box-shadow: var(--shadow-raised); font-size: var(--fs-sm); pointer-events: auto; animation: merge-banner-in 220ms ease-out both; }
.merge-banner { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: var(--sp-4); align-items: start; padding: var(--sp-4) var(--sp-5); border: var(--line-width) solid var(--line); border-left: 3px solid var(--green); border-radius: var(--r); background: var(--panel-strong); color: var(--text); box-shadow: var(--shadow-raised); font-size: var(--fs-sm); pointer-events: auto; position: relative; overflow: hidden; animation: merge-banner-in 220ms ease-out both; }
.merge-banner .toast-bar { background: color-mix(in srgb, var(--green) 40%, transparent); }
.merge-banner.merge-banner-out { animation: merge-banner-out 180ms ease-in both; }
.merge-banner-ico { color: var(--green); font-weight: var(--fw-bold); }
.merge-banner-head { font-weight: var(--fw-semibold); }
Expand Down Expand Up @@ -22812,7 +22813,10 @@ <h2 class="config-title" id="activity-monitor-labels-title">All labels</h2>
// Stateful: a persistent banner, bottom right, for one merge — stays
// until dismissed or stageTrackerMergeBannerMs() (twice the info toast
// duration, STAGE_TRACKER_MERGE_BANNER_MS at the default), stacked when
// several, with a "show row" link while the row is on the board.
// several, with a "show row" link while the row is on the board. The
// auto-dismiss goes through toastCountdownBar like every other timed
// toast, so the banner drains a .toast-bar along its bottom edge and
// hover / focus inside it holds both timer and bar together.
function stageTrackerMergeBanner(b) {
if (!document.body) return null;
let box = document.getElementById('merge-banners');
Expand All @@ -22830,12 +22834,12 @@ <h2 class="config-title" id="activity-monitor-labels-title">All labels</h2>
el.innerHTML = `<span class="merge-banner-ico" aria-hidden="true">✓</span><div class="merge-banner-body"><div class="merge-banner-head">${num ? `<span class="merge-banner-num">#${esc(num)}</span> ` : ''}merged${info.preview ? ' <span class="text-muted">(test)</span>' : ''}</div><div class="merge-banner-text" title="${esc(t.text)}">${esc(t.text)}</div><div class="merge-banner-links">${b.rowKey ? `<button type="button" data-action="hamBannerShowRow" data-arg0="${esc(b.rowKey)}" data-stop="1">Show row</button>` : ''}${info.url ? `<a href="${esc(info.url)}" target="_blank" rel="noopener">Open on GitHub</a>` : ''}<button type="button" data-action="hamMergedOpen" data-stop="1">All merges</button></div></div><button type="button" class="merge-banner-close" data-action="hamBannerDismiss" data-arg-types="t" data-stop="1" aria-label="Dismiss">×</button>`;
box.appendChild(el);
while (box.children.length > STAGE_TRACKER_MERGE_BANNER_MAX) box.children[0].remove();
el._timer = setTimeout(() => stageTrackerMergeBannerDismiss(el), stageTrackerMergeBannerMs());
toastCountdownBar(el, stageTrackerMergeBannerMs(), () => stageTrackerMergeBannerDismiss(el));
return el;
}
function stageTrackerMergeBannerDismiss(el) {
if (!el || !el.parentNode) return;
if (el._timer) { clearTimeout(el._timer); el._timer = 0; }
toastCountdownCancel(el);
if (stageTrackerReducedMotion()) { el.remove(); return; }
el.classList.add('merge-banner-out');
stageTrackerAfter(el, 'animationend', 180, () => el.remove());
Expand Down
Loading