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
fix(citations): count the Domains tab within the selected source scope (#1218)
Cihanfea00079e041
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsxindex b106db667..cc9d938ca 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/citations/page.tsx@@ -56,6 +56,7 @@ import { getBrandPrompts } from '@/lib/actions/tracking';import { toCsv } from '@/lib/csv';import type { Topic } from '@/types';import { SOURCE_CATEGORY_LABELS, type SourceCategory } from '@/lib/citations/classify';+import { inSourceScope } from '@/lib/citations/scope';import {CategoryBadge,DomainFavicon,@@ -865,43 +866,19 @@ export default function CitationsPage() {const [hasAnyCitations, setHasAnyCitations] = useState<boolean | null>(null);const [loadFailed, setLoadFailed] = useState(false);- const filteredDomainRows = (data?.rows ?? []).filter((row) => {- switch (filters.sourceScope) {- case 'own':- return row.category === 'you';-- case 'competitors':- return row.category === 'competitor';-- case 'third_party':- return row.category !== 'you' && row.category !== 'competitor';-- case 'all':- default:- return true;- }- });+ // Every cited domain arrives (the list isn't capped), so the scope is+ // applied here, and the Domains tab counts these rows rather than all of them.+ const filteredDomainRows = (data?.rows ?? []).filter((row) =>+ inSourceScope(row.category, filters.sourceScope),+ );// The server already scoped these (#745). This is kept for the moment// between picking a scope and the refetch landing, when `data` still holds// the previous scope's rows — without it the table would show the old scope// under the new one's name. Once the fresh rows arrive it filters nothing.- const filteredUrlRows = (data?.urlRows ?? []).filter((urlRow) => {- switch (filters.sourceScope) {- case 'own':- return urlRow.category === 'you';-- case 'competitors':- return urlRow.category === 'competitor';-- case 'third_party':- return urlRow.category !== 'you' && urlRow.category !== 'competitor';-- case 'all':- default:- return true;- }- });+ const filteredUrlRows = (data?.urlRows ?? []).filter((urlRow) =>+ inSourceScope(urlRow.category, filters.sourceScope),+ );// Pagination — resets to page 0 whenever any filter changesconst filterKey = JSON.stringify(filters);@@ -1278,7 +1255,8 @@ export default function CitationsPage() {><TabsList><TabsTrigger value="domains">- {t('tabDomains')} ({data?.totals.domains ?? 0})+ {/* The scope's domains, as the table lists them; All counts every one. */}+ {t('tabDomains')} ({filteredDomainRows.length})</TabsTrigger><TabsTrigger value="urls">{t('tabUrls')} ({data?.totals.urls ?? 0})diff --git a/web/src/lib/citations/scope.test.ts b/web/src/lib/citations/scope.test.tsindex d668ff965..1b63c4505 100644--- a/web/src/lib/citations/scope.test.ts+++ b/web/src/lib/citations/scope.test.ts@@ -1,5 +1,5 @@import { describe, expect, it } from 'vitest';-import { scopeDomainArgs } from './scope.js';+import { inSourceScope, scopeDomainArgs } from './scope.js';import type { SourceCategory } from './classify.js';/**@@ -81,3 +81,15 @@ describe('scopeDomainArgs', () => {expect(scopeDomainArgs('third_party', [])).toEqual({});});});++describe('inSourceScope', () => {+ it("keeps a scope's sources, and every source for All", () => {+ const inScope = (scope: Parameters<typeof inSourceScope>[1]) =>+ rows.filter((r) => inSourceScope(r.category, scope)).map((r) => r.domain);+ expect(inScope('own')).toEqual(['mybrand.com', 'blog.mybrand.com']);+ expect(inScope('competitors')).toEqual(['rival.com', 'other-rival.com']);+ expect(inScope('third_party')).toEqual(['reddit.com', 'techcrunch.com', 'randomsite.com']);+ expect(inScope('all')).toHaveLength(rows.length);+ expect(inScope(undefined)).toHaveLength(rows.length);+ });+});diff --git a/web/src/lib/citations/scope.ts b/web/src/lib/citations/scope.tsindex 3006c5945..bf10bc4c7 100644--- a/web/src/lib/citations/scope.ts+++ b/web/src/lib/citations/scope.ts@@ -3,6 +3,27 @@ import type { SourceCategory } from './classify';/** Which sources the Citations URL list covers. */export type CitationsSourceScope = 'all' | 'own' | 'competitors' | 'third_party';+/**+ * Whether a source of this category is in the scope: the Domains and URLs+ * tabs' rows, and the Domains tab's count, so the count is the list's.+ */+export function inSourceScope(+ category: SourceCategory,+ scope: CitationsSourceScope | undefined,+): boolean {+ switch (scope) {+ case 'own':+ return category === 'you';+ case 'competitors':+ return category === 'competitor';+ case 'third_party':+ return category !== 'you' && category !== 'competitor';+ case 'all':+ default:+ return true;+ }+}+/** The classified domain rows the Domains tab is built from. */interface ClassifiedDomain {domain: string;