import { useParams } from 'common' import { ExternalLink, HelpCircle } from 'lucide-react' import { NextRouter, useRouter } from 'next/router' import { ReactNode } from 'react' import { Button, cn, Loading, Tooltip, TooltipContent, TooltipTrigger } from 'ui' import type { LogsEndpointParams } from '../Settings/Logs/Logs.types' import type { BaseReportParams, ReportQueryType } from './Reports.types' import Panel from '@/components/ui/Panel' export interface ReportWidgetProps { data: T[] title: string description?: string error?: string | Object | null tooltip?: string | ReactNode className?: string contentClassName?: string headerClassName?: string renderer: (props: ReportWidgetRendererProps) => ReactNode append?: (props: ReportWidgetRendererProps) => ReactNode // for overriding props, such as data appendProps?: Partial // omitting params will hide the "View in logs explorer" button params?: BaseReportParams | LogsEndpointParams queryType?: ReportQueryType isLoading: boolean resolvedSql?: string } export interface ReportWidgetRendererProps extends ReportWidgetProps { router: NextRouter projectRef: string } const ReportWidget = (props: ReportWidgetProps) => { const router = useRouter() const { ref } = useParams() const projectRef = ref as string return (

{props.title}

{' '} {props?.tooltip && ( {props.tooltip} )}

{props.description}

{props.params && (
{props.data === undefined ? null : props.renderer({ ...props, router, projectRef: projectRef as string })}
{props.append && ( <> {props.append({ ...props, ...(props.appendProps || {}), router, projectRef: projectRef as string, })} )}
) } export default ReportWidget