diff --git a/changelog.d/added-tracker-bulk-accept-triage.md b/changelog.d/added-tracker-bulk-accept-triage.md new file mode 100644 index 0000000000..b134358fab --- /dev/null +++ b/changelog.d/added-tracker-bulk-accept-triage.md @@ -0,0 +1 @@ +- Activity monitor: a multi-row selection offers **Accept triage (N selected)** — leading the selection bar and the bulk ⋯ menu when every selected row waits on a maintainer's triage, *Accept triage (k of N)* when some rows are skipped — accepting every selected issue through the existing per-item endpoint with one summary toast ("Accepted 4 issues"). diff --git a/src/docs/dashboard-copy-inventory.md b/src/docs/dashboard-copy-inventory.md index 599c634f37..589b8602db 100644 --- a/src/docs/dashboard-copy-inventory.md +++ b/src/docs/dashboard-copy-inventory.md @@ -64,6 +64,7 @@ The new hover, verbatim (title line omitted): | ⋯ menu hints (`stageTrackerLeadActions` → `ham-menu-hint`) | ⋯ menu | server consequences (11–31 each) | server consequences (≤ 12 each) | Go budget test | | `stageTrackerLeadActionHtml` (`tracker-actions.js`) | the row header's inline lead button (chip slot) | — (the lead sat in the ⋯ menu only) | the menu entry's label (1–4), its hint as the hover | `TestStageTrackerLeadActionInline`, `TestStageTrackerMaintainerRowsHaveLeadAction` | | Toasts (`STAGE_TRACKER_ACTING_CAPTIONS`, acted labels) | toast | 2–4 each | unchanged | — | +| `stageTrackerSelectionTriage` (`tracker-actions.js`) | selection bar lead button / bulk ⋯ menu entry, summary toast | — (no bulk Accept triage; one row at a time) | *Accept triage (4 selected)* / *Accept triage (2 of 4)* with the hint *skips the 2 not waiting on triage*; one toast *Accepted 4 issues* | `TestStageTrackerBulkAcceptTriage` | | Settings → Features → Auto-merge → "Merge only on current base" help (`renderGovFeatures`, `config-features.js`) and the Repos-tab override row / repo-card `current-base` chip ([#15335](https://github.com/hivecommons/hive/issues/15335)) | settingHelpMark popover, checkbox label, chip hover | — (new) | 56 (help), 5 (row label), 1 (chip) | `TestCurrentBaseSettingsMarkupNodeGuard` | ## Totals diff --git a/src/docs/dashboard-sections.md b/src/docs/dashboard-sections.md index 1d09f03f6e..376d6d2050 100644 --- a/src/docs/dashboard-sections.md +++ b/src/docs/dashboard-sections.md @@ -1155,7 +1155,7 @@ The row effect is reusable in the SPA as `celebrateRow(rowEl, {kind: 'merged' | The checkbox in a row's left gutter selects the row — and the checkbox in a nested PR sub-row's gutter selects that PR on its own, so one or more PRs under an issue can be picked without the issue or each other; **Shift+click** selects the range from the last clicked row (sub-rows are in the range order right after their issue), **Cmd/Ctrl+click** toggles, **Cmd/Ctrl+Shift+click** adds a range to what is selected; with a row focused, **Space** toggles it (Shift+Space extends). -Cmd/Ctrl- or Shift-clicking the row itself, away from its links, selects it too. A selection bar appears above the list with the count, **Clear**, and the same actions for the whole selection — *Decide…* (opens the group as a menu, *Let hive decide* first — each selected row gets its own delegated-decision job, see below), **Let hive decide (N selected)** (one click for the whole selection: one delegated-decision job per selected item, each nested PR sub-row by its own number, with one summary toast — "3 sent · 2 decided · 1 no-op", plus "· 1 failed" when any failed — and the per-action confirm / *Don't ask again* of *Let hive decide*), *Hold*, *Release hold*, *Re-evaluate now*, *Mark needs-human…*, *Copy links* — each enabled only when it is valid for every selected row and otherwise greyed with the first reason ("Not applicable to acme/console#12", "Sign in with write access…"). +Cmd/Ctrl- or Shift-clicking the row itself, away from its links, selects it too. A selection bar appears above the list with the count, **Clear**, and the same actions for the whole selection — **Accept triage (N selected)** when every selected row is an issue waiting on a maintainer's triage (015 *Triage needed*, the `needs-triage` chip, or a 000-new reporter-trust hold): it leads the bar as the same `ham-lead-act` button a single row shows and heads the bulk ⋯ menu; a mixed selection offers **Accept triage (k of N)** after *Decide…* with the hint *skips the N−k not waiting on triage*, and a selection with no such row does not offer it at all. One click posts the per-item `…/items/{number}/accept-triage` endpoint once per eligible row, in order (PRs and already-triaged issues are skipped, never posted), each row showing the same busy chevron and *Accepting triage…* → *Actionable* transition as a single Accept triage, with one summary toast *Accepted N issues* (*Accepted k of N issues. Failed: …* when any refused) — no new write path, the same gated label application as the row action; *Decide…* (opens the group as a menu, *Let hive decide* first — each selected row gets its own delegated-decision job, see below), **Let hive decide (N selected)** (one click for the whole selection: one delegated-decision job per selected item, each nested PR sub-row by its own number, with one summary toast — "3 sent · 2 decided · 1 no-op", plus "· 1 failed" when any failed — and the per-action confirm / *Don't ask again* of *Let hive decide*), *Hold*, *Release hold*, *Re-evaluate now*, *Mark needs-human…*, *Copy links* — each enabled only when it is valid for every selected row and otherwise greyed with the first reason ("Not applicable to acme/console#12", "Sign in with write access…"). Right-clicking a selected row acts on the whole selection. Bulk actions run one request per row, in list order, under a progress toast ("Hold 2/5 — acme/console#12…"); the result toast lists each failure by row and the successes stand, after which the list and the status snapshot refresh (a hive-wide rescan is sent once per batch). Selection is keyed on the row's item (repository, kind, number), not its node, so the live re-render keeps it; a row that leaves the list — merged, closed, filtered or paged out — leaves the selection. diff --git a/src/pkg/dashboard/stage_tracker_accept_triage_test.go b/src/pkg/dashboard/stage_tracker_accept_triage_test.go index 6f7b571fa8..54dea4bfd5 100644 --- a/src/pkg/dashboard/stage_tracker_accept_triage_test.go +++ b/src/pkg/dashboard/stage_tracker_accept_triage_test.go @@ -122,7 +122,7 @@ let refreshed = 0; function stageTrackerAfterActions() { refreshed++; } assert.strictEqual(_stageTracker.items[1].stage, 15, 'the refused row is left as it was'); assert.strictEqual(rendered, 1, 'one optimistic re-render for the success'); assert.strictEqual(refreshed, 1, 'then the usual refetch'); - assert.strictEqual(toasts[toasts.length - 1], 'done:error:Accept triage: 1/2 done. Failed: o/r#2 — write permission required', 'the failure is toasted, never a native dialog'); + assert.strictEqual(toasts[toasts.length - 1], 'done:error:Accepted 1 of 2 issues. Failed: o/r#2 — write permission required', 'the failure is toasted, never a native dialog'); })().catch(e => { console.error(e); process.exit(1); }); `) } diff --git a/src/pkg/dashboard/stage_tracker_row_actions_test.go b/src/pkg/dashboard/stage_tracker_row_actions_test.go index e34e8e5c81..84dd866ba5 100644 --- a/src/pkg/dashboard/stage_tracker_row_actions_test.go +++ b/src/pkg/dashboard/stage_tracker_row_actions_test.go @@ -100,6 +100,7 @@ func stageTrackerRowActionsPreamble(t *testing.T, html string) string { jsFunc(t, html, "stageTrackerMenuTextHtml"), jsFunc(t, html, "stageTrackerFlatActions"), jsFunc(t, html, "stageTrackerSelectionActions"), + jsFunc(t, html, "stageTrackerSelectionTriage"), jsFunc(t, html, "stageTrackerMenuItemHtml"), jsFunc(t, html, "stageTrackerMenuHasHints"), jsFunc(t, html, "stageTrackerMenuHtml"), @@ -1771,3 +1772,87 @@ global.fetch = async (url, init) => { })().catch(e => { console.error(e); process.exit(1); }); `) } + +// TestStageTrackerBulkAcceptTriage: the selection bar and the bulk ⋯ menu +// offer Accept triage for every selected issue waiting on triage at once +// (owner report: four "Triage needed" rows multi-selected, no Accept +// triage in the menu). It leads the bar when the whole selection is +// triage ("Accept triage (4 selected)"), counts out the rows it skips +// otherwise ("Accept triage (2 of 4)"), is greyed with the first reason +// when a viewer may not write, posts the per-item accept-triage endpoint +// once per eligible row in order, re-renders each as Actionable and sums +// up as one toast "Accepted N issues". +func TestStageTrackerBulkAcceptTriage(t *testing.T) { + html := indexHTML(t) + runStageTrackerRowActionsScript(t, stageTrackerRowActionsPreamble(t, html)+` +const ctx = { user: true, canHold: true, canHuman: true }; +const tri = n => ({ repo: 'o/r', kind: 'issue', number: n, url: 'u' + n, stage: 15, caption: 'Triage needed', modifiers: ['needs-triage'] }); +const t1 = tri(15437), t2 = tri(15438), t3 = tri(15439), t4 = tri(15440); +const plain = { repo: 'o/r', kind: 'issue', number: 7, url: 'u7', stage: 10, caption: 'Actionable', modifiers: [] }; +const pr = { repo: 'o/r', kind: 'pr', number: 8, url: 'u8', stage: 20, caption: 'Claimed', modifiers: [] }; + +// All four waiting on triage: Accept triage leads the selection. +const all = stageTrackerSelectionActions([t1, t2, t3, t4], () => ctx); +assert.strictEqual(all[0].id, 'accept-triage'); +assert.strictEqual(all[0].label, 'Accept triage (4 selected)'); +assert.strictEqual(all[0].enabled, true); +assert.strictEqual(all[0].lead, true, 'leads when every selected row waits on triage'); +assert.strictEqual(all[0].count, 4); +const bar = stageTrackerSelBarHtml([t1, t2, t3, t4], all); +assert.ok(bar.includes('class="ham-lead-act" data-action="hamSelAction" data-arg0="accept-triage"'), 'the bar renders it as the lead button: ' + bar); +assert.ok(bar.includes('>Accept triage (4 selected)<')); +const menu = stageTrackerMenuHtml(all, '4 selected'); +assert.ok(menu.indexOf('data-ham-act="accept-triage"') < menu.indexOf('data-ham-act="decide"'), 'the ⋯ menu offers it first'); + +// Mixed: a PR and an actionable issue in the selection are skipped and counted out. +const mixed = stageTrackerSelectionActions([t1, plain, t2, pr], () => ctx); +const mt = mixed.find(a => a.id === 'accept-triage'); +assert.ok(mt, 'offered when at least one selected row waits on triage'); +assert.strictEqual(mt.label, 'Accept triage (2 of 4)'); +assert.strictEqual(mt.hint, 'skips the 2 not waiting on triage'); +assert.strictEqual(mt.enabled, true); +assert.strictEqual(mt.lead, false, 'not the lead when some rows are skipped'); +assert.ok(mixed.indexOf(mt) > mixed.findIndex(a => a.id === 'decide'), 'sits after Decide… when it does not lead'); +assert.ok(stageTrackerSelBarHtml([t1, plain], mixed).includes('class="ham-chip" data-action="hamSelAction" data-arg0="accept-triage"'), 'a chip, not the lead button, when mixed'); + +// Nothing waiting on triage: not offered at all. +assert.ok(!stageTrackerSelectionActions([plain, pr], () => ctx).some(a => a.id === 'accept-triage')); + +// No write access: greyed with the reason, never hidden. +const denied = stageTrackerSelectionActions([t1, t2], () => ({ user: true, canHold: false, canHuman: false }))[0]; +assert.strictEqual(denied.id, 'accept-triage'); +assert.strictEqual(denied.enabled, false); +assert.ok(denied.why.includes('o/r#15437'), denied.why); + +// The run: one POST per eligible row, in order; skipped rows are not posted. +const calls = []; +global.fetch = async (url, init) => { calls.push(url); return { ok: true, status: 200, json: async () => ({ ok: true, result: { action: 'triage-accepted', target: { repo: 'o/r', kind: 'issue', number: Number(url.match(/items\/(\d+)/)[1]) }, outcome: 'accepted' } }) }; }; +const toasts = []; +global.showToast = (msg, type) => { toasts.push(type + ':' + msg); return null; }; global.dismissToast = () => {}; +function stageTrackerProgressToast() { return { update() {}, done(msg, type) { if (msg) toasts.push('summary:' + type + ':' + msg); } }; } +function stageTrackerAfterActions() {} +function stageTrackerNoteOwnerEvent() {} +// Accept triage asks nothing first (no dialog, native or in-app). +async function stageTrackerActionPayload(items, id) { assert.strictEqual(id, 'accept-triage'); return {}; } +_stageTracker = { items: [t1, plain, t2, pr] }; +(async () => { + const res = await runRowAction('accept-triage', [t1, plain, t2, pr]); + assert.deepStrictEqual(calls, ['/api/repos/o/r/items/15437/accept-triage', '/api/repos/o/r/items/15438/accept-triage'], 'only the rows waiting on triage are posted, each to the per-item endpoint'); + assert.strictEqual(res.results.length, 2); + assert.ok(res.results.every(r => r.ok)); + assert.strictEqual(_stageTracker.items[0].stage, 10, 'each accepted row re-reads Actionable at once'); + assert.strictEqual(_stageTracker.items[2].stage, 10); + assert.ok(toasts.includes('summary:success:Accepted 2 issues'), 'one summary toast: ' + JSON.stringify(toasts)); + + // Nothing eligible: a warning toast, no request. + calls.length = 0; toasts.length = 0; + await runRowAction('accept-triage', [plain, pr]); + assert.deepStrictEqual(calls, []); + assert.ok(toasts.some(x => x.startsWith('warning:Accept triage: nothing to act on')), JSON.stringify(toasts)); + + // The summary counts failures. + assert.strictEqual(stageTrackerActionSummary('Accept triage', [{ item: t1, ok: true }, { item: t2, ok: false, error: 'HTTP 403' }], 'accept-triage').msg, 'Accepted 1 of 2 issues. Failed: o/r#15438 — HTTP 403'); + assert.strictEqual(stageTrackerActionSummary('Accept triage', [{ item: t1, ok: true }, { item: t2, ok: true }, { item: t3, ok: true }, { item: t4, ok: true }], 'accept-triage').msg, 'Accepted 4 issues'); +})().catch(e => { console.error(e); process.exit(1); }); +`) +} diff --git a/src/pkg/dashboard/static-src/js/tracker-actions.js b/src/pkg/dashboard/static-src/js/tracker-actions.js index 9276163770..c4e5c2916f 100644 --- a/src/pkg/dashboard/static-src/js/tracker-actions.js +++ b/src/pkg/dashboard/static-src/js/tracker-actions.js @@ -525,9 +525,36 @@ // One click for the whole selection: each item is decided on its own // (a nested PR sub-row by its own number), summed up in one toast. out.push(Object.assign({}, submenu[0], { label: 'Let hive decide (' + items.length + ' selected)', hint: 'per item' })); + // Accept triage for every selected issue waiting on a maintainer's + // triage, one click (hivecommons/hive#15475: four "Triage needed" + // rows selected, no bulk Accept triage). Rows that are not — PRs, issues past 015 — + // are skipped, and the count says so ("3 of 4"). It leads the bar + // and the menu when the whole selection is triage, as on one row. + const triage = stageTrackerSelectionTriage(items, per); + if (triage) { if (triage.lead) out.unshift(triage); else out.push(triage); } for (const id of STAGE_TRACKER_SEL_ACTIONS) out.push(Object.assign({ id, label: STAGE_TRACKER_ACTION_LABELS[id] + (id === 'needs-human' ? '…' : id === 'copy' ? 's' : '') }, judge(id))); return out; } + // Pure: the selection's Accept triage entry, or null when no selected + // row is waiting on triage. `per` is the per-item flat action map + // stageTrackerSelectionActions built; enabled when every eligible row + // allows it (the first reason otherwise), `lead` when every selected + // row is eligible. + function stageTrackerSelectionTriage(items, per) { + const eligible = per.filter(p => p.flat['accept-triage']); + if (!eligible.length) return null; + const blocked = eligible.find(p => !p.flat['accept-triage'].enabled); + const all = eligible.length === items.length; + return { + id: 'accept-triage', + label: 'Accept triage (' + (all ? items.length + ' selected' : eligible.length + ' of ' + items.length) + ')', + hint: all ? 'per issue' : 'skips the ' + (items.length - eligible.length) + ' not waiting on triage', + enabled: !blocked, + why: blocked ? blocked.flat['accept-triage'].why + ' (' + stageTrackerRefOf(blocked.it) + ')' : '', + lead: all, + count: eligible.length, + }; + } function stageTrackerMenuItemHtml(a) { const dis = a.enabled ? '' : ` aria-disabled="true" title="${esc(a.why || '')}"`; if (a.submenu) { @@ -974,9 +1001,11 @@ } // Pure: the selection bar — count, Clear, and the shared actions // (disabled ones keep their tooltip, so aria-disabled rather than disabled). + // An entry flagged `lead` (Accept triage when every selected row waits + // on triage) renders as the row header's lead button, not a chip. function stageTrackerSelBarHtml(items, actions) { if (!items.length) return ''; - const btn = a => ``; + const btn = a => ``; return `${items.length} selected${actions.map(btn).join('')}`; } function stageTrackerRenderSelBar() { @@ -1040,12 +1069,14 @@ } return null; } - // Pure: one line for the result toast. + // Pure: one line for the result toast. A bulk Accept triage sums up as + // "Accepted 4 issues" (the per-row toasts carry the rest). function stageTrackerActionSummary(label, results, id) { const n = results.length; const fails = results.filter(r => !r.ok); const ok = n - fails.length; let msg = label + ': ' + (id === 'decide:delegate' || id === 'decide:delegate-all' ? stageTrackerDelegateTally(results) : ok + '/' + n + ' done'); + if (id === 'accept-triage' && n > 1) msg = 'Accepted ' + ok + (fails.length ? ' of ' + n : '') + ' issue' + (ok === 1 && !fails.length ? '' : 's'); const debounced = results.some(r => r.ok && r.data && (r.data.status === 'debounced' || r.data.status === 'in-progress')); if (debounced) msg += ' (a rescan was already running — the next one is queued by the hive)'; if (fails.length) { @@ -1917,6 +1948,12 @@ // Adopt now / Reroute act on the PR waiting on its contributor (072 / 071). items = items.map(stageTrackerTakeoverTarget).filter(Boolean); if (!items.length) return { toasts: [], pending: [] }; + } else if (id === 'accept-triage') { + // Accept triage acts on the issues waiting on it; a bulk selection + // may carry PRs or issues past 015, which are skipped and counted + // out in the menu label ("3 of 4"). + items = items.filter(stageTrackerTriageNeeded); + if (!items.length) { stageTrackerNothingToActOn(id, rows); return { toasts: [], pending: [] }; } } else if (id === 'decide:close-read') { // Close (read) acts on the advisory row itself: an advisory is not // a decision park, so it has no decision target diff --git a/src/pkg/dashboard/static/index.html b/src/pkg/dashboard/static/index.html index 0aa2513327..65a811e2e5 100644 --- a/src/pkg/dashboard/static/index.html +++ b/src/pkg/dashboard/static/index.html @@ -18803,9 +18803,36 @@