Initial commit - WhyRating Engine (Google Reviews Scraper)

This commit is contained in:
Alejandro Gutiérrez
2026-02-02 18:19:00 +00:00
parent 0543a08242
commit 2206ddeff2
136 changed files with 51138 additions and 855 deletions

View File

@@ -0,0 +1,190 @@
'use client';
import { useEffect, useState } from 'react';
import { useParams, useSearchParams, useRouter } from 'next/navigation';
import Link from 'next/link';
import { ArrowLeft, Loader2, FileText, BarChart3 } from 'lucide-react';
import { DynamicDashboard } from '@/components/dashboard/DynamicDashboard';
import { ReviewIQDashboard } from '@/components/reviewiq';
import { getDashboardConfig } from '@/lib/pipeline-api';
import type { DashboardConfig } from '@/lib/pipeline-types';
// Lazy load Report tab
import dynamic from 'next/dynamic';
const ReportTab = dynamic(() => import('@/components/reviewiq/ReportTab').then(m => m.ReportTab), {
loading: () => <div className="flex items-center justify-center min-h-[400px]"><Loader2 className="w-8 h-8 animate-spin text-blue-600" /></div>
});
type ReviewIQTab = 'report' | 'dashboard';
export default function PipelineAnalyticsPage() {
const params = useParams();
const searchParams = useSearchParams();
const pipelineId = params.pipelineId as string;
const jobId = searchParams.get('job_id') || undefined;
const businessId = searchParams.get('business_id') || undefined;
const [config, setConfig] = useState<DashboardConfig | null>(null);
const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null);
// Use the handcrafted ReviewIQ dashboard for the reviewiq pipeline
const useReviewIQDashboard = pipelineId === 'reviewiq';
// Tab state for ReviewIQ
const router = useRouter();
const viewParam = searchParams.get('view') as ReviewIQTab | null;
const [activeTab, setActiveTab] = useState<ReviewIQTab>(viewParam || 'report');
// Update URL when tab changes
const handleTabChange = (tab: ReviewIQTab) => {
setActiveTab(tab);
const params = new URLSearchParams(searchParams.toString());
if (tab === 'report') {
params.delete('view');
} else {
params.set('view', tab);
}
router.push(`/pipelines/${pipelineId}/analytics?${params.toString()}`, { scroll: false });
};
useEffect(() => {
// Skip config fetch for ReviewIQ - it uses its own optimized endpoint
if (useReviewIQDashboard) {
setLoading(false);
return;
}
async function fetchConfig() {
try {
setLoading(true);
const dashboardConfig = await getDashboardConfig(pipelineId);
setConfig(dashboardConfig);
} catch (err) {
setError(err instanceof Error ? err.message : 'Failed to load dashboard config');
} finally {
setLoading(false);
}
}
fetchConfig();
}, [pipelineId, useReviewIQDashboard]);
if (loading) {
return (
<div className="flex items-center justify-center min-h-[400px]">
<Loader2 className="w-8 h-8 animate-spin text-blue-600" />
</div>
);
}
// Use handcrafted ReviewIQ Dashboard with tabs
if (useReviewIQDashboard) {
const tabs = [
{ id: 'report' as const, label: 'Report', icon: FileText },
{ id: 'dashboard' as const, label: 'Dashboard', icon: BarChart3 },
];
return (
<div className="h-full overflow-y-auto p-6">
{/* Navigation breadcrumb */}
<div className="mb-4">
<Link
href={`/pipelines/${pipelineId}`}
className="inline-flex items-center text-sm text-gray-600 hover:text-gray-900"
>
<ArrowLeft className="w-4 h-4 mr-1" />
Back to ReviewIQ Pipeline
</Link>
</div>
{/* Job context indicator */}
{jobId && (
<div className="mb-4 bg-blue-50 border border-blue-200 rounded-lg p-3 text-sm text-blue-700">
Showing results for job: <code className="bg-blue-100 px-1 rounded">{jobId}</code>
</div>
)}
{/* Tab Navigation */}
<div className="mb-6 border-b border-gray-200">
<nav className="flex gap-2" aria-label="Tabs">
{tabs.map((tab) => {
const Icon = tab.icon;
const isActive = activeTab === tab.id;
return (
<button
key={tab.id}
onClick={() => handleTabChange(tab.id)}
className={`
relative px-4 py-2.5 flex items-center gap-2 text-sm font-medium transition-colors
${isActive
? 'text-blue-600'
: 'text-gray-500 hover:text-gray-700'
}
`}
>
<Icon className={`w-4 h-4 ${isActive ? 'text-blue-600' : 'text-gray-400'}`} />
<span>{tab.label}</span>
{/* Active indicator bar */}
<span
className={`absolute bottom-0 left-0 right-0 h-0.5 bg-blue-600 transition-opacity ${isActive ? 'opacity-100' : 'opacity-0'}`}
/>
</button>
);
})}
</nav>
</div>
{/* Tab Content */}
{activeTab === 'report' && (
<ReportTab jobId={jobId} businessId={businessId} />
)}
{activeTab === 'dashboard' && (
<ReviewIQDashboard jobId={jobId} businessId={businessId} />
)}
</div>
);
}
// Fallback for other pipelines using dynamic dashboard
if (error || !config) {
return (
<div className="p-6">
<div className="bg-red-50 border border-red-200 rounded-lg p-4 text-red-700">
{error || 'Failed to load dashboard configuration'}
</div>
</div>
);
}
return (
<div className="h-full overflow-y-auto p-6">
{/* Navigation breadcrumb */}
<div className="mb-4">
<Link
href={`/pipelines/${pipelineId}`}
className="inline-flex items-center text-sm text-gray-600 hover:text-gray-900"
>
<ArrowLeft className="w-4 h-4 mr-1" />
Back to {pipelineId} Pipeline
</Link>
</div>
{/* Job context indicator */}
{jobId && (
<div className="mb-4 bg-blue-50 border border-blue-200 rounded-lg p-3 text-sm text-blue-700">
Showing results for job: <code className="bg-blue-100 px-1 rounded">{jobId}</code>
</div>
)}
{/* Dynamic Dashboard for other pipelines */}
<DynamicDashboard
pipelineId={pipelineId}
config={config}
businessId={businessId}
jobId={jobId}
/>
</div>
);
}

View File

@@ -16,6 +16,7 @@ import {
ExternalLink,
Timer,
ArrowRightLeft,
BarChart3,
} from 'lucide-react';
import type { ExecutionStatus, StageMetrics } from '@/lib/pipeline-types';
import { getExecution } from '@/lib/pipeline-api';
@@ -432,6 +433,22 @@ export default function ExecutionDetailPage() {
</span>
</div>
)}
{/* View Results Dashboard Button */}
{execution?.status === 'completed' && execution?.job_id && (
<div className="mt-6 pt-4 border-t border-gray-200">
<Link
href={`/pipelines/${pipelineId}/analytics?job_id=${execution.job_id}`}
className="inline-flex items-center px-4 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium"
>
<BarChart3 className="w-5 h-5 mr-2" />
View Results Dashboard
</Link>
<p className="mt-2 text-sm text-gray-500">
See classification results, sentiment analysis, and identified issues
</p>
</div>
)}
</div>
{/* Error Message */}

View File

@@ -22,21 +22,21 @@ function PipelineCard({ pipeline }: { pipeline: PipelineInfo }) {
return (
<Link
href={`/pipelines/${pipeline.id}`}
className="block bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 hover:shadow-md hover:border-blue-300 dark:hover:border-blue-600 transition-all"
className="block bg-white rounded-xl border-2 border-gray-200 p-5 hover:shadow-lg hover:border-blue-400 transition-all"
>
<div className="flex items-start justify-between">
<div className="flex items-center">
<div
className={`p-2 rounded-lg ${
pipeline.is_enabled
? 'bg-green-100 text-green-600 dark:bg-green-900/30 dark:text-green-400'
: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400'
? 'bg-green-100 text-green-600'
: 'bg-gray-100 text-gray-600'
}`}
>
<Beaker className="w-5 h-5" />
</div>
<div className="ml-3">
<h3 className="font-medium text-gray-900 dark:text-gray-100">
<h3 className="font-bold text-gray-900">
{pipeline.name}
</h3>
<p className="text-sm text-gray-500">v{pipeline.version}</p>
@@ -45,33 +45,33 @@ function PipelineCard({ pipeline }: { pipeline: PipelineInfo }) {
<ChevronRight className="w-5 h-5 text-gray-400" />
</div>
<p className="mt-3 text-sm text-gray-600 dark:text-gray-400 line-clamp-2">
<p className="mt-3 text-sm text-gray-600 line-clamp-2">
{pipeline.description}
</p>
<div className="mt-4 flex items-center justify-between">
<div className="flex items-center text-sm text-gray-500">
<div className="flex items-center text-sm text-gray-600">
<span className="font-medium mr-2">Stages:</span>
{pipeline.stages.slice(0, 3).map((stage, i) => (
<span
key={stage}
className="px-2 py-0.5 bg-gray-100 dark:bg-gray-700 rounded text-xs mr-1"
className="px-2 py-0.5 bg-gray-100 text-gray-700 rounded text-xs mr-1"
>
{stage}
</span>
))}
{pipeline.stages.length > 3 && (
<span className="text-xs text-gray-400">
<span className="text-xs text-gray-500">
+{pipeline.stages.length - 3} more
</span>
)}
</div>
<span
className={`px-2 py-1 rounded-full text-xs font-medium ${
className={`px-2 py-1 rounded-full text-xs font-semibold ${
pipeline.is_enabled
? 'bg-green-100 text-green-700 dark:bg-green-900/30 dark:text-green-400'
: 'bg-gray-100 text-gray-600 dark:bg-gray-700 dark:text-gray-400'
? 'bg-green-100 text-green-700'
: 'bg-gray-100 text-gray-600'
}`}
>
{pipeline.is_enabled ? 'Enabled' : 'Disabled'}
@@ -108,14 +108,14 @@ export default function PipelinesPage() {
}, [showDisabled]);
return (
<div className="p-6">
<div className="h-full overflow-y-auto p-6">
{/* Header */}
<div className="flex items-center justify-between mb-6">
<div>
<h1 className="text-2xl font-bold text-gray-900 dark:text-gray-100">
<h1 className="text-2xl font-bold text-gray-900">
Pipelines
</h1>
<p className="text-gray-500 mt-1">
<p className="text-gray-600 mt-1">
Data processing pipelines for review analysis
</p>
</div>
@@ -129,7 +129,7 @@ export default function PipelinesPage() {
onChange={(e) => setShowDisabled(e.target.checked)}
className="rounded border-gray-300 text-blue-600 focus:ring-blue-500"
/>
<span className="ml-2 text-sm text-gray-600 dark:text-gray-400">
<span className="ml-2 text-sm text-gray-700">
Show disabled
</span>
</label>
@@ -138,7 +138,7 @@ export default function PipelinesPage() {
<button
onClick={fetchPipelines}
disabled={loading}
className="p-2 text-gray-500 hover:text-gray-700 dark:hover:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-800 rounded-md disabled:opacity-50"
className="p-2 text-gray-500 hover:text-gray-700 hover:bg-gray-200 rounded-md disabled:opacity-50"
title="Refresh"
>
<RefreshCw className={`w-5 h-5 ${loading ? 'animate-spin' : ''}`} />
@@ -150,7 +150,7 @@ export default function PipelinesPage() {
{error ? (
<div className="text-center py-12">
<AlertCircle className="w-12 h-12 text-red-500 mx-auto mb-4" />
<p className="text-red-600 dark:text-red-400">{error}</p>
<p className="text-red-600">{error}</p>
<button
onClick={fetchPipelines}
className="mt-4 px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700"
@@ -163,17 +163,17 @@ export default function PipelinesPage() {
{[1, 2, 3].map((i) => (
<div
key={i}
className="bg-white dark:bg-gray-800 rounded-lg border border-gray-200 dark:border-gray-700 p-6 animate-pulse"
className="bg-white rounded-lg border border-gray-200 p-6 animate-pulse"
>
<div className="flex items-center">
<div className="w-10 h-10 bg-gray-200 dark:bg-gray-700 rounded-lg" />
<div className="w-10 h-10 bg-gray-200 rounded-lg" />
<div className="ml-3 flex-1">
<div className="h-4 w-32 bg-gray-200 dark:bg-gray-700 rounded" />
<div className="h-3 w-16 bg-gray-200 dark:bg-gray-700 rounded mt-2" />
<div className="h-4 w-32 bg-gray-200 rounded" />
<div className="h-3 w-16 bg-gray-200 rounded mt-2" />
</div>
</div>
<div className="h-8 w-full bg-gray-200 dark:bg-gray-700 rounded mt-4" />
<div className="h-6 w-3/4 bg-gray-200 dark:bg-gray-700 rounded mt-4" />
<div className="h-8 w-full bg-gray-200 rounded mt-4" />
<div className="h-6 w-3/4 bg-gray-200 rounded mt-4" />
</div>
))}
</div>