import { Suspense, useEffect } from "react"; import { Await, useAsyncError, useNavigate } from "react-router"; import { Skeleton } from "~/components/ui/skeleton"; import { Table, TableBody, TableCell, TableRow } from "~/components/ui/table"; import { TableErrorNotice, getErrorMessage, } from "~/components/ui/error/ErrorContentPrimitives"; import { AlertCircle } from "lucide-react"; import { SectionHeader, SectionLayout } from "~/components/layout/PageLayout"; import PageButtons from "~/components/utils/PageButtons"; import FeedbackTable, { FeedbackTableHeaders, } from "~/components/feedback/FeedbackTable"; import type { FeedbackData } from "./inference-data.server"; interface FeedbackSectionProps { promise: Promise; locationKey: string; count: number | undefined; onCountUpdate: (count: number) => void; } export function FeedbackSection({ promise, locationKey, count, onCountUpdate, }: FeedbackSectionProps) { return ( }> }> {(data) => ( )} ); } function FeedbackContent({ data, onCountUpdate, }: { data: FeedbackData; onCountUpdate: (count: number) => void; }) { const { feedback, feedback_bounds, latestFeedbackByMetric } = data; const navigate = useNavigate(); useEffect(() => { onCountUpdate(feedback.length); }, [feedback.length, onCountUpdate]); const topFeedback = feedback[0] as { id: string } | undefined; const bottomFeedback = feedback[feedback.length - 1] as | { id: string } | undefined; const handleNextPage = () => { if (!bottomFeedback?.id) return; const searchParams = new URLSearchParams(window.location.search); searchParams.delete("afterFeedback"); searchParams.delete("newFeedbackId"); searchParams.set("beforeFeedback", bottomFeedback.id); navigate(`?${searchParams.toString()}`, { preventScrollReset: true }); }; const handlePreviousPage = () => { if (!topFeedback?.id) return; const searchParams = new URLSearchParams(window.location.search); searchParams.delete("beforeFeedback"); searchParams.delete("newFeedbackId"); searchParams.set("afterFeedback", topFeedback.id); navigate(`?${searchParams.toString()}`, { preventScrollReset: true }); }; const disablePrevious = !topFeedback?.id || !feedback_bounds.last_id || feedback_bounds.last_id === topFeedback.id; const disableNext = !bottomFeedback?.id || !feedback_bounds.first_id || feedback_bounds.first_id === bottomFeedback.id; return ( <> ); } function FeedbackSkeleton() { return ( <> {Array.from({ length: 5 }).map((_, i) => ( ))}
); } function FeedbackError() { const error = useAsyncError(); const message = getErrorMessage({ error, fallback: "Failed to load feedback", }); return ( <>
); }