import { AlertCircle, ChevronDown, TriangleAlert } from "lucide-react";
import { RowStatus } from "../../../components/ui/row-meta.tsx";
import { Alert, AlertDescription } from "../../../components/ui/alert.tsx";
import { useUnreviewedResults, type UnreviewedResult } from "../../../hooks/useUnreviewedResults.ts";
import "../BenchPage/QualityControlStrip.css";
import "./UnreviewedResults.css";
// RESULTS NOBODY HAS ACKNOWLEDGED, counted, aged, and marked where nobody is named.
//
// NOT BECAUSE THEY WERE HIDDEN. The queue below lists the same orders and already tells a result
// received apart from one reviewed. What it does not do is count them, say how long they have sat,
// or say which of them no clinician will ever be prompted about -- and on staging that was half.
//
// SILENT WHEN THERE IS NOTHING, and that is a decision rather than a shortcut. A banner that says
// "all clear" on every page load is noise people learn to scroll past, and the one page load where
// it mattered would look the same as the hundred before it. It also never renders before the answer
// arrives: the hook holds `undefined` until then, because "nothing is waiting" printed over a list
// that has not loaded is the exact false all-clear this screen exists to prevent.
//
// THE ROWS NOBODY OWNS COME FIRST AND ARE MARKED. Everything else here will also reach somebody's
// own screen and prompt them; these will prompt nobody, ever, and a practice reading the list needs
// to know which is which. Measured on staging, they were half of them.
//
// IT DOES NOT OFFER TO ACKNOWLEDGE FROM HERE. Acknowledging means reading the result, and a control
// that cleared the row from a summary line would let somebody empty this list without opening one.
const dayCount = (when?: string): number | undefined => {
if (!when) return undefined;
const at = new Date(when);
if (Number.isNaN(at.getTime())) return undefined;
return Math.floor((Date.now() - at.getTime()) / 86400000);
};
/** How long it has been sitting, which is the thing that makes a row urgent rather than merely open. */
const waitingFor = (when?: string): string | undefined => {
const days = dayCount(when);
if (days === undefined || days < 0) return undefined;
// "Waiting today" is not a sentence. Anything under a day is said as such.
if (days === 0) return "less than a day";
if (days === 1) return "1 day";
return `${days} days`;
};
const rowKey = (row: UnreviewedResult, at: number) => row.orderId ?? `row-${at}`;
const UnreviewedResults = () => {
const { results, unassigned, truncated, error } = useUnreviewedResults();
if (error) {
return (
The search stopped before it reached the end, so this list is incomplete and more results may be waiting.
) : null; if (results.length === 0) { if (!truncated) return null; return ({unassigned > 0 ? `${atLeast}${unassigned} of these ${unassigned === 1 ? "is" : "are"} not on anybody's own ` + "list, so nobody will be prompted about them." : "Each of these is also on the list of whoever ordered it."}
{[ waitingFor(row.authoredOn) ? `Waiting ${waitingFor(row.authoredOn)}` : undefined, row.requesterDisplay ? `Ordered by ${row.requesterDisplay}` : "No orderer recorded", ].filter(Boolean).join(" ยท ")}