// ======================================== // WorkflowStatusPieChart Component // ======================================== // Recharts pie chart visualizing workflow status distribution import { useMemo } from 'react'; import { PieChart, Pie, Cell, Tooltip, Legend, ResponsiveContainer } from 'recharts'; import type { WorkflowStatusCount } from '@/hooks/useWorkflowStatusCounts'; import { getChartColors, STATUS_COLORS } from '@/lib/chartTheme'; export interface WorkflowStatusPieChartProps { /** Workflow status count data */ data: WorkflowStatusCount[]; /** Optional CSS class name */ className?: string; /** Chart height (default: 300) */ height?: number; /** Optional label for the chart */ title?: string; } /** * Custom tooltip component for the pie chart */ function CustomTooltip({ active, payload }: any) { if (active && payload && payload.length) { const { name, value, payload: data } = payload[0]; const percentage = data.percentage ?? Math.round((value / 100) * 100); return (

{name}

{value} ({percentage}%)

); } return null; } /** * WorkflowStatusPieChart - Visualizes workflow status distribution * * @example * ```tsx * const { data, isLoading } = useWorkflowStatusCounts(); * return ; * ``` */ export function WorkflowStatusPieChart({ data, className = '', height = 300, title, }: WorkflowStatusPieChartProps) { const colors = useMemo(() => getChartColors(), []); const chartData = useMemo(() => { return data.map((item) => ({ ...item, displayName: item.status.charAt(0).toUpperCase() + item.status.slice(1).replace('_', ' '), })); }, [data]); const sliceColors = useMemo(() => { return chartData.map((item) => { const colorKey = STATUS_COLORS[item.status]; return colors[colorKey]; }); }, [chartData, colors]); return (
{title &&

{title}

} `${displayName} ${Math.round(percentage || 0)}%`} outerRadius={80} fill="#8884d8" dataKey="count" > {sliceColors.map((color, index) => ( ))} } /> entry.payload.displayName} />
); } export default WorkflowStatusPieChart;