'use client'; import { useState } from 'react'; import { ProcessInfo, ProcessState, ProcessStateCode } from '@/lib/supervisor/types'; import { useStartProcessGroup, useStopProcessGroup, useRestartProcessGroup } from '@/lib/hooks/useSupervisor'; import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card'; import { Button } from '@/components/ui/button'; import { ProcessCard } from '@/components/process/ProcessCard'; import { ChevronDown, ChevronUp, Play, Square, RotateCw } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; interface GroupCardProps { groupName: string; processes: ProcessInfo[]; } export function GroupCard({ groupName, processes }: GroupCardProps) { const [isExpanded, setIsExpanded] = useState(true); const startGroupMutation = useStartProcessGroup(); const stopGroupMutation = useStopProcessGroup(); const restartGroupMutation = useRestartProcessGroup(); const isLoading = startGroupMutation.isPending || stopGroupMutation.isPending || restartGroupMutation.isPending; // Calculate statistics const stats = processes.reduce( (acc, proc) => { if (proc.state === ProcessState.RUNNING) acc.running++; else if (proc.state === ProcessState.STOPPED || proc.state === ProcessState.EXITED) acc.stopped++; else if (proc.state === ProcessState.FATAL) acc.fatal++; return acc; }, { running: 0, stopped: 0, fatal: 0, total: processes.length } ); const handleStart = () => { startGroupMutation.mutate({ name: groupName }); }; const handleStop = () => { stopGroupMutation.mutate({ name: groupName }); }; const handleRestart = () => { restartGroupMutation.mutate({ name: groupName }); }; return (
{groupName}
Total: {stats.total} Running: {stats.running} Stopped: {stats.stopped} {stats.fatal > 0 && ( Fatal: {stats.fatal} )}
{isExpanded && (
{processes.map((process) => ( ))}
)}
); }