import { useMemo } from "react"; import { useIsServer } from "../../hooks"; import { useGleanClick } from "../../telemetry/glean-context"; import InternalLink from "../../ui/atoms/internal-link"; import { OBSERVATORY } from "../../telemetry/constants"; import { ReactComponent as StarsSVG } from "../../../public/assets/observatory/stars.svg"; import { ObservatoryResult, SCORING_TABLE } from "../types"; import { formatMinus, hostAsRedirectChain } from "../utils"; import { Tooltip } from "../tooltip"; import { RescanButton } from "./rescan-button"; import { HumanDuration } from "./human-duration"; export function ObservatoryRating({ result, host, rescanTrigger, }: { result: ObservatoryResult; host: string; rescanTrigger: () => void; }) { const gleanClick = useGleanClick(); const isServer = useIsServer(); const arrowState = useMemo(() => { const [oldScore, oldGrade] = result.history.length ? [result.history.at(-2)?.score, result.history.at(-2)?.grade] : [undefined, undefined]; const newScore = result.scan.score; const newGrade = result.scan.grade; if ( typeof newScore === "number" && typeof oldScore === "number" && newGrade !== oldGrade && newScore !== oldScore ) { return oldScore < newScore ? "up" : "down"; } else { return "none"; } }, [result.history, result.scan.grade, result.scan.score]); return ( <>

Scan summary:{" "} {hostAsRedirectChain(host, result)}

{formatMinus(result.scan.grade)}
{SCORING_TABLE.map((st) => { return ( ); })}
Score : <>{result.scan.score} / 100
Scan Time :{" "} {!isServer && ( )}
Tests Passed : {result.scan.tests_passed} /  {result.scan.tests_quantity}
{!isServer && ( )}
gleanClick(`${OBSERVATORY}: scan-another`)} > Scan another website
); } type ARROW_STATE = "up" | "down" | "none"; function Trend({ arrowState }: { arrowState: ARROW_STATE }) { switch (arrowState) { case "up": return (
{" "} since last scan
); case "down": return (
{" "} since last scan
); default: return []; } }