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(action-center): say on the Action Center when a brand's first analysis is running (#1248)
Cihan8550b59fd454
diff --git a/web/messages/en.json b/web/messages/en.jsonindex 252241f4a..3d58607af 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -82,6 +82,14 @@"signals": "Signals","history": "History"},+ "firstRun": {+ "running": "First analysis running",+ "queued": "First analysis queued",+ "progress": "{current} of {total} answers",+ "runningBody": "AI assistants are answering your prompts for the first time. Actions, signals and KPIs fill in once it finishes: a few minutes, or an hour or two at busy times. You can leave this page.",+ "queuedBody": "Another analysis is running right now. Yours starts the moment a slot opens, and keeps going in the background.",+ "link": "Follow it on Visibility"+ },"pages": {"actions": "What should you do now, ranked by your KPI goals.","signals": "What changed across your AI visibility data.",diff --git a/web/src/components/action-center/action-center-tabs.tsx b/web/src/components/action-center/action-center-tabs.tsxindex 0f9ff53ac..bd3ac1b65 100644--- a/web/src/components/action-center/action-center-tabs.tsx+++ b/web/src/components/action-center/action-center-tabs.tsx@@ -7,11 +7,13 @@ import { useBrandStore } from '@/stores/use-brand-store';import { getNewSignalCount } from '@/lib/actions/signals';import { cn } from '@/lib/utils';import { ACTION_CENTER_TABS } from '@/lib/action-center/tabs';+import { FirstRunNote } from './first-run-note';/*** The Action Center's section nav: Actions | Signals | KPIs | History.* Route-backed rather than state-backed tabs so each section is linkable- * and the browser back button works across them.+ * and the browser back button works across them. The first run's note sits+ * under it while a new brand's first analysis goes on.*/export function ActionCenterTabs() {const pathname = usePathname();@@ -35,30 +37,34 @@ export function ActionCenterTabs() {}, [brandId, pathname]);return (- <nav className="flex gap-6 border-b" aria-label={t('label')}>- {ACTION_CENTER_TABS.map((tab) => {- const isActive = pathname.startsWith(tab.href);- return (- <Link- key={tab.key}- href={tab.href}- aria-current={isActive ? 'page' : undefined}- className={cn(- '-mb-px border-b-2 pb-2 text-sm font-medium transition-colors',- isActive- ? 'border-foreground text-foreground'- : 'border-transparent text-muted-foreground hover:text-foreground',- )}- >- {t(tab.key)}- {tab.key === 'signals' && newSignals > 0 && (- <span className="ml-1.5 rounded-full bg-blue-500/10 px-1.5 py-0.5 text-[10px] font-medium text-blue-600 dark:text-blue-400">- {newSignals}- </span>- )}- </Link>- );- })}- </nav>+ <>+ <nav className="flex gap-6 border-b" aria-label={t('label')}>+ {ACTION_CENTER_TABS.map((tab) => {+ const isActive = pathname.startsWith(tab.href);+ return (+ <Link+ key={tab.key}+ href={tab.href}+ aria-current={isActive ? 'page' : undefined}+ className={cn(+ '-mb-px border-b-2 pb-2 text-sm font-medium transition-colors',+ isActive+ ? 'border-foreground text-foreground'+ : 'border-transparent text-muted-foreground hover:text-foreground',+ )}+ >+ {t(tab.key)}+ {tab.key === 'signals' && newSignals > 0 && (+ <span className="ml-1.5 rounded-full bg-blue-500/10 px-1.5 py-0.5 text-[10px] font-medium text-blue-600 dark:text-blue-400">+ {newSignals}+ </span>+ )}+ </Link>+ );+ })}+ </nav>+ {/* Under the tabs on every section: they all fill in from the first run. */}+ <FirstRunNote />+ </>);}diff --git a/web/src/components/action-center/first-run-note.test.tsx b/web/src/components/action-center/first-run-note.test.tsxnew file mode 100644index 000000000..ee63bf873--- /dev/null+++ b/web/src/components/action-center/first-run-note.test.tsx@@ -0,0 +1,161 @@+import { act } from 'react';+import { createRoot, type Root } from 'react-dom/client';+import { NextIntlClientProvider } from 'next-intl';+import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';+import messages from '../../../messages/en.json';+import type { TrackingJobStatus, TrackingWindow } from '@/lib/actions/tracking';++/**+ * The Action Center's "First analysis running" note (#1238's review): people+ * land on Actions while a new brand's first run goes on, and only Visibility+ * showed it.+ */++const { getTrackingWindow, getJobStatus, loadTrackingJob, store } = vi.hoisted(() => ({+ getTrackingWindow: vi.fn(),+ getJobStatus: vi.fn(),+ loadTrackingJob: vi.fn(),+ store: { brandId: 'b1' as string | null },+}));+vi.mock('@/lib/actions/tracking', () => ({ getTrackingWindow, getJobStatus }));+vi.mock('@/lib/tracking-job-store', () => ({ loadTrackingJob }));+vi.mock('@/stores/use-brand-store', () => ({+ useBrandStore: (selector: (state: { activeBrandId: string | null }) => unknown) =>+ selector({ activeBrandId: store.brandId }),+}));+vi.mock('@/i18n/navigation', () => ({+ Link: ({ href, ...props }: { href: string }) => <a href={href} {...props} />,+}));++const { FirstRunNote } = await import('./first-run-note');++(globalThis as typeof globalThis & { IS_REACT_ACT_ENVIRONMENT: boolean }).IS_REACT_ACT_ENVIRONMENT =+ true;++const win = (over: Partial<TrackingWindow> = {}): TrackingWindow => ({+ anchored: null,+ activeRun: null,+ lastRunAt: null,+ nextRunAt: null,+ ...over,+});+const job = (over: Partial<TrackingJobStatus> = {}): TrackingJobStatus => ({+ status: 'active',+ progress: null,+ result: null,+ failedReason: null,+ ...over,+});++let container: HTMLDivElement;+let root: Root;++async function render() {+ await act(async () => {+ root.render(+ <NextIntlClientProvider locale="en" messages={messages} timeZone="UTC">+ <FirstRunNote />+ </NextIntlClientProvider>,+ );+ });+}+const text = () => container.textContent ?? '';++beforeEach(() => {+ vi.useFakeTimers();+ getTrackingWindow.mockReset().mockResolvedValue(win());+ getJobStatus.mockReset().mockResolvedValue(job());+ loadTrackingJob.mockReset().mockReturnValue(null);+ store.brandId = 'b1';+ container = document.createElement('div');+ document.body.appendChild(container);+ root = createRoot(container);+});++afterEach(() => {+ act(() => root.unmount());+ container.remove();+ vi.useRealTimers();+});++describe('FirstRunNote', () => {+ it("says the first analysis is running from the ledger, whoever's browser started it", async () => {+ getTrackingWindow.mockResolvedValue(+ win({ activeRun: { startedAt: '2026-10-20T09:00:00Z', source: 'manual' } }),+ );+ await render();+ expect(text()).toContain('First analysis running');+ expect(text()).toContain('Actions, signals and KPIs fill in once it finishes');+ expect(container.querySelector('a')?.getAttribute('href')).toBe('/dashboard/insights');+ expect(getJobStatus).not.toHaveBeenCalled();+ });++ it("says it's queued before the worker starts it, from the job this browser saved", async () => {+ loadTrackingJob.mockReturnValue({ jobId: 'j1', brandId: 'b1', startedAt: 1 });+ getJobStatus.mockResolvedValue(job({ status: 'waiting' }));+ await render();+ expect(getJobStatus).toHaveBeenCalledWith('j1');+ expect(text()).toContain('First analysis queued');+ expect(text()).toContain('Yours starts the moment a slot opens');+ });++ it("shows the saved job's progress while it runs", async () => {+ getTrackingWindow.mockResolvedValue(+ win({ activeRun: { startedAt: '2026-10-20T09:00:00Z', source: 'manual' } }),+ );+ loadTrackingJob.mockReturnValue({ jobId: 'j1', brandId: 'b1', startedAt: 1 });+ getJobStatus.mockResolvedValue(job({ progress: { current: 12, total: 40 } }));+ await render();+ expect(text()).toContain('First analysis running12 of 40 answers');+ });++ it('shows nothing once the brand has a completed run, and stops reading', async () => {+ getTrackingWindow.mockResolvedValue(+ win({+ lastRunAt: '2026-10-19T09:00:00Z',+ activeRun: { startedAt: '2026-10-20T09:00:00Z', source: 'cron' },+ }),+ );+ await render();+ expect(text()).toBe('');+ await act(async () => {+ await vi.advanceTimersByTimeAsync(120_000);+ });+ expect(getTrackingWindow).toHaveBeenCalledTimes(1);+ });++ it("ignores another brand's saved job, and one that failed", async () => {+ loadTrackingJob.mockReturnValue({ jobId: 'j1', brandId: 'b2', startedAt: 1 });+ await render();+ expect(text()).toBe('');+ expect(getJobStatus).not.toHaveBeenCalled();++ loadTrackingJob.mockReturnValue({ jobId: 'j2', brandId: 'b1', startedAt: 1 });+ getJobStatus.mockResolvedValue(job({ status: 'failed', failedReason: 'boom' }));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(30_000);+ });+ expect(getJobStatus).toHaveBeenCalledWith('j2');+ expect(text()).toBe('');+ });++ it('keeps the note through a failed read, and goes when the first run is done', async () => {+ getTrackingWindow.mockResolvedValueOnce(+ win({ activeRun: { startedAt: '2026-10-20T09:00:00Z', source: 'manual' } }),+ );+ await render();+ expect(text()).toContain('First analysis running');++ getTrackingWindow.mockRejectedValueOnce(new Error('timeout'));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(30_000);+ });+ expect(text()).toContain('First analysis running');++ getTrackingWindow.mockResolvedValueOnce(win({ lastRunAt: '2026-10-20T09:40:00Z' }));+ await act(async () => {+ await vi.advanceTimersByTimeAsync(30_000);+ });+ expect(text()).toBe('');+ });+});diff --git a/web/src/components/action-center/first-run-note.tsx b/web/src/components/action-center/first-run-note.tsxnew file mode 100644index 000000000..07ecc2304--- /dev/null+++ b/web/src/components/action-center/first-run-note.tsx@@ -0,0 +1,105 @@+'use client';++import { useEffect, useState } from 'react';+import { useTranslations } from 'next-intl';+import { ArrowRight, Loader2 } from 'lucide-react';+import { Link } from '@/i18n/navigation';+import { useBrandStore } from '@/stores/use-brand-store';+import { getJobStatus, getTrackingWindow, type TrackingJobStatus } from '@/lib/actions/tracking';+import { loadTrackingJob } from '@/lib/tracking-job-store';++/** How often the note reads again while the first run goes on. */+const POLL_MS = 30_000;++/** A saved job the worker hasn't finished: queued, delayed or running. */+const LIVE_JOB = new Set<TrackingJobStatus['status']>(['waiting', 'delayed', 'active']);++interface FirstRun {+ brandId: string;+ /** Queued: the worker hasn't started it, so the ledger has no row yet. */+ queued: boolean;+ progress: TrackingJobStatus['progress'];+}++/**+ * "First analysis running" on the Action Center (#1238's review): after the+ * payment, a new brand or onboarding, people land on Actions while the first+ * tracking run is still going, and only Visibility showed it. Shown while the+ * brand has no completed run and one is under way: from the tracking_runs+ * ledger (any browser's run), or, while the job still waits for the worker,+ * from the job this browser saved (TrackingJobHandoff), which also gives the+ * progress. It stops reading once the brand has a completed run.+ */+export function FirstRunNote() {+ const t = useTranslations('actionCenter.firstRun');+ const brandId = useBrandStore((s) => s.activeBrandId);+ const [run, setRun] = useState<FirstRun | null>(null);++ useEffect(() => {+ if (!brandId) return;+ let cancelled = false;+ let timer: ReturnType<typeof setTimeout> | undefined;++ const tick = async () => {+ const win = await getTrackingWindow(brandId).catch(() => null);+ if (cancelled) return;+ if (win?.lastRunAt) {+ // The first run is done: this brand never needs the note again.+ setRun(null);+ return;+ }+ // A failed read keeps what the note says until the next one.+ if (win) {+ const saved = loadTrackingJob();+ const job =+ saved?.brandId === brandId ? await getJobStatus(saved.jobId).catch(() => null) : null;+ if (cancelled) return;+ const live = job !== null && LIVE_JOB.has(job.status);+ setRun(+ win.activeRun || live+ ? {+ brandId,+ queued: !win.activeRun && job?.status !== 'active',+ progress: live ? job.progress : null,+ }+ : null,+ );+ }+ timer = setTimeout(tick, POLL_MS);+ };++ tick();+ return () => {+ cancelled = true;+ clearTimeout(timer);+ };+ }, [brandId]);++ // Another brand's run never shows under this one.+ if (!run || run.brandId !== brandId) return null;+ const { progress } = run;++ return (+ <div role="status" className="rounded-lg border border-primary/20 bg-primary/5 px-4 py-3">+ <div className="flex flex-wrap items-center gap-x-2 gap-y-1">+ <Loader2 className="h-4 w-4 animate-spin text-primary" aria-hidden />+ <span className="text-sm font-medium">{run.queued ? t('queued') : t('running')}</span>+ {progress && progress.total > 0 && (+ <span className="text-xs text-muted-foreground tabular-nums">+ {t('progress', { current: progress.current, total: progress.total })}+ </span>+ )}+ <Link+ href="/dashboard/insights"+ className="ml-auto inline-flex items-center gap-1 text-xs font-medium text-primary hover:underline"+ >+ {t('link')}+ <ArrowRight className="h-3.5 w-3.5" aria-hidden />+ </Link>+ </div>+ <p className="mt-1 text-xs text-muted-foreground">+ {run.queued ? t('queuedBody') : t('runningBody')}+ </p>+ </div>+ );+}