import { Link } from 'react-router-dom' import { useQuery } from '@tanstack/react-query' import { api } from '@/lib/api' import { hasWebsiteScope, scopedQueryKey } from '@/lib/queryKeys' import { useAppStore } from '@/store/useAppStore' import type { Question } from '@/types' import { Alert, AlertDescription, AlertTitle } from '@/components/ui/alert' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card' import { Skeleton } from '@/components/ui/skeleton' import { Network, Sparkles } from 'lucide-react' type OverviewSnapshot = { id: number tryout_id: string title: string question_count: number created_at: string basis_items: Question[] } type OverviewWebsite = { id: number name: string domain: string snapshots: OverviewSnapshot[] } type HierarchyOverview = { summary: { websites: number snapshots: number source_questions: number basis_items: number ai_runs: number variants: number snapshots_without_basis: number basis_without_variants: number orphan_variants: number } websites: OverviewWebsite[] } function SummaryCard({ label, value }: { label: string; value: number }) { return ( {label}
{value}
) } export default function DataOverview() { const { websiteId } = useAppStore() const { data, isLoading, isError } = useQuery({ queryKey: scopedQueryKey(websiteId, 'data-overview'), queryFn: async () => { const res = await api.get('/admin/overview/hierarchy') return res.data }, enabled: hasWebsiteScope(websiteId), }) if (!hasWebsiteScope(websiteId)) { return
Select a website to load the data overview.
} if (isLoading) return if (isError || !data) { return ( Failed to load data overview Check the selected website and backend API availability. ) } return (

Data Overview

Snapshot, basis question, AI run, and variant hierarchy.

{(data.summary.snapshots_without_basis > 0 || data.summary.basis_without_variants > 0 || data.summary.orphan_variants > 0) && ( Hierarchy gaps detected {data.summary.snapshots_without_basis} snapshots without promoted basis items,{' '} {data.summary.basis_without_variants} basis items without variants, and{' '} {data.summary.orphan_variants} variants without a visible basis. )} {data.websites.map((website) => (

{website.name}

{website.domain}

{website.snapshots.length === 0 ? (
No imported snapshots found for this website.
) : (
{website.snapshots.map((snapshot) => ( ))}
Snapshot Tryout Questions Basis Actions
{snapshot.title}
Snapshot #{snapshot.id}
{snapshot.tryout_id} {snapshot.question_count} {snapshot.basis_items.length}
{snapshot.basis_items[0] && ( )}
)}
))}
) }