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(insights): translate the result detail page and offer a retry when it fails to load (#974)

Gökhan Geyik7e995abd6d8d
diff --git a/web/messages/en.json b/web/messages/en.json
index 7467af869..c0ffa8a01 100644
--- a/web/messages/en.json
+++ b/web/messages/en.json
@@ -1584,7 +1584,17 @@
"positiveSentiment": "Positive Sentiment",
"neutral": "Neutral",
"negative": "Negative",
- "sovByPlatform": "Share of Voice by Platform"
+ "sovByPlatform": "Share of Voice by Platform",
+ "resultDetail": {
+ "notFoundTitle": "Result not found",
+ "notFoundDescription": "This result may have been deleted or does not exist.",
+ "loadFailedTitle": "Couldn't load this result",
+ "loadFailedDescription": "Something went wrong while loading this result. Please try again.",
+ "goBack": "Go back",
+ "brandCitations": "Brand Citations",
+ "totalCitations": "Total Citations",
+ "checkedAt": "Checked: {date}"
+ }
},
"topics": {
"addTopic": "Add Topic",
diff --git a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
index 699f1c671..f18c06d8f 100644
--- a/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
+++ b/web/src/app/[locale]/(dashboard)/dashboard/insights/[id]/page.tsx
@@ -2,23 +2,35 @@
import { useEffect, useState } from 'react';
import { useParams } from 'next/navigation';
+import { useTranslations } from 'next-intl';
import { useRouter } from '@/i18n/navigation';
import { getPromptResultById, type PromptResultWithText } from '@/lib/actions/tracking';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import { Skeleton } from '@/components/ui/skeleton';
-import { ArrowLeft, ExternalLink, MessageSquareText, Quote, Eye, Clock } from 'lucide-react';
+import {
+ AlertCircle,
+ ArrowLeft,
+ ExternalLink,
+ MessageSquareText,
+ Quote,
+ Eye,
+ Clock,
+ RotateCw,
+} from 'lucide-react';
import { cn } from '@/lib/utils';
import { PLATFORM_LABELS } from '@/config/platform-labels';
import { ResponseDetail } from '@/components/results/response-detail';
+import { formatRegionDisplay } from '@/lib/region';
function SentimentBadge({ sentiment }: { sentiment: 'positive' | 'neutral' | 'negative' }) {
+ const t = useTranslations('insights');
return (
<Badge
variant="outline"
className={cn(
- 'text-xs capitalize',
+ 'text-xs',
sentiment === 'positive' &&
'border-green-500/30 bg-green-500/10 text-green-600 dark:text-green-400',
sentiment === 'neutral' &&
@@ -27,7 +39,7 @@ function SentimentBadge({ sentiment }: { sentiment: 'positive' | 'neutral' | 'ne
'border-red-500/30 bg-red-500/10 text-red-600 dark:text-red-400',
)}
>
- {sentiment}
+ {t(sentiment)}
</Badge>
);
}
@@ -36,29 +48,40 @@ export default function ResultDetailPage() {
const params = useParams();
const router = useRouter();
const resultId = params.id as string;
+ const t = useTranslations('insights');
+ const tDetail = useTranslations('insights.resultDetail');
+ const common = useTranslations('common');
const [result, setResult] = useState<PromptResultWithText | null>(null);
const [loading, setLoading] = useState(true);
const [notFound, setNotFound] = useState(false);
+ const [loadFailed, setLoadFailed] = useState(false);
+ const [attempt, setAttempt] = useState(0);
useEffect(() => {
let cancelled = false;
async function load() {
setLoading(true);
- const data = await getPromptResultById(resultId);
- if (cancelled) return;
- if (!data) {
- setNotFound(true);
- } else {
- setResult(data);
+ setLoadFailed(false);
+ try {
+ const data = await getPromptResultById(resultId);
+ if (cancelled) return;
+ if (!data) {
+ setNotFound(true);
+ } else {
+ setResult(data);
+ }
+ } catch {
+ if (!cancelled) setLoadFailed(true);
+ } finally {
+ if (!cancelled) setLoading(false);
}
- setLoading(false);
}
load();
return () => {
cancelled = true;
};
- }, [resultId]);
+ }, [resultId, attempt]);
// Opened in its own tab ("Open full page" on a prompt) there is no history
// to go back to, so Back leads to the result's prompt instead.
@@ -77,17 +100,35 @@ export default function ResultDetailPage() {
);
}
+ if (loadFailed) {
+ return (
+ <div className="flex flex-col items-center justify-center py-24 text-center">
+ <AlertCircle className="h-12 w-12 text-destructive/60 mb-4" />
+ <h2 className="text-lg font-semibold">{tDetail('loadFailedTitle')}</h2>
+ <p className="text-muted-foreground text-sm mt-1">{tDetail('loadFailedDescription')}</p>
+ <div className="mt-6 flex gap-2">
+ <Button variant="outline" className="gap-2" onClick={goBack}>
+ <ArrowLeft className="h-4 w-4" />
+ {tDetail('goBack')}
+ </Button>
+ <Button variant="outline" className="gap-2" onClick={() => setAttempt((n) => n + 1)}>
+ <RotateCw className="h-4 w-4" />
+ {common('retry')}
+ </Button>
+ </div>
+ </div>
+ );
+ }
+
if (notFound || !result) {
return (
<div className="flex flex-col items-center justify-center py-24 text-center">
<MessageSquareText className="h-12 w-12 text-muted-foreground/40 mb-4" />
- <h2 className="text-lg font-semibold">Result not found</h2>
- <p className="text-muted-foreground text-sm mt-1">
- This result may have been deleted or does not exist.
- </p>
+ <h2 className="text-lg font-semibold">{tDetail('notFoundTitle')}</h2>
+ <p className="text-muted-foreground text-sm mt-1">{tDetail('notFoundDescription')}</p>
<Button variant="outline" className="mt-6 gap-2" onClick={goBack}>
<ArrowLeft className="h-4 w-4" />
- Go back
+ {tDetail('goBack')}
</Button>
</div>
);
@@ -103,7 +144,7 @@ export default function ResultDetailPage() {
onClick={goBack}
>
<ArrowLeft className="h-4 w-4" />
- Back
+ {common('back')}
</Button>
{/* Header */}
@@ -121,7 +162,7 @@ export default function ResultDetailPage() {
</Badge>
{result.region && (
<Badge variant="outline" className="text-xs">
- {result.region}
+ {formatRegionDisplay(result.region)}
</Badge>
)}
</div>
@@ -134,7 +175,7 @@ export default function ResultDetailPage() {
<MessageSquareText className="h-5 w-5 text-muted-foreground" />
<div>
<p className="text-2xl font-bold tabular-nums">{result.mentionCount}</p>
- <p className="text-xs text-muted-foreground">Mentions</p>
+ <p className="text-xs text-muted-foreground">{t('mentions')}</p>
</div>
</CardContent>
</Card>
@@ -143,7 +184,7 @@ export default function ResultDetailPage() {
<Quote className="h-5 w-5 text-muted-foreground" />
<div>
<p className="text-2xl font-bold tabular-nums">{result.citationCount}</p>
- <p className="text-xs text-muted-foreground">Brand Citations</p>
+ <p className="text-xs text-muted-foreground">{tDetail('brandCitations')}</p>
</div>
</CardContent>
</Card>
@@ -152,7 +193,7 @@ export default function ResultDetailPage() {
<ExternalLink className="h-5 w-5 text-muted-foreground" />
<div>
<p className="text-2xl font-bold tabular-nums">{result.citations.length}</p>
- <p className="text-xs text-muted-foreground">Total Citations</p>
+ <p className="text-xs text-muted-foreground">{tDetail('totalCitations')}</p>
</div>
</CardContent>
</Card>
@@ -163,7 +204,7 @@ export default function ResultDetailPage() {
{/* Timestamp */}
<div className="flex items-center gap-2 text-xs text-muted-foreground pb-6">
<Clock className="h-3.5 w-3.5" />
- Checked: {new Date(result.createdAt).toLocaleString()}
+ {tDetail('checkedAt', { date: new Date(result.createdAt).toLocaleString() })}
</div>
</div>
);
diff --git a/web/src/lib/actions/tracking.test.ts b/web/src/lib/actions/tracking.test.ts
index ddd39b9f4..b2224d6f5 100644
--- a/web/src/lib/actions/tracking.test.ts
+++ b/web/src/lib/actions/tracking.test.ts
@@ -24,11 +24,17 @@ const promptResultRow = {
created_at: '2026-07-07T00:00:00.000Z',
};
+let promptResultRead: { data: unknown; error: { message: string } | null } = {
+ data: promptResultRow,
+ error: null,
+};
+
function fakeQueryBuilder(table: string) {
const builder = {
select: () => builder,
eq: () => builder,
neq: () => builder,
+ maybeSingle: async () => promptResultRead,
single: async () => {
if (table === 'prompt_results') return { data: promptResultRow, error: null };
if (table === 'prompts') {
@@ -79,6 +85,24 @@ vi.mock('@/lib/actions/topic', () => ({
}));
describe('getPromptResultById', () => {
+ afterEach(() => {
+ promptResultRead = { data: promptResultRow, error: null };
+ });
+
+ it('returns null for a result that does not exist', async () => {
+ promptResultRead = { data: null, error: null };
+ const { getPromptResultById } = await import('./tracking');
+
+ await expect(getPromptResultById('missing-id')).resolves.toBeNull();
+ });
+
+ it('throws when the read fails, so the page can offer a retry (#908)', async () => {
+ promptResultRead = { data: null, error: { message: 'statement timeout' } };
+ const { getPromptResultById } = await import('./tracking');
+
+ await expect(getPromptResultById('result-id')).rejects.toThrow('statement timeout');
+ });
+
it('carries observed search queries through to prompt result details', async () => {
const { getPromptResultById } = await import('./tracking');
diff --git a/web/src/lib/actions/tracking.ts b/web/src/lib/actions/tracking.ts
index 0e3496873..8b63448fb 100644
--- a/web/src/lib/actions/tracking.ts
+++ b/web/src/lib/actions/tracking.ts
@@ -1089,9 +1089,12 @@ export async function getPromptResultById(resultId: string): Promise<PromptResul
.select('*')
.eq('id', resultId)
.neq('platform', 'chatgpt-shopping')
- .single();
+ .maybeSingle();
- if (error || !data) return null;
+ // A failed read throws, so the page can offer a retry instead of reporting
+ // the result as missing.
+ if (error) throw new Error(error.message);
+ if (!data) return null;
const row = data as Record<string, unknown>;
const { data: promptData } = await supabase