import { useTRPC } from '@/integrations/trpc/react'; import type { RouterOutputs } from '@/trpc/client'; import { useQuery } from '@tanstack/react-query'; import type { IChartInput } from '@openpanel/validation'; 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 { Chart, Summary, Tables } from './chart'; export function ReportFunnelChart() { const { report: { series, range, projectId, funnelWindow, funnelGroup, startDate, endDate, previous, breakdowns, }, isLazyLoading, } = useReportChartContext(); const input: IChartInput = { series, range, projectId, interval: 'day', chartType: 'funnel', breakdowns, funnelWindow, funnelGroup, previous, metric: 'sum', startDate, endDate, limit: 20, }; const trpc = useTRPC(); const res = useQuery( trpc.chart.funnel.queryOptions(input, { enabled: !isLazyLoading && input.series.length > 0, }), ); if (isLazyLoading || res.isLoading) { return ; } if (res.isError) { return ; } if (!res.data || res.data.current.length === 0) { return ; } return (
{res.data.current.length > 1 && } {res.data.current.map((item, index) => ( ))}
); } function Loading() { return ( ); } function Error() { return ( ); } function Empty() { return ( ); }