'use client'; import { useState } from 'react'; import { useSignalProcess } from '@/lib/hooks/useSupervisor'; import { Button } from '@/components/ui/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; import { X, AlertTriangle } from 'lucide-react'; import { cn } from '@/lib/utils/cn'; interface SignalSenderProps { processName: string; onClose: () => void; } const COMMON_SIGNALS = [ { value: 'HUP', label: 'HUP (1)', description: 'Hangup - reload configuration', dangerous: false }, { value: 'INT', label: 'INT (2)', description: 'Interrupt - graceful shutdown', dangerous: false }, { value: 'QUIT', label: 'QUIT (3)', description: 'Quit', dangerous: false }, { value: 'TERM', label: 'TERM (15)', description: 'Terminate - graceful shutdown', dangerous: true }, { value: 'KILL', label: 'KILL (9)', description: 'Kill - immediate termination', dangerous: true }, { value: 'USR1', label: 'USR1 (10)', description: 'User-defined signal 1', dangerous: false }, { value: 'USR2', label: 'USR2 (12)', description: 'User-defined signal 2', dangerous: false }, ]; export function SignalSender({ processName, onClose }: SignalSenderProps) { const [selectedSignal, setSelectedSignal] = useState(''); const [customSignal, setCustomSignal] = useState(''); const [showConfirm, setShowConfirm] = useState(false); const signalMutation = useSignalProcess(); const handleSendSignal = () => { const signal = selectedSignal || customSignal; if (!signal) return; const isDangerous = ['TERM', 'KILL', 'QUIT'].includes(signal.toUpperCase()); if (isDangerous && !showConfirm) { setShowConfirm(true); return; } signalMutation.mutate( { name: processName, signal }, { onSuccess: () => { onClose(); }, } ); }; const signal = selectedSignal || customSignal; const isDangerous = signal && ['TERM', 'KILL', 'QUIT'].includes(signal.toUpperCase()); return (
Send Signal Send Unix signal to {processName}
{/* Common Signals */}
{COMMON_SIGNALS.map((sig) => ( ))}
{/* Custom Signal */}
{ setCustomSignal(e.target.value.toUpperCase()); setSelectedSignal(''); setShowConfirm(false); }} className="w-full h-10 rounded-md border border-input bg-background px-3 py-2 text-sm focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring" />
{/* Confirmation Warning */} {isDangerous && showConfirm && (

Warning: Dangerous Signal

Signal {signal} may terminate or kill the process. Are you sure you want to continue?

)} {/* Actions */}
); }