"use client"; import { Fragment, useMemo, type ReactNode } from "react"; import classNames from "@calcom/ui/classNames"; import { PanelCard } from "@calcom/ui/components/card"; import { Spinner } from "@calcom/ui/components/icon"; import { SkeletonText } from "@calcom/ui/components/skeleton"; import { Tooltip } from "@calcom/ui/components/tooltip"; type PanelCardProps = React.ComponentProps; type LegendItem = { label: string; color: string; // hex format }; export type LegendSize = "sm" | "default"; export function ChartCard({ legend, legendSize, enabledLegend, onSeriesToggle, isPending, isError, ...panelCardProps }: Omit & { legend?: Array; legendSize?: LegendSize; enabledLegend?: Array; onSeriesToggle?: (label: string) => void; isPending?: boolean; isError?: boolean; children?: ReactNode; }) { const legendComponent = legend && legend.length > 0 ? ( ) : null; // Generate a chart ID from the title for testing purposes const chartId = useMemo(() => { if (typeof panelCardProps.title === "string") { return panelCardProps.title.toLowerCase().replace(/\s+/g, "-"); } return undefined; }, [panelCardProps.title]); // Calculate loading state from isPending/isError const computedLoadingState = useMemo(() => { if (isPending) return "loading"; if (isError) return "error"; return "loaded"; }, [isPending, isError]); const shouldShowDefaultLoading = isPending && !panelCardProps.children; const displayTitle = shouldShowDefaultLoading ? : panelCardProps.title; return ( {panelCardProps.headerContent} {legendComponent} ) : ( legendComponent ) }> {shouldShowDefaultLoading ? (
) : ( panelCardProps.children )}
); } export function ChartCardItem({ count, className, children, }: { count?: number | string; className?: string; children: ReactNode; }) { return (
{children}
{count !== undefined &&
{count}
}
); } function Legend({ items, size = "default", enabledItems, onItemToggle, }: { items: LegendItem[]; size?: LegendSize; enabledItems?: LegendItem[]; onItemToggle?: (label: string) => void; }) { const enabledSet = useMemo(() => new Set((enabledItems ?? []).map((i) => i.label)), [enabledItems]); const isClickable = Boolean(onItemToggle); return (
{items.map((item, index) => { const isEnabled = enabledItems ? enabledSet.has(item.label) : true; return ( {index < items.length - 1 &&
} ); })}
); }