import React, { useEffect, useState } from 'react'; import { __, sprintf, _n } from '@wordpress/i18n'; import { api } from '../api'; import { Panel, MetricGrid, SectionTitle } from './ui'; /* * The sixteen-signal reference grid, moved off the dashboard (1.0 Phase 2). * * The dashboard opens on the verdict and the work queue; the full metric * inventory is reference, and reference lives with the analytics on the * Insights screen. Self-fetching, so any screen can mount it without * plumbing KPI state through its own props. */ const go = (hash) => { window.location.hash = hash; }; const dash = (v) => (v === null || v === undefined ? '–' : v); /** * A MetricGrid whose cells are destinations: `MetricGrid` hands back the * cell's id on click, so the route rides on the metric itself. */ function LaunchGrid({ metrics, columns = 4 }) { return ( { const m = metrics.find((x) => (x.id || x.label) === id); if (m && m.href) go(m.href); }} /> ); } export default function SiteMetricsPanel() { const [kpis, setKpis] = useState(null); const [setup, setSetup] = useState(null); const [content, setContent] = useState(null); useEffect(() => { api.get('/dashboard/kpis').then(setKpis).catch(() => {}); api.get('/setup/status').then(setSetup).catch(() => {}); api.get('/score/content').then(setContent).catch(() => {}); }, []); if (!kpis) return null; const k = kpis; const vis = k.visibility || {}; const search = k.search || {}; const links = k.links || {}; const idx = k.indexing || {}; const cnt = k.content || {}; const commerce = k.commerce || {}; const health = k.health || {}; return (
{__('AI search', 'ai-rank-suite')}
{__('Search', 'ai-rank-suite')}
{__('Content health', 'ai-rank-suite')} 0 ? 'var(--ars-accent)' : undefined, sub: sprintf(__('%s thin pages', 'ai-rank-suite'), content?.thin_content ?? 0), href: '/content/bulk', }, ]} />
{commerce.active ? __('Technical health & store', 'ai-rank-suite') : __('Technical health', 'ai-rank-suite')} 0 ? 'var(--ars-c-red-ink)' : undefined, sub: commerce.active ? sprintf(__('%1$s checked · %2$s redirected', 'ai-rank-suite'), (links.checked ?? 0).toLocaleString(), links.redirected ?? 0) : sprintf(__('%s links checked', 'ai-rank-suite'), (links.checked ?? 0).toLocaleString()), href: '/links/checker', }, { id: 'notfound', label: __('404 errors', 'ai-rank-suite'), hint: __('Requests that hit nothing. A redirect rule turns each one back into a page.', 'ai-rank-suite'), value: links.not_found ?? 0, accent: links.not_found > 0 ? 'var(--ars-accent)' : undefined, sub: sprintf(_n('%s redirect rule active', '%s redirect rules active', links.redirects ?? 0, 'ai-rank-suite'), (links.redirects ?? 0).toLocaleString()), href: '/links/redirects', }, ...(commerce.active ? [] : [ { id: 'redirected', label: __('Redirected links', 'ai-rank-suite'), hint: __('Links that only resolve after a redirect hop. Point them at the final URL and save the hop.', 'ai-rank-suite'), value: links.redirected ?? 0, href: '/links/checker', }, ]), { id: 'system', label: __('System', 'ai-rank-suite'), hint: __('Module health. A failing module is quarantined so it cannot take the site down; a second SEO plugin active means output may collide.', 'ai-rank-suite'), value: health.quarantined > 0 ? sprintf(__('%d failed', 'ai-rank-suite'), health.quarantined) : __('Healthy', 'ai-rank-suite'), accent: health.quarantined > 0 || health.conflict ? 'var(--ars-c-red-ink)' : undefined, sub: health.conflict ? `${health.conflict} also active` : `${health.modules ?? 0} modules running`, href: '/developer', }, ...(commerce.active ? [ { id: 'products', label: __('Products', 'ai-rank-suite'), hint: __('Published products carrying Product, Offer, Review and Shipping structured data.', 'ai-rank-suite'), value: commerce.products ?? 0, sub: 'schema-enriched', href: '/schema', }, { id: 'feed-google', label: __('Google Merchant feed', 'ai-rank-suite'), hint: __('The product feed Google Merchant Center reads. Built once, cached, served instantly.', 'ai-rank-suite'), value: dash(commerce.feed_google), unit: commerce.feed_google == null ? '' : 'items', sub: commerce.feed_google == null ? 'not built yet' : 'cached, served instantly', href: '/feeds', }, { id: 'feed-meta', label: __('Meta catalog feed', 'ai-rank-suite'), hint: __('The catalog feed Facebook & Instagram Shops read.', 'ai-rank-suite'), value: dash(commerce.feed_meta), unit: commerce.feed_meta == null ? '' : 'items', sub: commerce.feed_meta == null ? 'not built yet' : 'Facebook & Instagram Shops', href: '/feeds', }, ] : []), ]} />
); }