Bulk close can close the osTicket tickets; Alerts top-level, Records group
Closing several alerts together can now also close their osTicket tickets (one by one, each written on its incident and in the audit log; one that fails does not stop the rest; Undo does not reopen tickets). The single and bulk close share one helper. Alerts moves to the top of the sidebar, and Monthly report and Change log move to a new Records group. Docs updated. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
215c0de8bf
commit
78822346b1
13 files changed
+234
-37
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { Fragment, useEffect, useMemo, useState } from "react";
|
||||
import { Link, useSearchParams } from "react-router-dom";
|
||||
import { api, type AlertCategory, type AlertItem, type AlertSeverity, type AlertsReport, type CurrentUser } from "../api/client";
|
||||
import { api, type AlertCategory, type BulkResult, type AlertItem, type AlertSeverity, type AlertsReport, type CurrentUser } from "../api/client";
|
||||
import { useSortable } from "../hooks/useSortable";
|
||||
import SortableTh from "../components/SortableTh";
|
||||
import { usePagination } from "../hooks/usePagination";
|
||||
@@ -61,6 +61,16 @@ const alertTabs = (view: "now" | "history" | "noise") => (
|
||||
/>
|
||||
);
|
||||
|
||||
/** What happened to the osTicket tickets when several alerts were closed with them, as a sentence to follow "N alerts closed." */
|
||||
function ticketSentence(t: BulkResult["tickets"]): string {
|
||||
if (!t) return "";
|
||||
const parts: string[] = [];
|
||||
if (t.closed > 0) parts.push(`${plural(t.closed, "osTicket ticket")} closed too — Undo opens the alerts again, not the tickets.`);
|
||||
if (t.alreadyClosed > 0) parts.push(`${plural(t.alreadyClosed, "ticket")} ${t.alreadyClosed === 1 ? "was" : "were"} already closed.`);
|
||||
if (t.failed.length > 0) parts.push(`${plural(t.failed.length, "ticket")} could not be closed (${t.failed[0].message}${t.failed.length > 1 ? "…" : ""}).`);
|
||||
return parts.length > 0 ? " " + parts.join(" ") : "";
|
||||
}
|
||||
|
||||
export default function Alerts({ user }: { user: CurrentUser }) {
|
||||
const [params] = useSearchParams();
|
||||
const view = params.get("view");
|
||||
@@ -186,6 +196,12 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
|
||||
const here = new Set((report?.alerts ?? []).map((a) => a.id));
|
||||
return [...picked].filter((id) => here.has(id));
|
||||
}, [picked, report]);
|
||||
// What the picked alerts have in osTicket: the tickets that can be closed from here, and how many more have one that cannot.
|
||||
const ticketsOfPicked = useMemo(() => {
|
||||
const ids = new Set(pickedIds);
|
||||
const withTicket = (report?.alerts ?? []).filter((a) => ids.has(a.id) && a.ticket?.number && !a.ticket.closedAt);
|
||||
return { closable: withTicket.filter((a) => a.ticket?.canClose).map((a) => a.ticket!.number as string), other: withTicket.filter((a) => !a.ticket?.canClose).length };
|
||||
}, [pickedIds, report]);
|
||||
const shownIds = useMemo(() => (sorted ?? []).filter((a) => !a.silenced).map((a) => a.id), [sorted]);
|
||||
const allShownPicked = shownIds.length > 0 && shownIds.every((id) => picked.has(id));
|
||||
function togglePicked(id: string) {
|
||||
@@ -239,8 +255,8 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
|
||||
setPicked(new Set());
|
||||
}
|
||||
}
|
||||
async function bulkClose(note: string | null) {
|
||||
const ok = await doBulk({ call: api.bulk.alerts, body: { action: "close", alertIds: pickedIds, note }, done: (r) => `${plural(r.changed, "alert")} closed.`, reload: afterBulk });
|
||||
async function bulkClose(note: string | null, closeTickets: boolean) {
|
||||
const ok = await doBulk({ call: api.bulk.alerts, body: { action: "close", alertIds: pickedIds, note, ...(closeTickets ? { closeTickets: true } : {}) }, done: (r) => `${plural(r.changed, "alert")} closed.${ticketSentence(r.tickets)}`, reload: afterBulk });
|
||||
if (ok) {
|
||||
setBulkForm(null);
|
||||
setPicked(new Set());
|
||||
@@ -653,7 +669,7 @@ function AlertsNow({ user, tabs }: { user: CurrentUser; tabs: React.ReactNode })
|
||||
</>
|
||||
)}
|
||||
{bulkForm === "ack" && <AckBulkDrawer count={pickedIds.length} onSubmit={bulkAck} onClose={() => setBulkForm(null)} />}
|
||||
{bulkForm === "close" && <CloseBulkDrawer count={pickedIds.length} onSubmit={bulkClose} onClose={() => setBulkForm(null)} />}
|
||||
{bulkForm === "close" && <CloseBulkDrawer count={pickedIds.length} tickets={ticketsOfPicked} onSubmit={bulkClose} onClose={() => setBulkForm(null)} />}
|
||||
{bulkForm === "snooze" && <SnoozeBulkDrawer count={pickedIds.length} onSubmit={bulkSnooze} onClose={() => setBulkForm(null)} />}
|
||||
{bulkForm === "silence" && <SilenceBulkDrawer noun={pickedIds.length === 1 ? "alert" : "alerts"} count={pickedIds.length} canSilenceDependents={false} onSubmit={bulkSilence} onClose={() => setBulkForm(null)} />}
|
||||
|
||||
|
||||
Reference in new issue
Block a user