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(audit): give Site Audit's Pages list its own address and open it from the auto-audit e-mail (#1208)
Cihan67deb24f70ed
diff --git a/server/src/lib/audit/auto-audit-email.js b/server/src/lib/audit/auto-audit-email.jsindex 91176f1c0..2812bb15d 100644--- a/server/src/lib/audit/auto-audit-email.js+++ b/server/src/lib/audit/auto-audit-email.js@@ -46,7 +46,9 @@ export function renderAutoAuditEmail({ brands, nextRunAt }) {criticalIssues: brands.reduce((n, b) => n + b.criticalIssues, 0),};const failed = total.pages - total.completed;- const url = `${appOrigin()}/dashboard/audit`;+ // Pages, where the run's audits are, rather than the Opportunities list.+ const url = `${appOrigin()}/dashboard/audit?tab=pages`;+ const settingsUrl = `${appOrigin()}/dashboard/audit`;const brandItems =brands.length > 1@@ -71,7 +73,7 @@ export function renderAutoAuditEmail({ brands, nextRunAt }) {</div><p style="font-size:12px;color:#9ca3af;border-top:1px solid #e5e7eb;padding-top:16px;">You're receiving this because auto-audit e-mails are on in Site Audit settings.- <a href="${escapeHtml(url)}" style="color:#6b7280;">Change them</a>+ <a href="${escapeHtml(settingsUrl)}" style="color:#6b7280;">Change them</a></p></div>`;diff --git a/server/src/lib/audit/auto-audit-email.test.js b/server/src/lib/audit/auto-audit-email.test.jsindex 326345543..bb5476626 100644--- a/server/src/lib/audit/auto-audit-email.test.js+++ b/server/src/lib/audit/auto-audit-email.test.js@@ -12,7 +12,8 @@ describe('renderAutoAuditEmail', () => {});expect(subject).toBe('Site Audit: 25 pages audited · 6 critical issues');expect(html).toContain('25 pages audited · 6 critical issues · next run Oct 28');- expect(html).toContain('http://localhost:3000/dashboard/audit');+ // Open Site Audit lands on Pages, where the run's audits are.+ expect(html).toContain('href="http://localhost:3000/dashboard/audit?tab=pages"');// One brand: no per-brand list, nothing failed.expect(html).not.toContain('<ul');expect(html).not.toContain("couldn't");diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.test.ts b/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.test.tsnew file mode 100644index 000000000..d07a64070--- /dev/null+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.test.ts@@ -0,0 +1,22 @@+import { describe, expect, it } from 'vitest';+import { parseListTab, withListTab } from './_list-tab';++describe('parseListTab', () => {+ it('reads the two lists and nothing else', () => {+ expect(parseListTab('pages')).toBe('pages');+ expect(parseListTab('opportunities')).toBe('opportunities');+ expect(parseListTab(null)).toBeNull();+ expect(parseListTab('settings')).toBeNull();+ });+});++describe('withListTab', () => {+ it('sets the tab and keeps the rest of the address', () => {+ expect(withListTab('https://app.example.com/dashboard/audit', 'pages')).toBe(+ '/dashboard/audit?tab=pages',+ );+ expect(+ withListTab('https://app.example.com/tr/dashboard/audit?tab=pages&x=1#top', 'opportunities'),+ ).toBe('/tr/dashboard/audit?tab=opportunities&x=1#top');+ });+});diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.ts b/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.tsnew file mode 100644index 000000000..e66b1b237--- /dev/null+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/_list-tab.ts@@ -0,0 +1,18 @@+/**+ * The Site Audit hub's two lists, each with its own address (?tab=pages,+ * ?tab=opportunities), so a link can open one: the auto-audit e-mail opens+ * Pages, where the run's audits are.+ */+export type ListTab = 'opportunities' | 'pages';++/** The list an address asks for; null for none or another value. */+export function parseListTab(value: string | null): ListTab | null {+ return value === 'pages' || value === 'opportunities' ? value : null;+}++/** The address with `tab` set to the list, the rest of it kept. */+export function withListTab(href: string, tab: ListTab): string {+ const url = new URL(href);+ url.searchParams.set('tab', tab);+ return `${url.pathname}${url.search}${url.hash}`;+}diff --git a/web/src/app/[locale]/(dashboard)/dashboard/audit/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/audit/page.tsxindex 73690d223..e28d9f4b7 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/audit/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/audit/page.tsx@@ -17,6 +17,7 @@ import {Settings,} from 'lucide-react';import { useRouter } from '@/i18n/navigation';+import { useSearchParams } from 'next/navigation';import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';import { Button } from '@/components/ui/button';import { Input } from '@/components/ui/input';@@ -57,6 +58,7 @@ import { EmptyPoolMessage } from './_quota-meter';import { usePagesExport } from './_use-pages-export';import { nextAutoRun } from '@/lib/audit-auto-runs';import { cn } from '@/lib/utils';+import { parseListTab, withListTab, type ListTab } from './_list-tab';type RangePreset = '7d' | '30d' | '90d' | 'all';const RANGE_DAYS: Record<RangePreset, number | null> = { '7d': 7, '30d': 30, '90d': 90, all: null };@@ -64,8 +66,6 @@ const RANGE_DAYS: Record<RangePreset, number | null> = { '7d': 7, '30d': 30, '90/** Pages one bulk request may audit (the server's BULK_AUDIT_MAX). */const BULK_REQUEST_MAX = 50;-type ListTab = 'opportunities' | 'pages';-/** A tab's count, as the mockup's grey pill. */function TabCount({ count }: { count: number }) {return (@@ -126,14 +126,24 @@ export default function SiteAuditPage() {const { exporting, exportAll, exportPages } = usePagesExport(activeBrandId);// Capture "now" once (impure call belongs in a lazy initializer, not render).const [nowMs] = useState(() => Date.now());+ // A list the address names (?tab=pages, the auto-audit e-mail's link) opens+ // first on the brand the page opened with; another brand starts as usual.+ const searchParams = useSearchParams();+ const linked = useRef({ tab: parseListTab(searchParams.get('tab')), brandId: activeBrandId });const refetch = () => setRefreshKey((k: number) => k + 1);+ // The address follows the list shown, so it can be shared or reopened.+ const showList = (next: ListTab) => {+ setTab(next);+ window.history.replaceState(null, '', withListTab(window.location.href, next));+ };+// The run notice's View pages: the Pages list, latest audits first, so the// run's pages lead it (tagged Auto).const listsRef = useRef<HTMLDivElement>(null);const showPages = () => {- setTab('pages');+ showList('pages');listsRef.current?.scrollIntoView({ behavior: 'smooth', block: 'start' });};@@ -149,7 +159,9 @@ export default function SiteAuditPage() {// A selection, and the tab, belong to the brand they were made on.setSelected(new Set());setOppSelected(new Set());- setTab(null);+ // The store may only know the brand after the first render: that's the one it opened with.+ linked.current.brandId ??= activeBrandId;+ setTab(activeBrandId === linked.current.brandId ? linked.current.tab : null);setOpps(null);setLatestRun(null);(async () => {@@ -749,7 +761,7 @@ export default function SiteAuditPage() {<Tabsref={listsRef}value={tab ?? (oppsLoading ? 'opportunities' : 'pages')}- onValueChange={(v) => setTab(v as ListTab)}+ onValueChange={(v) => showList(v as ListTab)}><TabsList variant="line" aria-label={t('lists.label')}>{(opps || oppsLoading) && (