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/changed-shared-pr-group.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Activity Monitor: the issues one PR closes together are now one group of the list — the secondary rows sit right after their primary (indented on a rail), render from the primary's own PR snapshot, and fold under a caret on the primary's "also closes" pill (remembered in localStorage).
2 changes: 2 additions & 0 deletions src/docs/dashboard-sections/activity-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,8 @@ Payloads without `drawn_under` draw as before.

The link reads both ways (hivecommons/hive#15806): the entry drawn under #A carries `also_closes` — the other listed open issues the PR closes (number, title, url) — and the PR's line wears a gray **also closes #B** pill beside the PR link, in the lineage-pill style (comma-separated for several, three numbers then **+N**, every number linking to its issue; tooltip: *this PR also resolves #B (title)*). The "↳ … under …" listing never carries it.

The issues one PR closes are one group of the list. A secondary issue's row always sits right after its primary (#A, then #B — whatever the lead sort or a merge train would have put between them; the group takes the primary's place in the order, several secondaries keep their lead order among themselves), indented as a child on a thin rail from the primary's pill to the last child's elbow. Both rows are built from the primary's own listing of the PR — the secondary's copy is replaced by that object before the rows render — so the two chevron strips can never light different stages. The **also closes** pill on the primary carries a caret (▾/▸) that folds and unfolds the secondaries' rows (the folded pill reads **+N**; folded rows still count in the total), remembered per primary in `localStorage` under `hive.tracker.shared.collapsed`. A secondary whose primary is not a row of the current list (filtered out, or on another page) stands alone exactly as before, with its **↳ #N · under #M** chip.

#### Merged (the chip, the ledger, the flight)

A thin bar at the top of the tracker — it stays pinned under the card header while the list scrolls, with the stage column header strip pinned just below it — carries the dashboard's bee glyph (the version card's bee, in a 28 px hit area; the pill is no taller than the chips beside it) with **Merged** and the all-time count drawn as a **quiet odometer at rest, always** — one shallow inset track with a hairline border and faint dividers, a wheel per digit, tabular semibold digits at the chip's own type size, no thousands separator (#15543: the first drum's 18 px bevelled cells were "too big of font … the animation is perfect though" — the roll is unchanged) — every pull request the hive tracked that reached merged, *all time*, with *N today · N this week* beside it at the bar's usual size. The number is the server's, not the tab's: the hive keeps a **merged ledger** at `/data/merged-ledger.json` (entries for 90 days, an all-time total that only grows, atomic writes, seeded on first boot from the audit log's `pr_merged` history with the PR throughput counter as the floor, then backfilled by the first closed sweep, which on such a boot asks GitHub for every PR closed in the last 30 days — merges by people and other bots the audit log never saw — instead of its usual one day; so the ledger counts every merged PR in a configured repository, and its all-time number is expected to run above the hive-observed PR throughput counter it was seeded from) fed by the audit log's `pr_merged` lines — the hive's own merges on every path and the poller's observations of merges by people or other bots — and by webhook / closed-sweep snapshots of a PR GitHub reports merged, which carry the title and the merger's login within seconds.
Expand Down
170 changes: 170 additions & 0 deletions src/pkg/dashboard/stage_tracker_shared_pr_group_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
package dashboard

import (
"strings"
"testing"
)

// TestStageTrackerSharedPRGroupJS: the rows of issues one PR closes together
// are one unit of the list — the secondary sits right after its primary
// whatever the lead sort put between them, draws as its child, is built from
// the primary's own PR snapshot, and folds under the primary's "also closes"
// pill (remembered in localStorage). A secondary whose primary is not a row
// of this list stays standalone, as before.
func TestStageTrackerSharedPRGroupJS(t *testing.T) {
html := indexHTML(t)
runStageTrackerRowActionsScript(t, stageTrackerRowsPreludeJS(t, html)+"\n"+strings.Join([]string{
jsFunc(t, html, "stageTrackerLinkedSupersededText"),
jsFunc(t, html, "stageTrackerSharedPRParent"),
jsFunc(t, html, "stageTrackerSharedPRGroups"),
jsFunc(t, html, "stageTrackerSharedPRRebind"),
jsFunc(t, html, "stageTrackerSharedPRContiguous"),
jsConstLine(t, html, "STAGE_TRACKER_SHARED_COLLAPSED_KEY"),
jsFunc(t, html, "stageTrackerLoadSharedCollapsed"),
jsFunc(t, html, "stageTrackerSaveSharedCollapsed"),
jsFunc(t, html, "stageTrackerToggleCollapsed"),
}, "\n")+"\n"+stageTrackerActorIconJS(t, html)+stageTrackerRowsFixtureJS+`
const since = new Date(now - 3600000).toISOString();
const lit = (html) => (/<li class="ham-seg active[^"]*"[^>]*data-ham-stage="(\d+)"/.exec(strip(html)) || [])[1] || (/<li class="ham-seg active[^"]*"[^>]*title="([^"]*)"/.exec(strip(html)) || [])[1] || '';
const li = (n) => ({ number: n, title: 'Issue ' + n, url: 'https://x/issues/' + n });
const pr = (n, under, extra) => Object.assign({ number: n, title: 'fix', url: 'https://x/' + n, author: 'hive-bot', author_kind: 'hive', stage: 95, stage_since: since, drawn_under: under, merge_gate: { state: 'soaking' } }, extra || {});
const issue = (n, prs, extra) => Object.assign({ repo: 'hivecommons/hive', number: n, kind: 'issue', title: 'Issue ' + n, url: 'https://x/issues/' + n, stage: 40, stage_since: since, linked_prs: prs || [] }, extra || {});
const nums = (rows) => rows.map(r => r.number);

// The live board: #17292 (primary, PR #17308 also closes #17302) at the top,
// an unrelated #17329 between, #17302 (secondary) third.
const primary = issue(17292, [pr(17308, 17292, { also_closes: [li(17302)] })]);
const between = issue(17329, [], { stage: 30 });
// The secondary's copy of the PR is a different object from an older tick.
const secondary = issue(17302, [pr(17308, 17292, { stage: 50, merge_gate: null, stage_since: new Date(now - 7200000).toISOString() })]);

// Groups: the secondary belongs to the primary, by row key.
let g = stageTrackerSharedPRGroups([primary, between, secondary], stages);
assert.deepStrictEqual(g.parentOf, { 'hivecommons/hive/issue#17302': 'hivecommons/hive/issue#17292' });
assert.deepStrictEqual(g.children, { 'hivecommons/hive/issue#17292': ['hivecommons/hive/issue#17302'] });
assert.deepStrictEqual(g.prs, { 'hivecommons/hive/issue#17292': { 17308: true } });

// Adjacency: the secondary follows its primary; the unrelated row moves down.
let rows = stageTrackerSharedPRContiguous([primary, between, secondary], stages, {});
assert.deepStrictEqual(nums(rows), [17292, 17302, 17329], 'secondary right after its primary');
// The group sorts by the primary: a secondary ahead of its primary comes down to it.
rows = stageTrackerSharedPRContiguous([secondary, between, primary], stages, {});
assert.deepStrictEqual(nums(rows), [17329, 17292, 17302], 'group takes the primary\'s place');
// Several secondaries keep their lead order among themselves.
const third = issue(17310, [pr(17308, 17292, { stage: 50 })]);
const wide = issue(17292, [pr(17308, 17292, { also_closes: [li(17302), li(17310)] })]);
rows = stageTrackerSharedPRContiguous([third, between, wide, secondary], stages, {});
assert.deepStrictEqual(nums(rows), [17329, 17292, 17310, 17302]);
// Nothing to group → the very same array.
const plain = [between, issue(1, [pr(2, 1)])];
assert.strictEqual(stageTrackerSharedPRContiguous(plain, stages, {}), plain);

// Same snapshot: the secondary's listing of the PR becomes the primary's own
// entry (drawn_under kept, also_closes dropped) — stage 95 soaking, not the
// stale 50 — so both chevron strips light the same segment.
let sec = rows[3];
assert.strictEqual(sec.number, 17302);
assert.strictEqual(sec.linked_prs[0].stage, 95, 'rebound to the primary\'s PR snapshot');
assert.deepStrictEqual(sec.linked_prs[0].merge_gate, { state: 'soaking' });
assert.strictEqual(sec.linked_prs[0].drawn_under, 17292);
assert.strictEqual(sec.linked_prs[0].also_closes, null, 'the pill stays on the primary alone');
assert.strictEqual(secondary.linked_prs[0].stage, 50, 'the server payload is not mutated');
assert.notStrictEqual(sec, secondary, 'the row is a copy');
g = stageTrackerSharedPRGroups(rows, stages);
const ctxG = Object.assign({}, ctx, { shared: Object.assign(g, { collapsed: {} }) });
const headRow = stageTrackerRowHtml(rows[1], stages, ctxG);
const childRow = stageTrackerRowHtml(sec, stages, ctxG);
assert.strictEqual(lit(childRow), lit(headRow), 'both strips light from the same PR state: ' + lit(headRow) + ' vs ' + lit(childRow));
assert.notStrictEqual(lit(childRow), lit(stageTrackerRowHtml(secondary, stages, ctx)), 'the stale copy would have lit elsewhere');

// Visual: the primary heads the group, each secondary is a child; the last wears ham-shared-last.
assert.ok(/<div class="ham-row[^"]* ham-shared-head[^"]*"/.test(headRow), headRow.slice(0, 300));
assert.ok(/<div class="ham-row[^"]* ham-shared-child ham-shared-last"/.test(childRow), childRow.slice(0, 300));
assert.ok(childRow.includes('data-ham-shared-under="17292"'), childRow.slice(0, 300));
const midRow = stageTrackerRowHtml(rows[2], stages, ctxG);
assert.ok(/ ham-shared-child"/.test(midRow) && !midRow.includes('ham-shared-last'), midRow.slice(0, 300));
assert.ok(childRow.includes('↳ #17308 · under #17292'), 'the under chip stays');
assert.ok(!childRow.includes('ham-also-closes'), 'no reciprocal pill on a child');

// The primary's pill is the fold: a caret button, expanded by default.
const pi = headRow.indexOf('<span class="ham-badge ham-also-closes ham-shared-head-pill"');
assert.ok(pi >= 0, 'the primary wears the group pill: ' + headRow);
const pill = headRow.slice(pi, headRow.indexOf('</a></span>', pi) + '</a></span>'.length);
const pillTitle = (/ title="([^"]*)"/.exec(pill) || [])[1] || '';
assert.ok(pill.includes('data-action="hamSharedToggle" data-arg0="hivecommons/hive/issue#17292" data-stop="1" aria-expanded="true"'), pill);
assert.ok(pill.includes('aria-label="Fold 2 issue rows this PR also closes"'), pill);
assert.ok(pill.includes('▾') && text(pill).includes('also closes #17302, #17310'), text(pill));
assert.ok(pillTitle.includes('2 issue rows drawn under this row'), pillTitle);
assert.ok(!pill.slice(0, pill.indexOf('</button>')).includes('<a '), 'no link inside the button');

// Folded: the secondaries leave the list, the primary shows ▸ and +N, no head rail.
const folded = { 'hivecommons/hive/issue#17292': true };
rows = stageTrackerSharedPRContiguous([third, between, wide, secondary], stages, folded);
assert.deepStrictEqual(nums(rows), [17329, 17292], 'folded secondaries are not rows');
const ctxF = Object.assign({}, ctx, { shared: Object.assign(stageTrackerSharedPRGroups([third, between, wide, secondary], stages), { collapsed: folded }) });
const foldedRow = stageTrackerRowHtml(wide, stages, ctxF);
assert.ok(foldedRow.includes('ham-shared-folded') && foldedRow.includes('aria-expanded="false"') && foldedRow.includes('▸'), foldedRow);
assert.ok(foldedRow.includes('<span class="ham-shared-count">+2</span>'), foldedRow);
assert.ok(!/<div class="ham-row[^"]*ham-shared-head[^"]*"/.test(foldedRow), 'no rail below a folded head');

// Fallback: the primary filtered out (not a row) → the secondary stands alone, as before.
rows = stageTrackerSharedPRContiguous([between, secondary], stages, {});
assert.deepStrictEqual(nums(rows), [17329, 17302]);
assert.strictEqual(rows[1], secondary, 'untouched');
g = stageTrackerSharedPRGroups([between, secondary], stages);
assert.deepStrictEqual(g.parentOf, {});
const alone = stageTrackerRowHtml(secondary, stages, Object.assign({}, ctx, { shared: Object.assign(g, { collapsed: {} }) }));
assert.ok(!alone.includes('ham-shared-child') && alone.includes('↳ #17308 · under #17292'), alone.slice(0, 300));
// A primary in another repo with the same number is not this one's.
const other = issue(17292, [pr(17308, 17292, { also_closes: [li(17302)] })], { repo: 'hivecommons/pluk' });
assert.deepStrictEqual(stageTrackerSharedPRGroups([other, secondary], stages).parentOf, {});

// Without a group the pill's markup is unchanged.
assert.strictEqual(stageTrackerAlsoClosesChipHtml(pr(17308, 17292, { also_closes: [li(17302)] })), '<span class="ham-badge ham-also-closes" title="this PR also resolves #17302 (Issue 17302)">also closes <a href="https://x/issues/17302" target="_blank" rel="noopener">#17302</a></span>');
assert.strictEqual(stageTrackerAlsoClosesChipHtml(pr(17308, 17292, { also_closes: [li(17302)] }), { key: 'k', count: 0 }), stageTrackerAlsoClosesChipHtml(pr(17308, 17292, { also_closes: [li(17302)] })), 'an empty group is no group');
const one = stageTrackerAlsoClosesChipHtml(pr(17308, 17292, { also_closes: [li(17302)] }), { key: 'k', count: 1, collapsed: true });
assert.ok(one.includes('aria-label="Show 1 issue row this PR also closes"'), one);

// The fold persists under hive.tracker.shared.collapsed, like the repo groups.
const store = {};
global.localStorage = { getItem: k => (k in store ? store[k] : null), setItem(k, v) { store[k] = String(v); } };
assert.deepStrictEqual(stageTrackerLoadSharedCollapsed(), {});
let c = stageTrackerToggleCollapsed({}, 'hivecommons/hive/issue#17292');
stageTrackerSaveSharedCollapsed(c);
assert.strictEqual(store[STAGE_TRACKER_SHARED_COLLAPSED_KEY], '{"hivecommons/hive/issue#17292":true}');
assert.strictEqual(STAGE_TRACKER_SHARED_COLLAPSED_KEY, 'hive.tracker.shared.collapsed');
assert.deepStrictEqual(stageTrackerLoadSharedCollapsed(), { 'hivecommons/hive/issue#17292': true }, 'round-trips');
store[STAGE_TRACKER_SHARED_COLLAPSED_KEY] = '[1]';
assert.deepStrictEqual(stageTrackerLoadSharedCollapsed(), {}, 'a malformed value is empty');
`)
}

// TestStageTrackerSharedPRGroupWiring: the render applies the grouping after
// the lead sort, hands the groups to the rows, counts folded rows in the
// total, the caret's handler and CSS are in the page, and the CSS is tokens only.
func TestStageTrackerSharedPRGroupWiring(t *testing.T) {
html := indexHTML(t)
for _, want := range []string{
`ctx.shared = sharing ? Object.assign(stageTrackerSharedPRGroups(prepared, stages), { collapsed: _stageTrackerSharedCollapsed }) : null;`,
`const ordered = sharing ? stageTrackerSharedPRContiguous(prepared, stages, _stageTrackerSharedCollapsed) : prepared;`,
`if (foldedShared > 0) page.total += foldedShared;`,
`if (typeof stageTrackerLoadSharedCollapsed === 'function') _stageTrackerSharedCollapsed = stageTrackerLoadSharedCollapsed();`,
`function hamSharedToggle(key) {`,
`.ham-row.ham-shared-child {`, `.ham-row.ham-shared-head::before {`, `.ham-shared-toggle {`,
} {
if !strings.Contains(html, want) {
t.Errorf("index.html lacks %q", want)
}
}
start := strings.Index(html, ".ham-row.ham-shared-child {")
end := strings.Index(html[start:], ".ham-shared-count {")
if start < 0 || end < 0 {
t.Fatal("shared-PR group CSS block not found")
}
block := html[start : start+end]
for _, bad := range []string{"#", "rgb(", "hsl("} {
if strings.Contains(block, bad) {
t.Errorf("shared-PR group CSS uses a literal colour (%q); tokens only", bad)
}
}
}
16 changes: 16 additions & 0 deletions src/pkg/dashboard/static-src/css/tracker.css
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,22 @@
.ham-also-closes { color: var(--muted); }
.ham-also-closes a { color: inherit; text-decoration: none; }
.ham-also-closes a:hover { color: var(--text); text-decoration: underline; }
/* Shared-PR group (one PR closing several listed issues): the secondary
issues a PR also closes sit right under their primary, indented, on
a rail that runs from the primary's pill to the last child's elbow.
The primary's "also closes" pill carries the fold caret. Tokens only. */
.ham-row.ham-shared-child { position: relative; padding-left: var(--sp-6); }
.ham-row.ham-shared-child::before { content: ''; position: absolute; left: var(--sp-3); top: 0; bottom: 0; border-left: var(--line-width) solid var(--line-strong); pointer-events: none; }
.ham-row.ham-shared-child.ham-shared-last::before { bottom: 50%; }
.ham-row.ham-shared-child::after { content: ''; position: absolute; left: var(--sp-3); top: 50%; width: var(--sp-3); border-top: var(--line-width) solid var(--line-strong); pointer-events: none; }
.ham-row.ham-shared-child + .ham-row.ham-shared-child { border-top-color: transparent; }
.ham-row.ham-shared-head + .ham-row.ham-shared-child { border-top-color: transparent; }
.ham-row.ham-shared-head { position: relative; }
.ham-row.ham-shared-head::before { content: ''; position: absolute; left: var(--sp-3); top: 50%; bottom: 0; border-left: var(--line-width) solid var(--line-strong); pointer-events: none; }
.ham-shared-toggle { appearance: none; background: none; border: 0; padding: 0 var(--sp-1) 0 0; margin: 0; font: inherit; color: inherit; cursor: pointer; line-height: 1; vertical-align: baseline; }
.ham-shared-toggle:hover .ham-group-caret, .ham-shared-toggle:focus-visible .ham-group-caret { color: var(--text); }
.ham-shared-toggle:focus-visible { outline: var(--line-width) solid var(--line-strong); outline-offset: 1px; border-radius: var(--r-sm); }
.ham-shared-count { color: var(--text); }
.ham-plan-body, .ham-plan-note { white-space: pre-wrap; }
.ham-plan-note { color: var(--muted); font-size: var(--fs-xs); }
.ham-seg.active .cue-acting-cap { margin-left: var(--sp-2); }
Expand Down
12 changes: 11 additions & 1 deletion src/pkg/dashboard/static-src/js/tracker-filter-render.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,15 @@
if (stageTrackerRepoChipOn(stageTrackerRepoChipSetting(), repos.length)) ctx.repoChips = { primary: stageTrackerPrimaryRepo(), active: f.repo };
const visible = stageTrackerVisible(d.items, f, ctx);
const sorted = stageTrackerTrainContiguous(stageTrackerSort(visible, stages, f, { phone: stageTrackerPhone() }));
const ordered = typeof stageTrackerPreparationOrderRows === 'function' ? stageTrackerPreparationOrderRows(d, sorted, stages) : sorted;
const prepared = typeof stageTrackerPreparationOrderRows === 'function' ? stageTrackerPreparationOrderRows(d, sorted, stages) : sorted;
// Shared-PR groups last, so a secondary issue always sits right after
// its primary whatever the lead sort or train put between them; the
// groups a viewer folded leave their secondaries out of the list.
// Guarded: test harnesses lift renderStageTracker without tracker-words-core.
const sharing = typeof stageTrackerSharedPRContiguous === 'function';
ctx.shared = sharing ? Object.assign(stageTrackerSharedPRGroups(prepared, stages), { collapsed: _stageTrackerSharedCollapsed }) : null;
const ordered = sharing ? stageTrackerSharedPRContiguous(prepared, stages, _stageTrackerSharedCollapsed) : prepared;
const foldedShared = prepared.length - ordered.length;
// A TV display (display=1&density=tv) shows the rows that fit the
// screen, ungrouped, with "+N more" in place of the pager.
const tv = typeof stageTrackerDisplayTv === 'function' && stageTrackerDisplayTv();
Expand All @@ -107,6 +115,8 @@
? stageTrackerGroupPage(stageTrackerGroups(ordered, { primary: stageTrackerPrimaryRepo(), collapsed: _stageTrackerCollapsed, stages }), f)
: stageTrackerPage(ordered, f);
if (!tv && page.page !== f.page) f.page = page.page;
// A folded secondary is not filtered out: it counts toward the total.
if (foldedShared > 0) page.total += foldedShared;
// The rows this render draws (this page, group headers aside), for
// stageTrackerPRListedOwnRow: a covered issue defers to its PR's row
// only when that row is actually on screen. Kept beside the payload,
Expand Down
Loading
Loading