import React, { useEffect, useState } from 'react'; import { __, sprintf } from '@wordpress/i18n'; import { api } from '../api'; import { Card, Button, Badge, Notice, Tabs, PageState } from '../components/ui'; import { copyText } from '../copy'; import Webhooks from '../components/Webhooks'; function Status({ data, onMessage }) { const [busy, setBusy] = useState(null); const run = async (task) => { setBusy(task); try { const r = await api.post('/dev/maintenance', { task }); onMessage(r.message); } catch (e) { onMessage(e.message, true); } finally { setBusy(null); } }; const env = data.environment; const rows = [ [__('Plugin', 'ai-rank-suite'), sprintf(__('v%1$s · schema %2$s', 'ai-rank-suite'), env.plugin, env.db_schema)], ['WordPress', env.multisite ? sprintf(__('%s (multisite)', 'ai-rank-suite'), env.wordpress) : env.wordpress], ['PHP / MySQL', `${env.php} / ${env.mysql}`], [__('Theme', 'ai-rank-suite'), env.theme], [__('Memory limit', 'ai-rank-suite'), env.memory], [__('Locale', 'ai-rank-suite'), env.locale], [__('Pretty permalinks', 'ai-rank-suite'), env.permalinks ? __('✓ on', 'ai-rank-suite') : __('✕ off — required for llms.txt, sitemaps, IndexNow', 'ai-rank-suite')], ['HTTPS', env.ssl ? '✓' : '✕'], ['WP-Cron', data.constants.WP_CRON ? __('✓ running', 'ai-rank-suite') : __('✕ disabled — reports & answer simulations need a real cron', 'ai-rank-suite')], [__('Object cache', 'ai-rank-suite'), data.constants.OBJECT_CACHE ? __('✓ external', 'ai-rank-suite') : __('database (default)', 'ai-rank-suite')], ]; const report = [ ...rows.map(([k, v]) => `${k}: ${v}`), sprintf(__('Active modules: %s', 'ai-rank-suite'), data.modules.active.join(', ')), sprintf(__('Disabled: %s', 'ai-rank-suite'), data.modules.disabled.join(', ') || '—'), ...data.tables.map((t) => sprintf(__('%1$s: %2$s rows', 'ai-rank-suite'), t.name, t.rows)), ].join('\n'); const MAINTENANCE = [ { task: 'flush_transients', label: __('Clear plugin caches', 'ai-rank-suite'), hint: __('Drops every airanksuite_ transient — llms.txt, reports, rate limits', 'ai-rank-suite') }, { task: 'flush_rewrites', label: __('Rebuild rewrite rules', 'ai-rank-suite'), hint: __('Re-registers llms.txt, sitemaps and the IndexNow key file', 'ai-rank-suite') }, { task: 'rerun_migration', label: __('Re-run database migration', 'ai-rank-suite'), hint: __('Rebuilds tables idempotently — safe, takes a backup first', 'ai-rank-suite') }, { task: 'reanalyze_all', label: __('Reset all analyses', 'ai-rank-suite'), hint: __('Every page is re-scored on next access', 'ai-rank-suite') }, { task: 'clear_quarantine', label: __('Clear module quarantine', 'ai-rank-suite'), hint: __('Failed modules retry on the next load', 'ai-rank-suite') }, ]; // System status (~570px) and Maintenance (~480px) are comparable; Data // stacked under Maintenance made the right column ~450px taller than the // left, so the bottom-left third of the screen was blank. Two cards of // similar height in the row, Data full width beneath it in two columns — // the table has 9 short rows and does not need 900px of width for a table // name and a row count. return (
copyText(report)}>{__('Copy report', 'ai-rank-suite')} } >
{rows.map(([k, v]) => ( ))}
{k} {v}
{Object.keys(data.modules.quarantine).length > 0 && (
{sprintf(__('Quarantined modules: %s — check the error, then clear the quarantine.', 'ai-rank-suite'), Object.keys(data.modules.quarantine).join(', '))}
)}
{/* * Front-end faults. * * These are the failures nobody would otherwise find. A callback * of ours threw on a public page, the guard caught it so the * visitor got a working site, and with WP_DEBUG off on a * production install that is the end of the story — no error, * no white screen, nothing in any log. The page rendered; it * just quietly rendered without our tags on it. */} {(data.hook_faults || []).length > 0 && (
{data.hook_faults.map((f) => ( ))}
{__('Where', 'ai-rank-suite')} {__('Error', 'ai-rank-suite')} {__('Times', 'ai-rank-suite')}
{f.label}
{f.message}
{f.class} · {f.file}:{f.line}
{f.count}
{__('Send this to support as it is — the file and line are the whole diagnosis. Clearing the quarantine below also empties this list, so fix first and clear second.', 'ai-rank-suite')}
)}
{MAINTENANCE.map((m) => (
{m.label}
{m.hint}
))}
{/* items-start: a grid cell stretches its table, and a 2-row table stretched to a 7-row table's height spreads those two rows 120px apart. */}
{data.tables.map((t) => ( ))}
{__('Table', 'ai-rank-suite')} {__('Rows', 'ai-rank-suite')}
{t.name} {t.rows}
{data.crons.map((c) => ( ))}
{__('Scheduled job', 'ai-rank-suite')} {__('Next run', 'ai-rank-suite')}
{c.hook} {c.next || __('not scheduled', 'ai-rank-suite')}
); } /** * Which third-party plugins we can read from, and which are live here. * Answering "does this work with my stack?" without a support ticket. */ function Integrations() { const [rows, setRows] = useState(null); useEffect(() => { api.get('/integrations').then((r) => setRows(r.integrations)).catch(() => setRows([])); }, []); if (!rows) return {__('Loading…', 'ai-rank-suite')}; const active = rows.filter((r) => r.active); return (
{[...rows].sort((a, b) => Number(b.active) - Number(a.active)).map((r) => (
{r.active ? '✓' : '○'} {r.label}
{r.provides}
))}
); } function Hooks({ data }) { /* * Grouped by module, the way SEOPress groups by area — an agency looking * to bend the schema output should not have to scan the autopilot's hooks * to find it. The list itself is generated from the code that fires the * hooks (bin/hooks.php), so it cannot disagree with the plugin it ships in. */ const groups = []; const byModule = new Map(); (data.hooks || []).forEach((h) => { if (!byModule.has(h.module)) { byModule.set(h.module, []); groups.push(h.module); } byModule.get(h.module).push(h); }); return (
{groups.map((module) => ( {byModule.get(module).map((h) => ( ))} ))}
{__('Hook', 'ai-rank-suite')} {__('Type', 'ai-rank-suite')} {__('Arguments', 'ai-rank-suite')} {__('What it does', 'ai-rank-suite')}
{module}
{h.hook} {h.type} {h.args} {h.desc}

{__('Example:', 'ai-rank-suite')}add_filter( 'airanksuite/schema/graph', fn( $graph ) => [...$graph, $myNode] );

); } /** * REST console: the route catalogue, plus a "Try" that fires a real GET and * shows the live JSON. Only GET — a developer poking at the API wants to see * shapes, and a one-click DELETE in a reference table is how data goes * missing. Writes are documented, not offered. */ function Api({ data }) { const [filter, setFilter] = useState(''); const [live, setLive] = useState(null); // { route, status, ms, body } const [busy, setBusy] = useState(null); // The namespace root itself is in the list WordPress hands back; it is // index metadata, not one of our routes, and printed as an empty row. // The namespace root is index metadata WordPress adds, not one of ours. const all = data.routes.filter((r) => r.route !== '/airanksuite/v1'); const routes = all.filter((r) => !filter || r.route.toLowerCase().includes(filter.toLowerCase())); const runnable = (r) => r.methods.includes('GET') && !/\(\?P\d+)`. Nobody types that, and it is the widest * thing in the column. Show the placeholder the way documentation writes * it — the raw pattern stays in the title attribute for anyone who needs * the real expression. */ const pretty = (route) => route.replace(/^\/airanksuite\/v1/, '').replace(/\(\?P<([a-z_]+)>[^)]*\)/gi, '{$1}') || '/'; const tryRoute = async (r) => { setBusy(r.route); const path = r.route.replace(/^\/airanksuite\/v1/, ''); const started = performance.now(); try { const body = await api.get(path); setLive({ route: r.route, status: 200, ms: Math.round(performance.now() - started), body }); } catch (e) { setLive({ route: r.route, status: e.status || 'error', ms: Math.round(performance.now() - started), body: { error: e.message } }); } finally { setBusy(null); } }; /* * Side by side only when both halves can actually be read. * * At the lg breakpoint the admin sidebar leaves so little room that the * routes card was squeezed to about 190px and its subtitle broke one word * per line. Below xl the response panel sits underneath at full width. */ return (
setFilter(e.target.value)} style={{ minHeight: 30, width: 180 }} /> } flush > {/* Fits, so nothing scrolls sideways. A floor width on the table made the card wider than its grid column, and the whole page then scrolled horizontally — worse than the clipping it was meant to fix. The action column is now wide enough for the button on its own (96px against a 52px button and 16px of padding), so the table can simply be 100% of whatever space it gets and the route cell truncates. */}
{/* 96px, not 68: the cell carries 14px of padding on each side, so a 68px column left 40px for a 52px button and clipped it. The action column also drops its padding. */} {routes.map((r) => ( ))}
{__('Route', 'ai-rank-suite')} {__('Methods', 'ai-rank-suite')}
{pretty(r.route)}
{r.methods.map((m) => ( {m} ))}
{/* A route with an {id} placeholder cannot be called blind, and a write must not be fired from a documentation screen. Say which it is instead of leaving an unexplained gap. */} {!runnable(r) && ( {/\(\?P )} {runnable(r) && ( )}
copyText(JSON.stringify(live.body, null, 2))}>{__('Copy JSON', 'ai-rank-suite')} ) } > {live ? (
						{JSON.stringify(live.body, null, 2)}
					
) : (
{__('Nothing requested yet.', 'ai-rank-suite')}
)}
); } export default function DevTools({ tab = 'status', onTab }) { const [data, setData] = useState(null); const [message, setMessage] = useState(null); const [error, setError] = useState(null); const load = () => api.get('/dev/status').then(setData).catch((e) => setError(e.message)); useEffect(() => { load(); }, []); if (!data) return ; const onMessage = (msg, isError) => { setMessage({ msg, isError }); setTimeout(() => setMessage(null), 4000); if (!isError) load(); }; return (
{message && {message.msg}} {tab === 'status' && } {tab === 'integrations' && } {tab === 'hooks' && } {tab === 'webhooks' && } {tab === 'api' && window.airanksuiteData?.debug && }
); }