);
}
/**
* The types worth putting in front of somebody.
*
* The library holds 77 and hides all of them equally: Article, Product and
* Recipe end up as grey chips in the third tab, so a customer looking for
* "does this do Product schema" concludes it does not. These twelve are the
* ones people come looking for, on the first screen, with the field count and
* whether they are already live.
*/
function RichResults() {
const [meta, setMeta] = useState(null);
useEffect(() => {
api.get('/schema/types').then(setMeta).catch(() => {});
}, []);
if (!meta?.featured?.length) return null;
return (
{/*
* Name and status wrap among themselves; the field
* count keeps its own column and never breaks. A
* single flex row put "12 fields" outside the card
* as soon as a translation ran long.
*/}
{__('Add any of them to a single page in', 'ai-rank-suite')}{__('Content → open a page → Schema', 'ai-rank-suite')}, or to a whole post type
under {__('Templates', 'ai-rank-suite')}. Every other type lives in the {__('Library', 'ai-rank-suite')} tab.
{data.conflict && !s.force_output && (
{data.conflict} already outputs structured data — AI Rank Suite defers automatically to avoid a
duplicate graph.
)}
✓ Saved}
>
update({ enabled: v })} label={__('Output JSON-LD', 'ai-rank-suite')} />
update({ org_name: e.target.value })}
/>
{data.conflict && (
update({ force_output: v })}
label={`Force output although ${data.conflict} is active (advanced)`}
/>
)}
{error && {error}}
{__('Generate FAQs per page in', 'ai-rank-suite')}{__('Content', 'ai-rank-suite')} → open a page → {__('FAQ', 'ai-rank-suite')}. Saved items appear in the
JSON-LD graph and can be rendered anywhere with the{' '}
[airanksuite_faq]
{' '}
shortcode.
{__('Pick at least one content type or term. A template with no scope is never applied — that is deliberate, so a half-finished rule can never blanket the whole site.', 'ai-rank-suite')}
)}
{__('Values', 'ai-rank-suite')}
{required.length > 0 &&
{required.map((f) => )}
}
{recommended.length > 0 && (
{recommended.map((f) => )}
)}
{rest.length > 0 && (
<>
{showRest &&
{rest.map((f) => )}
}
>
)}
Variables are replaced per page:{' '}
{Object.keys(meta.variables)
.slice(0, 6)
.map((v) => (
{v}
))}
{error && {error}}
{saved && ✓ Saved}
{/* With no templates the empty state below already offers this,
in a different colour and with a different label. One call to
action per screen. */}
{(picking || templates.length > 0) && (
)}
{dirty && (
)}
{__('Your pages already get Organization, WebSite, WebPage/Article, Breadcrumbs and FAQPage automatically. A template adds a richer type — Recipe, Event, Course, SoftwareApplication, JobPosting — to a whole group of pages at once.', 'ai-rank-suite')}
)}
{templates.map((t, i) => (
{
setTemplates(templates.map((x, j) => (j === i ? next : x)));
setDirty(true);
}}
onRemove={() => {
setTemplates(templates.filter((_, j) => j !== i));
setDirty(true);
}}
/>
))}
{dirty && {__('Nothing is live until you press “Save templates”.', 'ai-rank-suite')}}
);
}
/* ---------------------------------------------------------------- Products */
/**
* WooCommerce product schema. Lives here because it *is* structured data —
* a separate nav item for one card would only fragment the mental model.
*/
function Products() {
const [data, setData] = useState(null);
const [busy, setBusy] = useState(false);
const [saved, setSaved] = useState(false);
const [error, setError] = useState(null);
useEffect(() => {
api.get('/settings/woocommerce').then(setData).catch(() => setData({ active: false }));
}, []);
if (!data) return {__('Loading…', 'ai-rank-suite')};
if (data.active === false) {
return (
{__('WooCommerce is not active on this site, so there are no products to describe. Everything else on this page works regardless.', 'ai-rank-suite')}
{error && {error}}
update({ identifiers: v })}
label={__('Publish global identifiers (GTIN, EAN, UPC, ISBN, MPN)', 'ai-rank-suite')}
/>
{__('Read automatically from WooCommerce core and the common GTIN plugins — no re-entry needed. Without one of these Google rejects the product entirely.', 'ai-rank-suite')}
update({ return_policy: v })}
label={__('Publish a merchant return policy', 'ai-rank-suite')}
/>
{!!s.return_policy && (
update({ return_free: v })} label={__('Returns are free', 'ai-rank-suite')} />
)}
update({ reviews: v })}
label={__('Include up to five customer reviews in the markup', 'ai-rank-suite')}
/>
);
}
/* -------------------------------------------------------------------- Page */
export default function Schema({ tab = 'overview', onTab }) {
const [data, setData] = useState(null);
const [stats, setStats] = useState(null);
const [error, setError] = useState(null);
const loadStats = () =>
Promise.allSettled([api.get('/schema/templates'), api.get('/schema/live')]).then(([tpl, live]) => {
// Every field guarded: a template list that is not an array, or a
// live sample without `issues`, must not take the screen down.
const t = tpl.status === 'fulfilled' && tpl.value ? tpl.value : {};
const l = live.status === 'fulfilled' && live.value ? live.value : {};
const templates = Array.isArray(t.templates) ? t.templates : [];
const samples = Array.isArray(l.samples) ? l.samples : [];
setStats({
types: t.types && typeof t.types === 'object' ? Object.keys(t.types).length : null,
templates: templates.length,
active: templates.filter((x) => x && x.enabled).length,
emitted: Array.isArray(samples[0]?.types) ? samples[0].types.length : 0,
issues: samples.reduce((a, x) => a + (Array.isArray(x?.issues) ? x.issues.length : 0), 0),
});
});
useEffect(() => {
api.get('/settings/schema').then(setData).catch((e) => setError(e.message));
loadStats();
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
if (!data) return ;
// The settings, under the name every tab below uses. This line was
// missing: the verdict referenced `s` that only the tabs declared, and the
// whole screen threw before it drew a pixel.
const s = data.settings || {};
// Schema is only worth anything if it names who you are; the organisation
// is the root every other block hangs from.
const named = !!(s.org_name && String(s.org_name).trim());
const verdict = data.conflict && !s.force_output
? {
tone: 'neutral',
text: sprintf(__('%s is already writing structured data, so this plugin steps back.', 'ai-rank-suite'), data.conflict),
why: __('Two schema graphs on one page contradict each other. If you would rather this plugin owned it, force output below and switch it off in the other one.', 'ai-rank-suite'),
}
: !s.enabled
? {
tone: 'warning',
text: __('Structured data is switched off — pages say nothing machine-readable about themselves.', 'ai-rank-suite'),
why: __('Schema is how a page tells Google and an assistant what it is: an article, a product, a business. Without it they guess.', 'ai-rank-suite'),
}
: !named
? {
tone: 'warning',
text: __('Schema is on but the organisation has no name.', 'ai-rank-suite'),
why: __('Every block references the site\'s identity. An unnamed one is a graph with a hole at the root — fill in the identity first.', 'ai-rank-suite'),
action: __('Open identity', 'ai-rank-suite'),
onAction: () => onTab && onTab('identity'),
}
: {
tone: 'good',
text: sprintf(__('Structured data is live for %s.', 'ai-rank-suite'), s.org_name),
why: __('The preview below is exactly what a crawler reads. Check it whenever the identity or the templates change.', 'ai-rank-suite'),
};
return (