Skip to content

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.

feat(prompts): add every listed suggestion at once with Add All (#1299)

Cihan8edd198ef2fc
diff --git a/web/messages/en.json b/web/messages/en.json
index f00de5b64..75edc85d3 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -4131,6 +4131,16 @@
"gaps": "Content Gaps",
"suggestions": {
"measuredSuggestionsKept": "Search Console and Analytics suggestions were kept — dismiss them individually to hide them for 30 days.",
+ "addAll": "Add All",
+ "addingAll": "Adding…",
+ "addAllTitle": "Add every suggestion listed below to your tracked prompts",
+ "addAllDone": "{count, plural, one {# prompt added to your tracked list} other {# prompts added to your tracked list}}",
+ "addAllHandled": "These suggestions were already added or dismissed",
+ "addAllFailed": "Couldn't add the suggestions",
+ "limitTitle": "{count, plural, one {# suggestion couldn't be added} other {# suggestions couldn't be added}}",
+ "limitBody": "{added, plural, =0 {Your plan's prompt limit is reached.} one {# was added before your plan's prompt limit was reached.} other {# were added before your plan's prompt limit was reached.}} {plan, select, growth {Contact us to raise your limit} enterprise {Contact us to raise your limit} other {Upgrade your plan}}, or pause {count, plural, one {# prompt} other {# prompts}} in Tracked Prompts first and try again.",
+ "openTracked": "Go to Tracked Prompts",
+ "closeLimitNote": "Close",
"include": "Include this prompt",
"topic": "Topic",
"selectTopic": "Select a topic",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.test.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.test.tsx
new file mode 100644
index 000000000..8987ae338
--- /dev/null
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.test.tsx
@@ -0,0 +1,223 @@
+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 { PromptSuggestion, TrackSuggestionsResult } from '@/lib/actions/prompt-suggestions';
+import { SuggestionsCard } from './_suggestions-card';
+
+(
+ globalThis as typeof globalThis & {
+ IS_REACT_ACT_ENVIRONMENT: boolean;
+ }
+).IS_REACT_ACT_ENVIRONMENT = true;
+
+const actions = vi.hoisted(() => ({
+ getPromptSuggestions: vi.fn(),
+ refreshPromptSuggestions: vi.fn(),
+ acceptSuggestion: vi.fn(),
+ dismissSuggestion: vi.fn(),
+ trackSuggestions: vi.fn(),
+}));
+vi.mock('@/lib/actions/prompt-suggestions', () => actions);
+
+const toast = vi.hoisted(() => ({ success: vi.fn(), error: vi.fn(), info: vi.fn() }));
+vi.mock('sonner', () => ({ toast }));
+
+vi.mock('@/i18n/navigation', () => ({
+ Link: ({ children, ...props }: React.ComponentProps<'a'>) => <a {...props}>{children}</a>,
+}));
+
+const suggestion = (n: number): PromptSuggestion => ({
+ id: `s${n}`,
+ brandId: 'b1',
+ suggestedText: `Prompt ${n}`,
+ topicName: null,
+ topicId: null,
+ reason: null,
+ estVolume: null,
+ relevance: null,
+ source: 'llm',
+ sourceData: null,
+ status: 'new',
+ generatedAt: '2026-10-21T08:00:00.000Z',
+ expiresAt: '2026-11-21T08:00:00.000Z',
+});
+
+const ids = (from: number, to: number) =>
+ Array.from({ length: to - from + 1 }, (_, i) => `s${from + i}`);
+
+let container: HTMLDivElement;
+let root: Root;
+const onAccepted = vi.fn();
+
+async function render(count: number, planId: 'starter' | 'growth' = 'starter') {
+ actions.getPromptSuggestions.mockResolvedValue({
+ suggestions: Array.from({ length: count }, (_, i) => suggestion(i + 1)),
+ });
+ await act(async () => {
+ root.render(
+ <NextIntlClientProvider locale="en" messages={messages} timeZone="UTC">
+ <SuggestionsCard
+ brandId="b1"
+ onAccepted={onAccepted}
+ sourceStates={null}
+ planId={planId}
+ limitActions={<button type="button">Upgrade plan</button>}
+ />
+ </NextIntlClientProvider>,
+ );
+ });
+}
+
+const addAllButton = () =>
+ [...container.querySelectorAll('button')].find((b) => b.textContent === 'Add All');
+const rows = () => container.querySelectorAll('li');
+
+async function clickAddAll() {
+ await act(async () => {
+ addAllButton()!.click();
+ });
+}
+
+beforeEach(() => {
+ container = document.createElement('div');
+ document.body.appendChild(container);
+ root = createRoot(container);
+ vi.clearAllMocks();
+});
+
+afterEach(() => {
+ act(() => root.unmount());
+ container.remove();
+});
+
+describe('SuggestionsCard — Add All', () => {
+ it('sits between New and Clear All', async () => {
+ await render(3);
+ const labels = [...container.querySelectorAll('button')].map((b) => b.textContent);
+ const at = (label: string) => labels.indexOf(label);
+ expect(at('New')).toBeGreaterThan(-1);
+ expect(at('Add All')).toBe(at('New') + 1);
+ expect(at('Clear All')).toBe(at('Add All') + 1);
+ });
+
+ it('tracks every suggestion listed and takes them off the list', async () => {
+ await render(3);
+ actions.trackSuggestions.mockResolvedValue({
+ trackedIds: ids(1, 3),
+ skippedIds: [],
+ } satisfies TrackSuggestionsResult);
+
+ await clickAddAll();
+
+ expect(actions.trackSuggestions).toHaveBeenCalledExactlyOnceWith(ids(1, 3));
+ expect(rows()).toHaveLength(0);
+ expect(onAccepted).toHaveBeenCalledOnce();
+ expect(toast.success).toHaveBeenCalledWith('3 prompts added to your tracked list');
+ expect(container.querySelector('[role="alert"]')).toBeNull();
+ });
+
+ it('sends more than 25 in batches', async () => {
+ await render(30);
+ actions.trackSuggestions.mockImplementation(async (batch: string[]) => ({
+ trackedIds: batch,
+ skippedIds: [],
+ }));
+
+ await clickAddAll();
+
+ expect(actions.trackSuggestions.mock.calls).toEqual([[ids(1, 25)], [ids(26, 30)]]);
+ expect(rows()).toHaveLength(0);
+ expect(toast.success).toHaveBeenCalledWith('30 prompts added to your tracked list');
+ });
+
+ it('keeps the rest and says how to make room when the plan limit is reached', async () => {
+ await render(25);
+ actions.trackSuggestions.mockResolvedValue({
+ trackedIds: ids(1, 10),
+ skippedIds: [],
+ error: 'Your Starter plan allows up to 50 active prompt locations…',
+ code: 'plan_limit',
+ } satisfies TrackSuggestionsResult);
+
+ await clickAddAll();
+
+ expect(rows()).toHaveLength(15);
+ expect(rows()[0].textContent).toContain('Prompt 11');
+ expect(toast.success).toHaveBeenCalledWith('10 prompts added to your tracked list');
+ expect(toast.error).not.toHaveBeenCalled();
+ const note = container.querySelector('[role="alert"]')!;
+ expect(note.textContent).toContain("15 suggestions couldn't be added");
+ expect(note.textContent).toContain(
+ "10 were added before your plan's prompt limit was reached.",
+ );
+ expect(note.textContent).toContain(
+ 'Upgrade your plan, or pause 15 prompts in Tracked Prompts first and try again.',
+ );
+ expect(note.querySelector('a[href="/dashboard/prompts/tracked"]')?.textContent).toBe(
+ 'Go to Tracked Prompts',
+ );
+ // The page's own Upgrade / Contact us buttons.
+ expect([...note.querySelectorAll('button')].map((b) => b.textContent)).toContain(
+ 'Upgrade plan',
+ );
+ });
+
+ it('stops after the batch that reached the limit', async () => {
+ await render(30, 'growth');
+ actions.trackSuggestions.mockResolvedValue({
+ trackedIds: [],
+ skippedIds: ['s1'],
+ error: 'limit',
+ code: 'plan_limit',
+ } satisfies TrackSuggestionsResult);
+
+ await clickAddAll();
+
+ expect(actions.trackSuggestions).toHaveBeenCalledOnce();
+ expect(onAccepted).not.toHaveBeenCalled();
+ // The skipped one was handled elsewhere: it leaves, the other 29 stay.
+ expect(rows()).toHaveLength(29);
+ const note = container.querySelector('[role="alert"]')!;
+ expect(note.textContent).toContain("29 suggestions couldn't be added");
+ expect(note.textContent).toContain(
+ "Your plan's prompt limit is reached. Contact us to raise your limit, or pause 29 prompts",
+ );
+
+ await act(async () => {
+ (note.querySelector('button[aria-label="Close"]') as HTMLButtonElement).click();
+ });
+ expect(container.querySelector('[role="alert"]')).toBeNull();
+ });
+
+ it('reports any other failure as an error and keeps what was not added', async () => {
+ await render(3);
+ actions.trackSuggestions.mockResolvedValue({
+ trackedIds: ['s1'],
+ skippedIds: [],
+ error: 'Something broke',
+ } satisfies TrackSuggestionsResult);
+
+ await clickAddAll();
+
+ expect(rows()).toHaveLength(2);
+ expect(toast.success).toHaveBeenCalledWith('1 prompt added to your tracked list');
+ expect(toast.error).toHaveBeenCalledWith('Something broke');
+ expect(container.querySelector('[role="alert"]')).toBeNull();
+ });
+
+ it('says so when every suggestion was already handled elsewhere', async () => {
+ await render(2);
+ actions.trackSuggestions.mockResolvedValue({
+ trackedIds: [],
+ skippedIds: ids(1, 2),
+ } satisfies TrackSuggestionsResult);
+
+ await clickAddAll();
+
+ expect(rows()).toHaveLength(0);
+ expect(onAccepted).not.toHaveBeenCalled();
+ expect(toast.info).toHaveBeenCalledWith('These suggestions were already added or dismissed');
+ });
+});
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.tsx
index 815494721..98fc02111 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-card.tsx
@@ -3,12 +3,14 @@
import { useEffect, useState, useCallback, useMemo, useTransition, useRef } from 'react';
import { createPortal } from 'react-dom';
import { useTranslations } from 'next-intl';
+import { Link } from '@/i18n/navigation';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Badge } from '@/components/ui/badge';
-import { Button } from '@/components/ui/button';
+import { Button, buttonVariants } from '@/components/ui/button';
import {
Sparkles,
Plus,
+ ListPlus,
X,
RefreshCw,
Loader2,
@@ -41,8 +43,10 @@ import {
refreshPromptSuggestions,
acceptSuggestion,
dismissSuggestion,
+ trackSuggestions,
type PromptSuggestion,
} from '@/lib/actions/prompt-suggestions';
+import type { PlanId } from '@/config/plans';
import {
fromYourData,
gaSourceData,
@@ -218,8 +222,15 @@ interface Props {
onAccepted?: () => void;
/** Connected sources and whether their data has landed; null when unknown. */
sourceStates: SuggestionSourceStates | null;
+ /** The organization's plan, for the prompt limit note's wording; absent while unknown. */
+ planId?: PlanId;
+ /** Where to go for more prompts (upgrade or contact us), shown in the prompt limit note. */
+ limitActions?: React.ReactNode;
}
+/** The most suggestions trackSuggestions takes in one call. */
+const TRACK_BATCH = 25;
+
const SOURCE_NAMES = { gsc: 'Search Console', ga: 'Analytics' } as const;
function joinNames(names: string[]): string {
@@ -261,7 +272,13 @@ function sourceNotice(
return null;
}
-export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
+export function SuggestionsCard({
+ brandId,
+ onAccepted,
+ sourceStates,
+ planId,
+ limitActions,
+}: Props) {
const t = useTranslations('prompts.suggestions');
const [suggestions, setSuggestions] = useState<PromptSuggestion[]>([]);
const [loading, setLoading] = useState(false);
@@ -282,6 +299,9 @@ export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
}, []);
const [search, setSearch] = useState('');
const [clearing, setClearing] = useState(false);
+ const [adding, setAdding] = useState(false);
+ // What Add All left behind when the plan's prompt limit stopped it.
+ const [limitNote, setLimitNote] = useState<{ added: number; left: number } | null>(null);
const [, startTransition] = useTransition();
const load = useCallback(async () => {
@@ -304,6 +324,7 @@ export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
setLoaded(false);
setSuggestions([]);
setError(null);
+ setLimitNote(null);
}, [brandId]);
// Fetching on mount is safe here because this component only mounts when
@@ -378,6 +399,48 @@ export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
.finally(() => setClearing(false));
};
+ /**
+ * Track every suggestion on screen, in batches trackSuggestions takes. Each
+ * prompt passes the same plan check as a single add, so a run stops where
+ * the plan's prompt limit is reached: what was added leaves the list, the
+ * rest stay and the note says how to make room for them.
+ */
+ const handleAddAll = async () => {
+ const ids = visible.map((s) => s.id);
+ if (ids.length === 0) return;
+ setAdding(true);
+ setLimitNote(null);
+ const added: string[] = [];
+ const gone: string[] = [];
+ let failure: { error: string; code?: 'plan_limit' } | null = null;
+ try {
+ for (let i = 0; i < ids.length && !failure; i += TRACK_BATCH) {
+ const result = await trackSuggestions(ids.slice(i, i + TRACK_BATCH));
+ added.push(...result.trackedIds);
+ // Accepted or dismissed elsewhere: they leave the list too.
+ gone.push(...result.skippedIds);
+ if (result.error) failure = { error: result.error, code: result.code };
+ }
+ } catch (err) {
+ failure = { error: err instanceof Error ? err.message : t('addAllFailed') };
+ }
+
+ const leaving = new Set([...added, ...gone]);
+ if (leaving.size > 0) setSuggestions((prev) => prev.filter((x) => !leaving.has(x.id)));
+ if (added.length > 0) {
+ onAccepted?.();
+ toast.success(t('addAllDone', { count: added.length }));
+ }
+ if (failure?.code === 'plan_limit') {
+ setLimitNote({ added: added.length, left: ids.length - leaving.size });
+ } else if (failure) {
+ toast.error(failure.error);
+ } else if (added.length === 0) {
+ toast.info(t('addAllHandled'));
+ }
+ setAdding(false);
+ };
+
const handleAccept = (s: PromptSuggestion) => {
setPendingId(s.id);
startTransition(async () => {
@@ -479,9 +542,25 @@ export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
{refreshing ? 'Generating…' : 'New'}
</Button>
+ <Button
+ onClick={handleAddAll}
+ disabled={adding || clearing || visible.length === 0}
+ size="sm"
+ variant="outline"
+ className="gap-2"
+ title={t('addAllTitle')}
+ >
+ {adding ? (
+ <Loader2 className="h-3.5 w-3.5 animate-spin" />
+ ) : (
+ <ListPlus className="h-3.5 w-3.5" />
+ )}
+ {adding ? t('addingAll') : t('addAll')}
+ </Button>
+
<Button
onClick={handleClearAll}
- disabled={clearing || visible.length === 0}
+ disabled={clearing || adding || visible.length === 0}
size="sm"
variant="outline"
className="gap-2 text-muted-foreground"
@@ -499,6 +578,47 @@ export function SuggestionsCard({ brandId, onAccepted, sourceStates }: Props) {
</div>
</CardHeader>
<CardContent>
+ {limitNote && (
+ <div
+ role="alert"
+ className="mb-4 flex items-start gap-2.5 rounded-lg border border-amber-200 bg-amber-50 p-3 dark:border-amber-900/50 dark:bg-amber-950/30"
+ >
+ <AlertTriangle className="mt-0.5 h-4 w-4 shrink-0 text-amber-600 dark:text-amber-500" />
+ <div className="min-w-0 flex-1 space-y-2.5 text-sm">
+ <div>
+ <p className="font-medium text-amber-900 dark:text-amber-200">
+ {t('limitTitle', { count: limitNote.left })}
+ </p>
+ <p className="text-amber-800/80 dark:text-amber-300/80">
+ {t('limitBody', {
+ added: limitNote.added,
+ count: limitNote.left,
+ plan: planId ?? 'unknown',
+ })}
+ </p>
+ </div>
+ <div className="flex flex-wrap items-center gap-2">
+ <Link
+ href="/dashboard/prompts/tracked"
+ className={buttonVariants({ variant: 'outline', size: 'sm' })}
+ >
+ {t('openTracked')}
+ </Link>
+ {limitActions}
+ </div>
+ </div>
+ <Button
+ size="icon"
+ variant="ghost"
+ className="-my-1 h-7 w-7 shrink-0 text-amber-800/80 dark:text-amber-300/80"
+ onClick={() => setLimitNote(null)}
+ aria-label={t('closeLimitNote')}
+ title={t('closeLimitNote')}
+ >
+ <X className="h-3.5 w-3.5" />
+ </Button>
+ </div>
+ )}
{loaded && !loading && !error && notice && (
<div
className={cn(
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-tab.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-tab.tsx
index 829cd0d89..4ddf2cb47 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-tab.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/_suggestions-tab.tsx
@@ -6,6 +6,7 @@ import {
type SourceState,
type SuggestionSourceStates,
} from '@/lib/actions/integrations';
+import type { PlanId } from '@/config/plans';
import { DataSourcesPanel } from './_data-sources-panel';
import { SuggestionsCard } from './_suggestions-card';
@@ -28,9 +29,13 @@ const MAX_POLLS = 20;
export function SuggestionsTab({
brandId,
onAccepted,
+ planId,
+ limitActions,
}: {
brandId: string;
onAccepted?: () => void;
+ planId?: PlanId;
+ limitActions?: React.ReactNode;
}) {
// undefined while loading; null when the read failed — both render nothing
// source-related, so a status failure never gets in the way of suggestions.
@@ -63,7 +68,13 @@ export function SuggestionsTab({
return (
<>
<DataSourcesPanel states={states} />
- <SuggestionsCard brandId={brandId} onAccepted={onAccepted} sourceStates={states ?? null} />
+ <SuggestionsCard
+ brandId={brandId}
+ onAccepted={onAccepted}
+ sourceStates={states ?? null}
+ planId={planId}
+ limitActions={limitActions}
+ />
</>
);
}
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
index 61ce561a5..ad89f1894 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/prompts/page.tsx
@@ -1984,7 +1984,14 @@ export default function PromptsPage() {
{view === 'suggestions' ? (
activeBrandId && (
<>
- <SuggestionsTab brandId={activeBrandId} onAccepted={reloadAfterChange} />
+ <SuggestionsTab
+ brandId={activeBrandId}
+ onAccepted={reloadAfterChange}
+ planId={locationQuota?.planId}
+ limitActions={
+ locationQuota ? <PromptLimitActions planId={locationQuota.planId} /> : null
+ }
+ />
</>
)
) : (