import React, { useEffect, useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Notice, Button } from './ui'; import { IconRefresh } from './icons'; /** * The full page report. * * Every other tab in this drawer answers part of the question. This one * answers the whole of it — is this page done? — as a single list of * requirements with a pass or a fail against each, weighted by how much each * one actually costs you. * * The weighting is why the number at the top is worth having. A missing meta * description and a missing twitter:card are not the same size of problem, and * a scorecard that averages them as if they were is a scorecard nobody should * act on. */ export default function ReportTab({ postId, onGoTo }) { const [data, setData] = useState(null); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); const [only, setOnly] = useState(false); const load = () => { setBusy(true); api .get(`/content/${postId}/report`) .then(setData) .catch((e) => setError(e.message)) .finally(() => setBusy(false)); }; useEffect(() => { setData(null); load(); // eslint-disable-next-line react-hooks/exhaustive-deps }, [postId]); if (error) return {error}; if (!data) return
{__('Checking every requirement…', 'ai-rank-suite')}
; const tone = data.score >= 85 ? 'green' : data.score >= 60 ? 'amber' : 'red'; const shown = only ? data.items.filter((i) => !i.pass) : data.items; return (
{data.score} %
{data.failed === 0 ? __('Everything checked out', 'ai-rank-suite') : sprintf(__('%1$s of %2$s requirements not met', 'ai-rank-suite'), data.failed, data.passed + data.failed)}

{sprintf(__('%1$s words · about %2$s min read · %3$s headings · %4$s images · %5$s internal and %6$s external links', 'ai-rank-suite'), data.words.toLocaleString(), data.reading, data.headings, data.images, data.internal, data.external)}

{sprintf(__('Weighted by consequence — %1$s of %2$s points. A missing description counts for more than a missing card type, because it costs more.', 'ai-rank-suite'), data.earned, data.possible)}

{/* * What the work did. * * Every number on this screen described the page as it is * now, which made an evening spent on it unprovable. This * is the first reading against the latest one, so a person * can see the thing they changed. It appears only once * there are two readings and the score actually moved: a * permanent "±0" is noise. */} {!!data.change && data.change.geo !== 0 && (

0 ? 'ars-c-green-ink' : 'ars-c-red-ink'} style={{ fontWeight: 600 }}> {data.change.geo > 0 ? `+${data.change.geo}` : data.change.geo} {' '} {sprintf( /* translators: 1: date of the first measurement, 2: number of measurements. */ _n('on the AI score since %1$s, over %2$s measurement.', 'on the AI score since %1$s, over %2$s measurements.', data.change.points, 'ai-rank-suite'), new Date(data.change.since * 1000).toLocaleDateString(), data.change.points )}

)}
{data.sections.map((section) => { const items = shown.filter((i) => i.section === section.id); if (items.length === 0) return null; const failed = items.filter((i) => !i.pass).length; return (
{section.label}
{section.note}
{/* The dots were a weight with no key anywhere on the screen — five of them next to one check and three next to another, explained only in a tooltip a phone cannot show. Said once per group instead. */} ●●● {__('= weight in the score', 'ai-rank-suite')} 0 ? ' is-bad' : ''}`}> {items.length - failed}/{items.length}
{items.map((item) => (
{item.pass ? '✓' : '✕'}
{item.label} {'●'.repeat(Math.min(5, item.weight))}

{item.detail}

{item.value && ( {item.value} )}
{/* Right edge on every row. It used to sit wherever the text above it ended, so in a column of five checks the one action jumped left and right. */} {!item.pass && onGoTo && FIXES[item.id] && ( )}
))}
); })} {only && data.failed === 0 && ( {__('Nothing failed. Untick the filter to see everything that passed.', 'ai-rank-suite')} )}
); } /** Which tab each failure is actually fixed on. */ const FIXES = { title: 'optimize', description: 'optimize', keyword: 'keywords', keyword_title: 'optimize', keyword_opening: 'checks', canonical: 'advanced', indexable: 'advanced', snippet_limit: 'advanced', schema: 'schema', faq: 'faq', og_image: 'preview', og_title: 'preview', tw_card: 'preview', llms: 'advanced', h1: 'checks', structure: 'checks', opening: 'checks', length: 'checks', alt: 'checks', };