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-drawn-under-filtered-parent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Dashboard stage tracker: a PR whose drawn_under issue is filtered out or on another page is now drawn under a listed issue instead of disappearing (#15116).
32 changes: 32 additions & 0 deletions src/pkg/dashboard/stage_tracker_actor_icon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ assert.deepStrictEqual(stageTrackerLinkedSorted(issue(14911, [lp(14921, 14910)])
`)
}

// A PR drawn under an issue that is filtered out or on another page is drawn
// under the first listed issue that covers it instead of vanishing.
func TestStageTrackerLinkedDrawnUnderHiddenParentJS(t *testing.T) {
html := indexHTML(t)
runStageTrackerRowActionsScript(t, stageTrackerRowsPreludeJS(t, html)+"\n"+stageTrackerActorIconJS(t, html)+jsFunc(t, html, "stageTrackerAdoptOrphanPRs")+stageTrackerRowsFixtureJS+`
const since = new Date(now - 3600000).toISOString();
const lp = (n, under) => ({ number: n, title: 'fix', url: 'https://x/' + n, author: 'hive-bot', author_kind: 'hive', stage: 70, stage_since: since, drawn_under: under });
const issue = (n, prs) => ({ repo: 'hivecommons/hive', number: n, kind: 'issue', title: 'Issue ' + n, url: 'https://x/' + n, stage: 40, stage_since: since, caption: 'open PR covers it', linked_prs: prs });
const hasPR = (row, n) => row.includes('#' + n) && !row.includes('under #');

// The owner (#14910) is not on the page: #14911 draws the PR itself.
let rows = stageTrackerAdoptOrphanPRs([issue(14911, [lp(14921, 14910)])]);
let html1 = stageTrackerRowHtml(rows[0], stages, ctx);
assert.ok(hasPR(html1, 14921), 'the PR is drawn when its owner is hidden: ' + html1);
assert.deepStrictEqual(stageTrackerLinkedElsewhere(rows[0]), []);

// Two listed issues cover it: only the first draws it, the other chips to it.
rows = stageTrackerAdoptOrphanPRs([issue(14911, [lp(14921, 14910)]), issue(14912, [lp(14921, 14910)])]);
assert.strictEqual(rows[0].linked_prs[0].drawn_under, 0);
assert.strictEqual(rows[1].linked_prs[0].drawn_under, 14911);

// The owner is listed: nothing changes, and inputs are never mutated.
const owner = issue(14910, [lp(14921, 14910)]), other = issue(14911, [lp(14921, 14910)]);
rows = stageTrackerAdoptOrphanPRs([owner, other]);
assert.strictEqual(rows[0], owner);
assert.strictEqual(rows[1], other);
rows = stageTrackerAdoptOrphanPRs([other, null]);
assert.strictEqual(other.linked_prs[0].drawn_under, 14910);
assert.strictEqual(rows[1], null);
`)
}

// The "Merged today" counter lives in the column header, over the Merge
// gate and ✓ columns (not in the filter chip bar), so a merge token's flight
// from a row's ✓ cell is short and ends above the gate. It is one node for
Expand Down
29 changes: 27 additions & 2 deletions src/pkg/dashboard/static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15231,6 +15231,30 @@ <h3 class="faq-group-title">Where to get help</h3>
return linked.sort((x, y) => (stageTrackerAnchor(y.stage, stages, 'pr') - stageTrackerAnchor(x.stage, stages, 'pr')) || (stageTrackerAttentionTier(x) - stageTrackerAttentionTier(y)) || (sinceOf(x) - sinceOf(y)) || ((x.number || 0) - (y.number || 0)));
}

// Pure: a PR whose drawn_under issue is not a row of this page (filtered
// out or on another page) would otherwise be drawn nowhere. The first
// listed issue that covers it draws it instead; later ones chip to that
// row. Returns the rows (same length, nulls kept), copying only changed ones.
function stageTrackerAdoptOrphanPRs(rows) {
const listed = new Set();
for (const it of rows) if (it && it.kind === 'issue') listed.add(it.repo + '#' + it.number);
const claimedBy = {};
return rows.map(it => {
if (!it || it.kind !== 'issue' || !Array.isArray(it.linked_prs)) return it;
let changed = false;
const linked = it.linked_prs.map(lp => {
const under = Number(lp && lp.drawn_under) || 0;
if (!under || under === (Number(it.number) || 0) || listed.has(it.repo + '#' + under)) return lp;
const key = it.repo + '#' + lp.number;
if (!(key in claimedBy)) claimedBy[key] = Number(it.number) || 0;
if (claimedBy[key] === (Number(it.number) || 0)) { changed = true; return Object.assign({}, lp, { drawn_under: 0 }); }
changed = true;
return Object.assign({}, lp, { drawn_under: claimedBy[key] });
});
return changed ? Object.assign({}, it, { linked_prs: linked }) : it;
});
}

// List order: furthest along the strip first — a covered issue counts as
// far along as its furthest covering PR — then longest-waiting first.
function stageTrackerSortKey(item, stages) {
Expand Down Expand Up @@ -16624,10 +16648,11 @@ <h2 class="config-title" id="activity-monitor-labels-title">All labels</h2>
// unchanged, collapsed out with their last row).
// A row celebrating its merge is pinned past the payload that
// dropped it (stageTrackerPinnedRows) until its moment is over.
const pageItems = stageTrackerAdoptOrphanPRs(page.rows.map(e => grouping ? e.item : e));
const rows = stageTrackerPinnedRows(el, [{ key: STAGE_TRACKER_HEADER_KEY, html: stageTrackerHeaderHtml(stages) }]
.concat(page.rows.map(e => grouping && !e.item
.concat(page.rows.map((e, i) => grouping && !e.item
? { key: e.group.key, html: stageTrackerGroupHeaderHtml(e.group, stages, ctx) }
: { key: stageTrackerItemKey(grouping ? e.item : e), html: stageTrackerRowHtml(grouping ? e.item : e, stages, ctx) })), nowMs);
: { key: stageTrackerItemKey(pageItems[i]), html: stageTrackerRowHtml(pageItems[i], stages, ctx) })), nowMs);
const rec = stageTrackerReconcile(el, rows, { effect, hidden: document.hidden });
if (rec.deferred) stageTrackerScheduleSettle();
stageTrackerMergedCountMount(el);
Expand Down
Loading