Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat(content): open the Plan's "What AI cites in your topics" closed (#1330)
Cihan90665cedcd58
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 86322fa71..3ae5e0be3 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -3115,6 +3115,9 @@},"mix": {"title": "What AI cites in your topics",+ "collapsed": "{types, plural, one {# page type} other {# page types}} · {gaps, plural, =0 {no gap} one {# gap} other {# gaps}}",+ "show": "Show",+ "hide": "Hide","aiShare": "Share of AI citations","yourShare": "Your pages' mix","shares": "{ai}% · {yours}%",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsxindex d9896d627..ad7bcbef5 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/_plan-insights.tsx@@ -1,7 +1,8 @@'use client';+import { useId, useState } from 'react';import { useTranslations } from 'next-intl';-import { Sparkles } from 'lucide-react';+import { ChevronDown, Sparkles } from 'lucide-react';import { Link } from '@/i18n/navigation';import type { PageType } from '@/lib/content/drafts';import type { MixRow, PlanResults } from '@/lib/content/plan-mix';@@ -103,71 +104,101 @@ export function PageTypeMix({}) {const t = useTranslations('contentEditor.plan.mix');const tTypes = useTranslations('contentEditor.pageTypes');+ // Closed until opened, as Tracked Prompts' usage header: the list is the+ // page's work. Kept mounted while closed, so it opens at once.+ const [open, setOpen] = useState(false);+ const bodyId = useId();// The largest share, AI's or the brand's, fills the track; the others are// drawn to its scale, so neither bar runs past it.const scale = Math.max(1, ...rows.map((r) => Math.max(r.aiShare, r.yourShare)));+ const gaps = rows.filter((r) => r.gap).length;return (- <section aria-labelledby="plan-mix-title" className="space-y-2">- <div className="flex flex-wrap items-baseline justify-between gap-2">- <h2 id="plan-mix-title" className="text-sm font-medium">- {t('title')}- </h2>- <span className="flex items-center gap-3 text-xs text-muted-foreground">- <span className="flex items-center gap-1.5">- <span aria-hidden className="h-2 w-2 rounded-sm bg-muted-foreground/40" />- {t('aiShare')}+ <section aria-labelledby="plan-mix-title" className="overflow-hidden rounded-xl border bg-card">+ {/* The whole bar opens it: "Show" and a chevron pointing down say so. */}+ <h2 className="text-sm font-medium">+ <button+ type="button"+ aria-expanded={open}+ aria-controls={bodyId}+ onClick={() => setOpen((o) => !o)}+ className="group flex w-full cursor-pointer flex-wrap items-center gap-x-2.5 gap-y-1 px-4 py-2.5 text-left transition-colors hover:bg-muted/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring/50"+ >+ <span id="plan-mix-title">{t('title')}</span>+ {!open && rows.length > 0 && (+ <span className="text-xs font-normal text-muted-foreground">+ {t('collapsed', { types: rows.length, gaps })}+ </span>+ )}+ <span className="ml-auto flex items-center gap-1 text-xs font-medium text-foreground group-hover:underline">+ {open ? t('hide') : t('show')}+ <ChevronDown+ aria-hidden+ className={cn('h-4 w-4 shrink-0 transition-transform', open && 'rotate-180')}+ /></span>- <span className="flex items-center gap-1.5">- <span aria-hidden className="h-2 w-2 rounded-sm bg-foreground" />- {t('yourShare')}- </span>- </span>- </div>- {rows.length === 0 ? (- <p className="rounded-xl border px-4 py-3 text-sm text-muted-foreground">{t('empty')}</p>- ) : (- <ul className="divide-y rounded-xl border">- {rows.map((row) => (- <li key={row.pageType}>- <button- type="button"- aria-pressed={selected === row.pageType}- onClick={() => onSelect(selected === row.pageType ? null : row.pageType)}- className={cn(- 'grid w-full grid-cols-[minmax(0,10rem)_1fr_auto] items-center gap-3 px-4 py-2 text-left text-sm transition-colors hover:bg-muted/40 sm:grid-cols-[minmax(0,12rem)_1fr_5.5rem_8rem]',- selected === row.pageType && 'bg-muted/60',- )}- >- <span className="truncate">{tTypes(row.pageType)}</span>- <MixBars aiShare={row.aiShare} yourShare={row.yourShare} scale={scale} />- <span className="text-right text-xs tabular-nums text-muted-foreground">- {t('shares', { ai: row.aiShare, yours: row.yourShare })}- {/* On a phone the gap goes under the shares. */}- {row.gap && (- <span className="block font-medium text-amber-700 sm:hidden dark:text-amber-400">- {t('gap', { count: row.pages })}- </span>- )}- </span>- <span+ </button>+ </h2>+ <div id={bodyId} className={cn('border-t', !open && 'hidden')}>+ {rows.length > 0 && (+ <div className="flex flex-wrap items-center justify-end gap-3 px-4 pt-2.5 pb-1 text-xs text-muted-foreground">+ <span className="flex items-center gap-1.5">+ <span aria-hidden className="h-2 w-2 rounded-sm bg-muted-foreground/40" />+ {t('aiShare')}+ </span>+ <span className="flex items-center gap-1.5">+ <span aria-hidden className="h-2 w-2 rounded-sm bg-foreground" />+ {t('yourShare')}+ </span>+ </div>+ )}+ {rows.length === 0 ? (+ <p className="px-4 py-3 text-sm text-muted-foreground">{t('empty')}</p>+ ) : (+ <ul className="divide-y">+ {rows.map((row) => (+ <li key={row.pageType}>+ <button+ type="button"+ aria-pressed={selected === row.pageType}+ onClick={() => onSelect(selected === row.pageType ? null : row.pageType)}className={cn(- 'hidden text-right text-xs sm:block',- row.gap- ? 'font-medium text-amber-700 dark:text-amber-400'- : 'text-muted-foreground',+ 'grid w-full grid-cols-[minmax(0,10rem)_1fr_auto] items-center gap-3 px-4 py-2 text-left text-sm transition-colors hover:bg-muted/40 sm:grid-cols-[minmax(0,12rem)_1fr_5.5rem_8rem]',+ selected === row.pageType && 'bg-muted/60',)}>- {row.gap ? t('gap', { count: row.pages }) : t('pages', { count: row.pages })}- </span>- </button>- </li>- ))}- </ul>- )}- {rows.length > 0 && covered < 100 && (- <p className="text-xs text-muted-foreground">{t('covered', { pct: covered })}</p>- )}+ <span className="truncate">{tTypes(row.pageType)}</span>+ <MixBars aiShare={row.aiShare} yourShare={row.yourShare} scale={scale} />+ <span className="text-right text-xs tabular-nums text-muted-foreground">+ {t('shares', { ai: row.aiShare, yours: row.yourShare })}+ {/* On a phone the gap goes under the shares. */}+ {row.gap && (+ <span className="block font-medium text-amber-700 sm:hidden dark:text-amber-400">+ {t('gap', { count: row.pages })}+ </span>+ )}+ </span>+ <span+ className={cn(+ 'hidden text-right text-xs sm:block',+ row.gap+ ? 'font-medium text-amber-700 dark:text-amber-400'+ : 'text-muted-foreground',+ )}+ >+ {row.gap ? t('gap', { count: row.pages }) : t('pages', { count: row.pages })}+ </span>+ </button>+ </li>+ ))}+ </ul>+ )}+ {rows.length > 0 && covered < 100 && (+ <p className="border-t px-4 py-2.5 text-xs text-muted-foreground">+ {t('covered', { pct: covered })}+ </p>+ )}+ </div></section>);}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsxindex 00b8d91da..e93b209cf 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/plan/page.test.tsx@@ -278,6 +278,24 @@ describe('the Content plan', () => {);});+ it('opens the mix closed, with its count, and opens it on a click', async () => {+ await renderPage();+ const mix = container.querySelector('section[aria-labelledby="plan-mix-title"]')!;+ const toggle = mix.querySelector<HTMLButtonElement>('h2 button')!;+ expect(toggle.getAttribute('aria-expanded')).toBe('false');+ // The whole bar is the button, and says it opens.+ expect(toggle.textContent).toBe('What AI cites in your topics2 page types · 1 gapShow');+ expect(mix.textContent).toContain('2 page types · 1 gap');+ const body = document.getElementById(toggle.getAttribute('aria-controls')!)!;+ expect(body.className).toContain('hidden');++ await act(async () => toggle.click());+ expect(toggle.getAttribute('aria-expanded')).toBe('true');+ expect(toggle.textContent).toBe('What AI cites in your topicsHide');+ expect(body.className).not.toContain('hidden');+ expect(mix.textContent).not.toContain('2 page types · 1 gap');+ });+it('draws both shares to the larger one’s scale, never past the track', async () => {await renderPage();const widths = (bar: 'ai' | 'yours') =>@@ -312,7 +330,7 @@ describe('the Content plan', () => {await renderPage();const guide = () =>container.querySelector<HTMLButtonElement>(- 'section[aria-labelledby="plan-mix-title"] button',+ 'section[aria-labelledby="plan-mix-title"] li button',)!;await act(async () => guide().click());expect(guide().getAttribute('aria-pressed')).toBe('true');@@ -344,7 +362,7 @@ describe('the Content plan', () => {await renderPage();const guide = () =>container.querySelector<HTMLButtonElement>(- 'section[aria-labelledby="plan-mix-title"] button',+ 'section[aria-labelledby="plan-mix-title"] li button',)!;await act(async () => guide().click());await act(async () => button('Overlaps').click());