import { useState } from 'react'; import { Key, Lock, Eye, EyeOff, Copy, CheckCircle2, XCircle, AlertTriangle, } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Badge } from '@/components/ui/badge'; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog'; import { toast } from 'sonner'; import { useCredentialDetail } from '@/hooks/api'; import type { SecretType } from './types'; import { TYPE_CONFIG, TYPE_BADGE_CLASS } from './constants'; import i18n from '@/i18n'; export interface CredDetailDialogProps { open: boolean; onClose: () => void; credId: number | null; } // 凭据详情弹窗 // Logan.Li export function CredDetailDialog({ open, onClose, credId }: CredDetailDialogProps) { const [showMap, setShowMap] = useState>({}); const { data: detail, isLoading: loading } = useCredentialDetail(credId, open); if (!open || !credId) return null; const toggleShow = (key: string) => setShowMap(prev => ({ ...prev, [key]: !prev[key] })); const copyValue = (val: string) => { navigator.clipboard.writeText(val); toast.success(i18n.t('aiops.agentCliCopied')); }; const st = detail?.secret_type as SecretType; const cfg = TYPE_CONFIG[st]; const content = (detail as Record)?.content as Record || {}; const Field = ({ label, value, sensitive, fieldKey }: { label: string; value: unknown; sensitive?: boolean; fieldKey?: string }) => { if (value === undefined || value === null || value === '') return null; const isLong = typeof value === 'string' && value.length > 80; const show = fieldKey ? showMap[fieldKey] : false; return (
{label}
{isLong ? (