import { useState, useEffect } from "react" import { DatePicker, Button, Input } from "antd" import moment from "moment" import { FileService } from "../../services/api" import { updateFromWebApiWrapperAsync, download, makePaginationObject, } from "../../components/factory" import { EditableTable } from "../../components/EditableTable" import UploadForm from "../../components/UploadForm" import LoaderPortal from "../../components/LoaderPortal" const pageSize = 12 const { RangePicker } = DatePicker const { Search } = Input export default function DocumentsTemplate({ idCategory, idWell }) { const [page, setPage] = useState(1) const [dataRange, setDataRange] = useState([]) const [company, setCompany] = useState([]) const [pagination, setPagination] = useState(null) const [files, setFiles] = useState([]) const [showLoader, setShowLoader] = useState(false) const uploadUrl = `/api/well/${idWell}/files/?idCategory=${idCategory}` const handleFileDownload = async (_, row) => { updateFromWebApiWrapperAsync( async () => { await download(`/api/well/${idWell}/files/${row.id}`) }, setShowLoader, `Не удалось скачать файл ${row}` ) } const handleUploadComplete = () => { update() } const handleFileDelete = (file) => { //FileService.delete(idWell, file.id) update() } const hanleCompanySearch = (value, _) => { setCompany(value) } const columns = [ { title: "Документ", key: "document", dataIndex: "name", render: (name, row) => ( ), }, { title: "Дата загрузки", key: "uploadDate", dataIndex: "uploadDate", render: (item) => moment.utc(item).local().format("DD MMM YYYY, HH:mm:ss"), }, { title: "Ф.И.О.", key: "userName", dataIndex: "userName", }, { title: "Компания", key: "company", dataIndex: "company", }, ] const addKeysAndUpdateFiles = (items) => { const mappedFiles = items?.map((fileInfo) => ({ key: fileInfo.id, begin: fileInfo.date, ...fileInfo, })) setFiles(mappedFiles ?? []) } const update = () => { let begin = null let end = null if (dataRange?.length > 1) { begin = dataRange[0].toISOString() end = dataRange[1].toISOString() } updateFromWebApiWrapperAsync( async () => { const paginatedFiles = await FileService.getFilesInfo( idWell, (page - 1) * pageSize, pageSize, idCategory, begin, end ) if (!paginatedFiles) return addKeysAndUpdateFiles(paginatedFiles?.items) const newPagination = makePaginationObject(paginatedFiles) setPagination(newPagination) }, setShowLoader, `Не удалось загрузить файлы по скважине "${idWell}"` ) } useEffect(update, [idWell, dataRange, page, idCategory, company]) const companies = [...new Set(files.map(file=>file.company))] .filter(company=>company) const DataListCompanies = {companies.map((company, i)=>)} return (
Фильтр по дате
 
Фильтр по компании {DataListCompanies}
  
Загрузка setShowLoader(true)} onUploadComplete={handleUploadComplete}/>
setPage(page), }} onRowDelete={handleFileDelete} rowKey={(record) => record.id} />
) }