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.

fix(content): keep filters reachable on zero results, and allow deleting selections (#733)

Gökhan Geyik9cccf24fa91f
diff --git a/server/src/routes/content.js b/server/src/routes/content.js
index ddf4a7167..28d0fb44d 100644
--- a/server/src/routes/content.js
+++ b/server/src/routes/content.js
@@ -255,6 +255,46 @@ router.post('/bulk/status', async (req, res) => {
}
});
+/**
+ * POST /api/content/bulk/delete
+ *
+ * Permanently remove opportunities (#731). Dismissing only hides a row behind
+ * a status filter, which is no help to a brand carrying hundreds of stale
+ * suggestions — this is the way to actually clear them.
+ *
+ * The generated brief lives on the opportunity row, so deleting takes it with
+ * it. `brief_usage.opportunity_id` is ON DELETE SET NULL, so the metered usage
+ * record survives and quota already spent stays spent — deleting must not hand
+ * back a brief allowance.
+ */
+router.post('/bulk/delete', async (req, res) => {
+ try {
+ const { ids } = req.body;
+
+ if (!Array.isArray(ids) || ids.length === 0) {
+ return res.status(400).json({ error: 'ids must be a non-empty array' });
+ }
+
+ await assertOpportunitiesAccess(ids, req.user.id);
+
+ const { data, error } = await supabaseAdmin
+ .from('content_opportunities')
+ .delete()
+ .in('id', ids)
+ .select('id');
+
+ if (error) throw new Error(error.message);
+
+ return res.json({ deleted: data?.length || 0 });
+ } catch (error) {
+ req.log.error({ err: error }, 'bulk delete error');
+ return res.status(error.status || 500).json({
+ error: 'Failed to delete opportunities',
+ details: error.message,
+ });
+ }
+});
+
/**
* POST /api/content/bulk/send-webhook
* Send multiple opportunities to webhook.
diff --git a/web/messages/en.json b/web/messages/en.json
index 51cc52dde..8accf8f0a 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -253,6 +253,7 @@
"sendToWorkflow": "Send to Workflow",
"sending": "Sending...",
"noResults": "No opportunities match your filters.",
+ "clearFilters": "Clear filters",
"dismiss": "Dismiss",
"dismissedToast": "Opportunity dismissed",
"undo": "Undo",
@@ -300,7 +301,12 @@
"sendAll": "Send All",
"dismissAll": "Dismiss All",
"dismissAllTitle": "Dismiss opportunities?",
- "dismissAllConfirm": "{count, plural, one {This will dismiss # opportunity.} other {This will dismiss # opportunities.}} This can't be undone."
+ "dismissAllConfirm": "{count, plural, one {This will dismiss # opportunity.} other {This will dismiss # opportunities.}} This can't be undone.",
+ "deleteAll": "Delete",
+ "deleteAllTitle": "Delete opportunities?",
+ "deleteAllConfirm": "{count, plural, one {This permanently deletes # opportunity.} other {This permanently deletes # opportunities.}} Dismissing instead keeps them out of your way without removing them.",
+ "deleteAllBriefWarning": "{count, plural, one {# of them has a generated brief, which is deleted too and does not return your monthly brief allowance.} other {# of them have generated briefs, which are deleted too and do not return your monthly brief allowance.}}",
+ "deletedToast": "{count, plural, one {Deleted # opportunity} other {Deleted # opportunities}}"
},
"table": {
"action": "Action",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx
index a0645fa3e..23fefe0bc 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/content/page.tsx
@@ -44,6 +44,7 @@ import {
ExternalLink,
X,
Settings2,
+ Trash2,
} from 'lucide-react';
import { cn } from '@/lib/utils';
import { useBrandStore } from '@/stores/use-brand-store';
@@ -56,6 +57,7 @@ import {
sendToWebhook,
bulkSendToWebhook,
bulkUpdateStatus,
+ bulkDeleteOpportunities,
} from '@/lib/actions/content';
import type { ContentOpportunity, ContentOpportunityStatus } from '@/types';
import { toast } from 'sonner';
@@ -414,12 +416,53 @@ export default function ContentPage() {
}
};
+ const handleBulkDelete = async () => {
+ setBulkSending(true);
+ try {
+ const ids = Array.from(selectedIds);
+ const result = await bulkDeleteOpportunities(ids);
+ toast.success(t('bulk.deletedToast', { count: result.deleted }));
+ setSelectedIds(new Set());
+ // No page reset needed: `usePagination` clamps to the last page that
+ // still exists, and the narrowed `start` refetches on its own. Resetting
+ // here as well would fire a second, competing load.
+ await loadData(true);
+ } catch (err) {
+ toast.error(err instanceof Error ? err.message : 'Bulk delete failed');
+ } finally {
+ setBulkSending(false);
+ }
+ };
+
const filtered = opportunities.filter(
(o) =>
o.title.toLowerCase().includes(search.toLowerCase()) ||
(o.description || '').toLowerCase().includes(search.toLowerCase()),
);
+ /** How many of the selected rows would lose a generated brief (#731). */
+ const selectedWithBrief = opportunities.filter(
+ (o) => selectedIds.has(o.id) && Boolean(o.brief),
+ ).length;
+
+ // "The brand has nothing" and "this filter matched nothing" are different
+ // states with different remedies, and the page used to answer both with the
+ // Generate card — which hid the very controls needed to undo the filter
+ // (#660). The unfiltered view is the only one whose emptiness means the
+ // brand truly has no opportunities.
+ const hasActiveFilters =
+ statusFilter !== 'all' ||
+ impactFilter !== 'all' ||
+ typeFilter !== 'all' ||
+ search.trim() !== '';
+
+ const clearFilters = () => {
+ setStatusFilter('all');
+ setImpactFilter('all');
+ setTypeFilter('all');
+ setSearch('');
+ };
+
if (!activeBrandId) {
return (
<div className="flex items-center justify-center min-h-[400px]">
@@ -473,7 +516,7 @@ export default function ContentPage() {
<div className="flex items-center justify-center min-h-[300px]">
<Loader2 className="h-8 w-8 animate-spin text-muted-foreground" />
</div>
- ) : opportunities.length === 0 ? (
+ ) : opportunities.length === 0 && !hasActiveFilters ? (
<Card>
<CardContent className="flex flex-col items-center justify-center py-16 gap-4">
<Lightbulb className="h-12 w-12 text-muted-foreground/40" />
@@ -659,6 +702,47 @@ export default function ContentPage() {
</DialogFooter>
</DialogContent>
</Dialog>
+
+ {/* Last in the row, and the only destructive-styled trigger:
+ this one does not move a row, it removes it. */}
+ <Dialog>
+ <DialogTrigger
+ render={
+ <Button
+ variant="outline"
+ size="sm"
+ className="h-7 text-xs gap-1.5 text-destructive hover:text-destructive"
+ disabled={bulkSending}
+ />
+ }
+ >
+ <Trash2 className="h-3 w-3" />
+ {t('bulk.deleteAll')}
+ </DialogTrigger>
+ <DialogContent className="sm:max-w-sm">
+ <DialogHeader>
+ <DialogTitle>{t('bulk.deleteAllTitle')}</DialogTitle>
+ <DialogDescription>
+ {t('bulk.deleteAllConfirm', { count: selectedIds.size })}
+ {selectedWithBrief > 0 && (
+ <span className="mt-2 block font-medium text-foreground">
+ {t('bulk.deleteAllBriefWarning', { count: selectedWithBrief })}
+ </span>
+ )}
+ </DialogDescription>
+ </DialogHeader>
+ <DialogFooter>
+ <DialogClose render={<Button variant="outline" />}>
+ {t('cancel')}
+ </DialogClose>
+ <DialogClose
+ render={<Button variant="destructive" onClick={handleBulkDelete} />}
+ >
+ {t('bulk.deleteAll')}
+ </DialogClose>
+ </DialogFooter>
+ </DialogContent>
+ </Dialog>
</div>
</div>
)}
@@ -790,8 +874,14 @@ export default function ContentPage() {
</TableBody>
</Table>
{filtered.length === 0 && (
- <div className="py-10 text-center text-sm text-muted-foreground">
- {t('noResults')}
+ <div className="flex flex-col items-center gap-3 py-10 text-center">
+ <p className="text-sm text-muted-foreground">{t('noResults')}</p>
+ {hasActiveFilters && (
+ <Button variant="outline" size="sm" className="gap-1.5" onClick={clearFilters}>
+ <X className="h-3.5 w-3.5" />
+ {t('clearFilters')}
+ </Button>
+ )}
</div>
)}
<TablePager
diff --git a/web/src/lib/actions/content.ts b/web/src/lib/actions/content.ts
index 7a9d2acfc..505fa35f8 100644
--- a/web/src/lib/actions/content.ts
+++ b/web/src/lib/actions/content.ts
@@ -285,6 +285,33 @@ export async function bulkUpdateStatus(
return res.json();
}
+/**
+ * Permanently delete opportunities (#731).
+ *
+ * Distinct from `bulkUpdateStatus(ids, 'dismissed')`, which only moves a row
+ * behind a status filter. Anything deleted here is gone, including any brief
+ * generated for it.
+ */
+export async function bulkDeleteOpportunities(ids: string[]): Promise<{ deleted: number }> {
+ const session = await getSession();
+
+ const res = await fetch(`${AEO_SERVER_URL}/api/content/bulk/delete`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ Authorization: `Bearer ${session.access_token}`,
+ },
+ body: JSON.stringify({ ids }),
+ });
+
+ if (!res.ok) {
+ const body = await res.json().catch(() => ({}));
+ throw new Error(body.error || `Server error: ${res.status}`);
+ }
+
+ return res.json();
+}
+
export type BulkSendResult =
| {
success: true;