import { useTRPC } from '@/integrations/trpc/react'; import type { RouterOutputs } from '@/trpc/client'; import { useQuery } from '@tanstack/react-query'; import { AspectContainer } from '../aspect-container'; import { ReportChartEmpty } from '../common/empty'; import { ReportChartError } from '../common/error'; import { ReportChartLoading } from '../common/loading'; import { useReportChartContext } from '../context'; import { useVisibleFunnelBreakdowns } from '@/hooks/use-visible-funnel-breakdowns'; import { Chart, Summary } from './chart'; import { BreakdownList } from './breakdown-list'; export function ReportFunnelChart() { const { isLazyLoading, report, shareId } = useReportChartContext(); const trpc = useTRPC(); const res = useQuery( trpc.chart.funnel.queryOptions( { ...report, shareId, }, { enabled: !isLazyLoading && report.series.length > 0, }, ), ); // Hook for limiting which breakdowns are shown in the chart only const { breakdowns: visibleBreakdowns, setVisibleSeries } = useVisibleFunnelBreakdowns(res.data?.current ?? [], 10); if (isLazyLoading || res.isLoading) { return ; } if (res.isError) { return ; } if (!res.data || res.data.current.length === 0) { return ; } const hasBreakdowns = res.data.current.length > 1; return (
{hasBreakdowns && } b.id)} setVisibleSeries={setVisibleSeries} />
); } function Loading() { return ( ); } function Error() { return ( ); } function Empty() { return ( ); }