/** * Terminal Connection Dialog * Full connection overlay with host info, progress indicator, and auth/progress content */ import { User } from 'lucide-react'; import React from 'react'; import { useI18n } from '../../application/i18n/I18nProvider'; import { cn } from '../../lib/utils'; import { Host, SSHKey } from '../../types'; import { DistroAvatar } from '../DistroAvatar'; import { Button } from '../ui/button'; import { TerminalAuthDialog, TerminalAuthDialogProps } from './TerminalAuthDialog'; import { TerminalConnectionProgress, TerminalConnectionProgressProps } from './TerminalConnectionProgress'; export interface ChainProgress { currentHop: number; totalHops: number; currentHostLabel: string; } export interface TerminalConnectionDialogProps { host: Host; status: 'connecting' | 'connected' | 'disconnected'; error: string | null; progressValue: number; chainProgress: ChainProgress | null; needsAuth: boolean; showLogs: boolean; _setShowLogs: (show: boolean) => void; // Auth dialog props authProps: Omit; keys: SSHKey[]; // Progress props progressProps: Omit; } // Helper to get protocol display info const getProtocolInfo = (host: Host): { i18nKey: string; showPort: boolean; port: number } => { // Check moshEnabled first since mosh uses protocol: "ssh" with moshEnabled: true if (host.moshEnabled) { return { i18nKey: 'terminal.connection.protocol.mosh', showPort: true, port: host.port || 22 }; } const protocol = host.protocol || 'ssh'; switch (protocol) { case 'local': return { i18nKey: 'terminal.connection.protocol.local', showPort: false, port: 0 }; case 'telnet': // Telnet uses telnetPort, not port (which is SSH port) return { i18nKey: 'terminal.connection.protocol.telnet', showPort: true, port: host.telnetPort ?? host.port ?? 23 }; case 'mosh': return { i18nKey: 'terminal.connection.protocol.mosh', showPort: true, port: host.port || 22 }; case 'serial': return { i18nKey: 'terminal.connection.protocol.serial', showPort: false, port: 0 }; case 'ssh': default: return { i18nKey: 'terminal.connection.protocol.ssh', showPort: true, port: host.port || 22 }; } }; export const TerminalConnectionDialog: React.FC = ({ host, status, error, progressValue, chainProgress, needsAuth, showLogs, _setShowLogs: setShowLogs, // Rename back to setShowLogs for internal use authProps, keys, progressProps, }) => { const { t } = useI18n(); const hasError = Boolean(error); const isConnecting = status === 'connecting'; const protocolInfo = getProtocolInfo(host); return (
{/* Show chain progress if available */} {chainProgress ? ( <>
{t('terminal.connection.chainOf', { current: chainProgress.currentHop, total: chainProgress.totalHops, })} {': '} {chainProgress.currentHostLabel}
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? `${host.hostname}:${protocolInfo.port}` : host.hostname}
) : ( <>
{host.label}
{t(protocolInfo.i18nKey)} {protocolInfo.showPort ? `${host.hostname}:${protocolInfo.port}` : host.hostname}
)}
{!needsAuth && ( )}
{/* Progress indicator - icons with progress bar below */}
{'>_'}
{needsAuth ? ( ) : ( )}
); }; export default TerminalConnectionDialog;