diff --git a/src/widgets/FilesDrawer/FilesDrawer.tsx b/src/widgets/FilesDrawer/FilesDrawer.tsx index 1ac9e2a..08f5924 100644 --- a/src/widgets/FilesDrawer/FilesDrawer.tsx +++ b/src/widgets/FilesDrawer/FilesDrawer.tsx @@ -1,20 +1,34 @@ import { CloseOutlined, UploadOutlined } from '@ant-design/icons'; -import { Button, Drawer, Typography } from 'antd'; +import { Button, Drawer, Switch, Tooltip, Typography } from 'antd'; import { useEffect, useState } from 'react'; import { fetchLegalEntity } from '../../services/api/directories/company_groups'; +import { isInWork, useCurrentConsolidation } from '../../store/slices/consolidations/selectors'; import { useAppSelector } from '../../store/store'; -import type { LegalEntityBrief } from '../../types/api'; +import type { FileOut, LegalEntityBrief } from '../../types/api'; import { FilesList } from './FilesList'; import { UploadDocumentsModal } from './UploadDocumentsModal'; +import { consolidationLabel } from './consolidationLabel'; import { useLegalEntityFiles } from './useLegalEntityFiles'; +const UPLOAD_DISABLED_HINT = 'Загрузка доступна только в версии в работе'; + export function DocumentsDrawer({ open, onClose }: { open: boolean; onClose: () => void }) { const [uploadOpen, setUploadOpen] = useState(false); const [entity, setEntity] = useState(null); - const { current_version_id, current_legal_entity_id } = useAppSelector((s) => s.consolidations); - const { files, loading, reload } = useLegalEntityFiles(current_legal_entity_id, open); + const [showAll, setShowAll] = useState(false); + const { current_legal_entity_id, consolidations } = useAppSelector((s) => s.consolidations); + const current = useCurrentConsolidation(); + // консолидация не определена (версии нет в списке ГК) — режим «все» без переключателя (design D-3) + const desk = current !== null && !showAll; + const consolidationId = desk ? current.consolidation_id : null; + const { files, loading, reload } = useLegalEntityFiles(current_legal_entity_id, consolidationId, open); + const canUpload = current !== null && isInWork(current.version_status); + const labelFor = desk + ? undefined + : (f: FileOut) => consolidationLabel(f.consolidation_id, consolidations, current?.consolidation_id ?? null); useEffect(() => { + setShowAll(false); // новая панель открывается столом консоли setEntity(null); if (!open || !current_legal_entity_id) return; let cancelled = false; @@ -30,6 +44,17 @@ export function DocumentsDrawer({ open, onClose }: { open: boolean; onClose: () }; }, [open, current_legal_entity_id]); + const uploadButton = ( + + ); + return ( }> -
- +
+ {canUpload ? ( + uploadButton + ) : ( + + {uploadButton} + + )} + {current !== null && ( + + + Все документы организации + + )}
- + {current_legal_entity_id && ( setUploadOpen(false)} diff --git a/src/widgets/FilesDrawer/FilesList.tsx b/src/widgets/FilesDrawer/FilesList.tsx index 41f46c0..8e4eaf8 100644 --- a/src/widgets/FilesDrawer/FilesList.tsx +++ b/src/widgets/FilesDrawer/FilesList.tsx @@ -57,9 +57,9 @@ function StatusPill({ row }: { row: DocumentRow }) { const HEADER = { fontSize: 11, letterSpacing: 0.5, color: '#8c8c8c', textTransform: 'uppercase' as const }; const head = (text: string) => {text}; -export function FilesList({ files, loading }: { files: FileOut[]; loading: boolean }) { +export function FilesList({ files, loading, labelFor }: { files: FileOut[]; loading: boolean; labelFor?: (f: FileOut) => string | null }) { const navigate = useNavigate(); - const rows = buildDocumentRows(files); + const rows = buildDocumentRows(files, labelFor); const columns: ColumnsType = [ { diff --git a/src/widgets/FilesDrawer/UploadDocumentsModal.tsx b/src/widgets/FilesDrawer/UploadDocumentsModal.tsx index a5dddf2..ee9b608 100644 --- a/src/widgets/FilesDrawer/UploadDocumentsModal.tsx +++ b/src/widgets/FilesDrawer/UploadDocumentsModal.tsx @@ -7,7 +7,7 @@ import { summarizeUpload, uploadFiles } from '../../services/api/files'; type Props = { legalEntityId: string; - versionId: string | null; + consolidationId: string | null; organizationName?: string | null; open: boolean; onClose: () => void; @@ -16,7 +16,7 @@ type Props = { type Summary = ReturnType; -export function UploadDocumentsModal({ legalEntityId, versionId, organizationName, open, onClose, onUploaded }: Props) { +export function UploadDocumentsModal({ legalEntityId, consolidationId, organizationName, open, onClose, onUploaded }: Props) { const [fileList, setFileList] = useState([]); const [uploading, setUploading] = useState(false); const [summary, setSummary] = useState(null); @@ -36,7 +36,7 @@ export function UploadDocumentsModal({ legalEntityId, versionId, organizationNam const files = fileList.map((f) => f.originFileObj).filter((f): f is NonNullable => Boolean(f)); setUploading(true); try { - const result = summarizeUpload(await uploadFiles(legalEntityId, files, versionId)); + const result = summarizeUpload(await uploadFiles(legalEntityId, files, consolidationId)); setSummary(result); if (result.accepted.length > 0) onUploaded(); else message.error('Ни один файл не принят'); diff --git a/src/widgets/FilesDrawer/documentRows.test.ts b/src/widgets/FilesDrawer/documentRows.test.ts index b762bfe..9b20410 100644 --- a/src/widgets/FilesDrawer/documentRows.test.ts +++ b/src/widgets/FilesDrawer/documentRows.test.ts @@ -105,4 +105,13 @@ describe('buildDocumentRows', () => { expect(rows[0].subtitle).toBe('Прочий документ · PDF · 12.03.2024'); expect(rows[0].linkable).toBe(false); }); + + it('подпись консолидации добавляется в subtitle последней, null — не добавляется', () => { + const rows = buildDocumentRows( + [file({ id: 'f1', documents: [doc()] }), file({ id: 'f2', documents: [], consolidation_id: 'c9' })], + (f) => (f.id === 'f2' ? 'вне консолидации' : null), + ); + expect(rows[0].subtitle.endsWith('вне консолидации')).toBe(false); + expect(rows[1].subtitle.endsWith(' · вне консолидации')).toBe(true); + }); }); diff --git a/src/widgets/FilesDrawer/documentRows.ts b/src/widgets/FilesDrawer/documentRows.ts index 785392a..bfeef40 100644 --- a/src/widgets/FilesDrawer/documentRows.ts +++ b/src/widgets/FilesDrawer/documentRows.ts @@ -36,8 +36,9 @@ function documentRowStatus(status: DocumentStatus): RowStatus { } /** Файлы → строки таблицы: одна строка на документ, файл без документов — одна строка на файл. */ -export function buildDocumentRows(files: FileOut[]): DocumentRow[] { +export function buildDocumentRows(files: FileOut[], labelFor?: (f: FileOut) => string | null): DocumentRow[] { return files.flatMap((f): DocumentRow[] => { + const extra = labelFor?.(f) ?? null; const name = f.original_name ?? 'без имени'; const date = formatMoscowDate(f.uploaded_at); if (f.documents.length === 0) { @@ -48,7 +49,7 @@ export function buildDocumentRows(files: FileOut[]): DocumentRow[] { documentId: null, name, fileType: f.file_type, - subtitle: join([f.file_type, date]), + subtitle: join([f.file_type, date, extra]), period: '—', status: failed ? 'error' : 'processing', statusLabel: failed ? 'Ошибка' : 'Обработка', @@ -68,7 +69,7 @@ export function buildDocumentRows(files: FileOut[]): DocumentRow[] { documentId: d.id, name, fileType: f.file_type, - subtitle: join([typeText, f.file_type, date]), + subtitle: join([typeText, f.file_type, date, extra]), period: periodLabel(d.period_year, d.period_quarter, d.is_cumulative), periodCheck: d.period_check, counterpartyCheck: d.counterparty_check, diff --git a/src/widgets/FilesDrawer/useLegalEntityFiles.ts b/src/widgets/FilesDrawer/useLegalEntityFiles.ts index df6e399..0adba90 100644 --- a/src/widgets/FilesDrawer/useLegalEntityFiles.ts +++ b/src/widgets/FilesDrawer/useLegalEntityFiles.ts @@ -6,8 +6,11 @@ import type { FileOut } from '../../types/api'; const POLL_MS = 5000; -/** Файлы ЮЛ; пока панель открыта и есть UPLOADED/PROCESSING — перечитываем раз в 5 с. */ -export function useLegalEntityFiles(legalEntityId: string | null, open: boolean) { +/** + * Файлы рабочего стола консолидации (`consolidationId`) или все файлы ЮЛ (`null`); + * пока панель открыта и есть UPLOADED/PROCESSING — перечитываем раз в 5 с. + */ +export function useLegalEntityFiles(legalEntityId: string | null, consolidationId: string | null, open: boolean) { const [files, setFiles] = useState([]); const [loading, setLoading] = useState(false); const requestRef = useRef(0); @@ -20,7 +23,7 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean) inFlightRef.current = true; setLoading(true); try { - const items = await listLegalEntityFiles(legalEntityId); + const items = await listLegalEntityFiles(legalEntityId, consolidationId); if (requestId === requestRef.current) { setFiles(items); errorShownRef.current = false; @@ -37,16 +40,17 @@ export function useLegalEntityFiles(legalEntityId: string | null, open: boolean) setLoading(false); } } - }, [legalEntityId]); + }, [legalEntityId, consolidationId]); + // biome-ignore lint/correctness/useExhaustiveDependencies: consolidationId — триггер сброса при смене режима, в теле не читается useEffect(() => { - // при смене ЮЛ / закрытии панели: старые ответы не применяем, файлы прежнего ЮЛ очищаем + // при смене ЮЛ, режима (консолидация/все) или закрытии панели: старые ответы не применяем, прежние файлы очищаем requestRef.current++; inFlightRef.current = false; errorShownRef.current = false; setFiles([]); if (open && legalEntityId) void reload(); - }, [open, legalEntityId, reload]); + }, [open, legalEntityId, consolidationId, reload]); const pending = hasPendingFiles(files); useEffect(() => {