import { Popover, Spin, Tag } from 'antd'; import { useState } from 'react'; import { getDocument } from '../../services/api/documents'; import type { IssueOut, Severity } from '../../types/api'; import { severityLabel } from '../../utils/labels'; import { SeverityIcon } from '../DocumentReview/IssuesPanel'; import type { DocumentRow } from './documentRows'; import { warningText } from './fileWarnings'; type IssuesState = { status: 'loading' } | { status: 'error' } | { status: 'done'; issues: IssueOut[] }; const tagColor = (s: Severity) => (s === 'error' ? 'error' : 'processing'); function DocumentIssues({ state }: { state: IssuesState | null }) { if (state === null || state.status === 'loading') return ; if (state.status === 'error') return Не удалось загрузить; if (state.issues.length === 0) return Нет; return ( <> {state.issues.map((i) => (
{severityLabel(i.severity)} {i.message}
))} ); } function Section({ title, children }: { title: string; children: React.ReactNode }) { return (
{title}
{children}
); } /** Значок с числом предупреждений под плашкой статуса; по клику — подробности (файл, обработка, документ). */ export function FileWarningsPopover({ row, badge }: { row: DocumentRow; badge: { count: number; level: Severity } | null }) { const [issues, setIssues] = useState(null); if (!badge) return null; // предупреждения документа грузим один раз за открытие: при закрытии сбрасываем, повторное открытие запрашивает заново const onOpenChange = (open: boolean) => { if (!open) { setIssues(null); return; } if (!row.documentId) return; setIssues({ status: 'loading' }); getDocument(row.documentId) .then((d) => setIssues({ status: 'done', issues: d.issues })) .catch(() => setIssues({ status: 'error' })); }; const content = (
{row.fileWarnings.length > 0 && (
{row.fileWarnings.map((w, i) => (
{severityLabel(w.severity)} {warningText(w)}
))}
)} {row.mappingWarnings.length > 0 && (
{row.mappingWarnings.map((w) => (
{severityLabel('info')} {w}
))}
)} {row.documentId && (
)}
); return ( ); }