Files
Niklas Ye e6dd463915 Act on several incidents at once from the queue
A storm of alerts used to mean opening every incident to acknowledge it.
The queue now has a checkbox per row and a bar to acknowledge, snooze or
assign everything ticked, with an Undo on the confirmation.

On the server this is one POST per action under /api/incidents
(acknowledge, unacknowledge, snooze, unsnooze, assign), each taking up to
100 ids and answering per id: ok, noop, conflict (resolved) or not_found
(missing, or not in the caller's teams, which look the same on purpose).
Partial success rather than all-or-nothing, since one resolved incident in
a selection should not block the other nine.

Each incident runs in its own transaction, row-locked, so the update, the
escalation stop and the timeline event land together and carry the same
actor as the single-incident endpoints. Those are unchanged; only the
snooze time parsing moved into a helper both now use.

Resolve is left out of bulk deliberately: it is terminal, and a mis-ticked
row is hard to take back. Undoing a bulk assign restores the previous
assignee but cannot unassign, as no endpoint does that.

The snooze and assign sheets moved to js/pickers.js so the incident page
and the queue share them.
2026-11-04 10:37:49 +01:00

56 lines
2.3 KiB
JavaScript

// The snooze and assign sheets, shared by the incident page (one incident) and
// the queue's bulk bar (many). Each resolves with the choice, or null when the
// sheet is dismissed.
import * as api from './api.js';
import { h, icon, openSheet, closeSheet } from './ui.js';
import { initial } from './format.js';
import { myID, users } from './state.js';
import { withAvatar } from './avatar.js';
// pickSnooze resolves with a body for the snooze endpoints: { duration } or { until }.
export function pickSnooze() {
const tomorrow9 = new Date();
tomorrow9.setDate(tomorrow9.getDate() + 1);
tomorrow9.setHours(9, 0, 0, 0);
const options = [
['30 minutes', { duration: '30m' }],
['1 hour', { duration: '1h' }],
['2 hours', { duration: '2h' }],
['4 hours', { duration: '4h' }],
['8 hours', { duration: '8h' }],
['Until 09:00 tomorrow', { until: tomorrow9.toISOString() }],
];
return openSheet(() => [
h('h2', { class: 'sheet-title', text: 'Snooze' }),
h('p', { class: 'sheet-text', text: 'Hide it from the queue for a while. It comes back on its own.' }),
h('ul', { class: 'menu' }, options.map(([label, value]) =>
h('li', {}, h('button', { class: 'menu-item', type: 'button', onclick: () => closeSheet(value) },
icon('clock'), label)))),
]);
}
// pickAssignee resolves with a user id. currentID marks the present assignee,
// when there is exactly one to mark. Rejects if the people cannot be loaded.
export async function pickAssignee(currentID = null) {
const [list, onCall] = await Promise.all([users(), api.onCallNow()]);
const me = myID();
const sorted = [...list].sort((a, b) => (b.id === me) - (a.id === me) || a.username.localeCompare(b.username));
return openSheet(() => [
h('h2', { class: 'sheet-title', text: 'Assign to' }),
h('ul', { class: 'menu', role: 'menu' }, sorted.map((u) =>
h('li', {}, h('button', {
class: 'menu-item',
type: 'button',
role: 'menuitemradio',
'aria-checked': String(u.id === currentID),
onclick: () => closeSheet(u.id),
},
withAvatar(h('span', { class: 'avatar avatar-sm', text: initial(u.username) }), u.id),
u.id === me ? `${u.username} (you)` : u.username,
onCall && onCall.user_id === u.id ? h('span', { class: 'menu-sub', text: 'on call' }) : null,
)))),
]);
}