import { useState, useEffect } from "react" import { DatePicker, Button, Input } from "antd" import moment from "moment" import { FileService } from "../../services/api" import { invokeWebApiWrapperAsync, download, formatBytes, } from "../../components/factory" import { EditableTable, makePaginationObject } from "../../components/Table" import UploadForm from "../../components/UploadForm" import LoaderPortal from "../../components/LoaderPortal" import {UserView} from '../../components/UserView' import {CompanyView} from '../../components/CompanyView' const pageSize = 12 const { RangePicker } = DatePicker const { Search } = Input export default function DocumentsTemplate({ idCategory, idWell, accept, headerChild, onChange }) { const [page, setPage] = useState(1) const [filterDataRange, setFilterDataRange] = useState([]) const [filterCompanyName, setFilterCompanyName] = useState([]) const [filterFileName, setFilterFileName] = 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) => { invokeWebApiWrapperAsync( async () => { await download(`/api/well/${idWell}/files/${row.id}`) }, setShowLoader, `Не удалось скачать файл ${row}` ) } const handleUploadComplete = () => { update() } const handleFileDelete = async (file) => { await FileService.delete(idWell, file.id) update() } const hanleCompanySearch = (value, _) => { setFilterCompanyName(value) } const hanleFileNameSearch = (value, _) => { setFilterFileName(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: "size", dataIndex: "size", render: item => formatBytes(item) }, { title: "Автор", key: "author", dataIndex: "author", render: item => }, { title: "Компания", key: "company", render: (_, record) => }, ] const update = () => { let begin = null let end = null if (filterDataRange?.length > 1) { begin = filterDataRange[0].toISOString() end = filterDataRange[1].toISOString() } invokeWebApiWrapperAsync( async () => { const paginatedFiles = await FileService.getFilesInfo( idWell, idCategory, filterCompanyName, filterFileName, begin, end, (page - 1) * pageSize, pageSize, ) if (!paginatedFiles) return const filesInfos = paginatedFiles.items??[] setFiles(filesInfos) const newPagination = makePaginationObject(paginatedFiles) setPagination(newPagination) }, setShowLoader, `Не удалось загрузить файлы по скважине "${idWell}"` ) } useEffect(update, [idWell, idCategory, page, filterDataRange, filterCompanyName, filterFileName]) useEffect(()=>{ if(onChange) onChange(files) }, [files, onChange]) const companies = [...new Set(files.map(file=>file.company))] .filter(company=>company) const DataListCompanies = {companies.map((company)=>)} const filenames = [...new Set(files.map(file=>file.name))] .filter(name=>name) const DataListFileNames = {filenames.map((name)=>)} return (
Фильтр по дате
 
Фильтр по компании {DataListCompanies}
 
Фильтр по имени файла {DataListFileNames}
  
Загрузка setShowLoader(true)} onUploadComplete={handleUploadComplete}/>
   {headerChild}
setPage(page), }} onRowDelete={handleFileDelete} rowKey={(record) => record.id} />
) }